Add __memset_chk assembler for mips32 and mips64.
Change-Id: I365b1f345c695850c30ccb1a9f56f254ce182000
diff --git a/libc/arch-mips/string/memset.S b/libc/arch-mips/string/memset.S
index 65bb5b5..dd94f3b 100644
--- a/libc/arch-mips/string/memset.S
+++ b/libc/arch-mips/string/memset.S
@@ -170,11 +170,6 @@
# define R6_CODE
#endif
-/* Allow the routine to be named something else if desired. */
-#ifndef MEMSET_NAME
-# define MEMSET_NAME memset
-#endif
-
/* We load/store 64 bits at a time when USE_DOUBLE is true.
The C_ prefix stands for CHUNK and is used to avoid macro name
conflicts with system header files. */
@@ -209,9 +204,19 @@
#define UNITM1(unit) (((unit)*NSIZE)-1)
#ifdef __ANDROID__
-LEAF(MEMSET_NAME,0)
+LEAF(__memset_chk,0)
#else
-LEAF(MEMSET_NAME)
+LEAF(__memset_chk)
+#endif
+ bgtu a2, a3, __memset_chk_fail
+
+ // Fall through to memset...
+END(__memset_chk)
+
+#ifdef __ANDROID__
+LEAF(memset,0)
+#else
+LEAF(memset)
#endif
.set nomips16
@@ -428,9 +433,10 @@
.set at
.set reorder
-END(MEMSET_NAME)
+END(memset)
#ifndef __ANDROID__
# ifdef _LIBC
-libc_hidden_builtin_def (MEMSET_NAME)
+libc_hidden_builtin_def (memset)
+libc_hidden_builtin_def (__memset_chk)
# endif
#endif
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 31a9e84..ad7aa04 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -153,15 +153,6 @@
return memrchr(s, c, n);
}
-#if defined(__mips__) // TODO: add optimized assembler for mips too, and remove this.
-// Runtime implementation of __builtin___memset_chk (used directly by compiler, not in headers).
-extern "C" void* __memset_chk(void* dst, int byte, size_t count, size_t dst_len) {
- __check_count("memset", "count", count);
- __check_buffer_access("memset", "write into", count, dst_len);
- return memset(dst, byte, count);
-}
-#endif
-
// memset is performance-critical enough that we have assembler __memset_chk implementations.
// This function is used to give better diagnostics than we can easily do from assembler.
extern "C" void* __memset_chk_fail(void* /*dst*/, int /*byte*/, size_t count, size_t dst_len) {