forked from OSchip/llvm-project
[Sanitizer] add internal_memset and internal_strrchr to sanitizer_common/
llvm-svn: 158202
This commit is contained in:
parent
99d58521c5
commit
59036d2c06
|
@ -251,19 +251,6 @@ int internal_memcmp(const void* s1, const void* s2, uptr n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Should not be used in performance-critical places.
|
||||
void* internal_memset(void* s, int c, uptr n) {
|
||||
// The next line prevents Clang from making a call to memset() instead of the
|
||||
// loop below.
|
||||
// FIXME: building the runtime with -ffreestanding is a better idea. However
|
||||
// there currently are linktime problems due to PR12396.
|
||||
char volatile *t = (char*)s;
|
||||
for (uptr i = 0; i < n; ++i, ++t) {
|
||||
*t = c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
char *internal_strstr(const char *haystack, const char *needle) {
|
||||
// This is O(N^2), but we are not using it in hot places.
|
||||
uptr len1 = internal_strlen(haystack);
|
||||
|
|
|
@ -34,7 +34,6 @@ namespace __asan {
|
|||
s64 internal_atoll(const char *nptr);
|
||||
uptr internal_strnlen(const char *s, uptr maxlen);
|
||||
char* internal_strchr(const char *s, int c);
|
||||
void* internal_memset(void *s, int c, uptr n);
|
||||
int internal_memcmp(const void* s1, const void* s2, uptr n);
|
||||
char *internal_strstr(const char *haystack, const char *needle);
|
||||
char *internal_strncat(char *dst, const char *src, uptr n);
|
||||
|
|
|
@ -34,6 +34,18 @@ void *internal_memcpy(void *dest, const void *src, uptr n) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
void *internal_memset(void* s, int c, uptr n) {
|
||||
// The next line prevents Clang from making a call to memset() instead of the
|
||||
// loop below.
|
||||
// FIXME: building the runtime with -ffreestanding is a better idea. However
|
||||
// there currently are linktime problems due to PR12396.
|
||||
char volatile *t = (char*)s;
|
||||
for (uptr i = 0; i < n; ++i, ++t) {
|
||||
*t = c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
char* internal_strdup(const char *s) {
|
||||
uptr len = internal_strlen(s);
|
||||
char *s2 = (char*)InternalAlloc(len + 1);
|
||||
|
@ -54,6 +66,14 @@ int internal_strcmp(const char *s1, const char *s2) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *internal_strrchr(const char *s, int c) {
|
||||
const char *res = 0;
|
||||
for (uptr i = 0; s[i]; i++) {
|
||||
if (s[i] == c) res = s + i;
|
||||
}
|
||||
return (char*)res;
|
||||
}
|
||||
|
||||
uptr internal_strlen(const char *s) {
|
||||
uptr i = 0;
|
||||
while (s[i]) i++;
|
||||
|
|
|
@ -26,10 +26,13 @@ void MiniLibcStub();
|
|||
// String functions
|
||||
void *internal_memchr(const void *s, int c, uptr n);
|
||||
void *internal_memcpy(void *dest, const void *src, uptr n);
|
||||
// Should not be used in performance-critical places.
|
||||
void *internal_memset(void *s, int c, uptr n);
|
||||
int internal_strcmp(const char *s1, const char *s2);
|
||||
char *internal_strdup(const char *s);
|
||||
uptr internal_strlen(const char *s);
|
||||
char *internal_strncpy(char *dst, const char *src, uptr n);
|
||||
char *internal_strrchr(const char *s, int c);
|
||||
|
||||
// Memory
|
||||
void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
|
|
|
@ -140,7 +140,6 @@ int internal_strncmp(const char *s1, const char *s2, uptr size);
|
|||
void internal_strcpy(char *s1, const char *s2);
|
||||
const char *internal_strstr(const char *where, const char *what);
|
||||
const char *internal_strchr(const char *where, char what);
|
||||
const char *internal_strrchr(const char *where, char what);
|
||||
|
||||
struct MD5Hash {
|
||||
u64 hash[2];
|
||||
|
|
|
@ -1545,10 +1545,6 @@ const char *internal_strchr(const char *where, char what) {
|
|||
return (const char*)REAL(strchr)((void*)where, what);
|
||||
}
|
||||
|
||||
const char *internal_strrchr(const char *where, char what) {
|
||||
return (const char*)REAL(strrchr)((void*)where, what);
|
||||
}
|
||||
|
||||
void internal_start_thread(void(*func)(void *arg), void *arg) {
|
||||
void *th;
|
||||
REAL(pthread_create)(&th, 0, (void*(*)(void *arg))func, arg);
|
||||
|
|
Loading…
Reference in New Issue