1*7c3d14c8STreehugger Robot //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===// 2*7c3d14c8STreehugger Robot // 3*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure 4*7c3d14c8STreehugger Robot // 5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source 6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details. 7*7c3d14c8STreehugger Robot // 8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 9*7c3d14c8STreehugger Robot // 10*7c3d14c8STreehugger Robot // This file is shared between AddressSanitizer and ThreadSanitizer 11*7c3d14c8STreehugger Robot // run-time libraries. 12*7c3d14c8STreehugger Robot // These tools can not use some of the libc functions directly because those 13*7c3d14c8STreehugger Robot // functions are intercepted. Instead, we implement a tiny subset of libc here. 14*7c3d14c8STreehugger Robot // FIXME: Some of functions declared in this file are in fact POSIX, not libc. 15*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 16*7c3d14c8STreehugger Robot 17*7c3d14c8STreehugger Robot #ifndef SANITIZER_LIBC_H 18*7c3d14c8STreehugger Robot #define SANITIZER_LIBC_H 19*7c3d14c8STreehugger Robot 20*7c3d14c8STreehugger Robot // ----------- ATTENTION ------------- 21*7c3d14c8STreehugger Robot // This header should NOT include any other headers from sanitizer runtime. 22*7c3d14c8STreehugger Robot #include "sanitizer_internal_defs.h" 23*7c3d14c8STreehugger Robot 24*7c3d14c8STreehugger Robot namespace __sanitizer { 25*7c3d14c8STreehugger Robot 26*7c3d14c8STreehugger Robot // internal_X() is a custom implementation of X() for use in RTL. 27*7c3d14c8STreehugger Robot 28*7c3d14c8STreehugger Robot // String functions 29*7c3d14c8STreehugger Robot s64 internal_atoll(const char *nptr); 30*7c3d14c8STreehugger Robot void *internal_memchr(const void *s, int c, uptr n); 31*7c3d14c8STreehugger Robot void *internal_memrchr(const void *s, int c, uptr n); 32*7c3d14c8STreehugger Robot int internal_memcmp(const void* s1, const void* s2, uptr n); 33*7c3d14c8STreehugger Robot void *internal_memcpy(void *dest, const void *src, uptr n); 34*7c3d14c8STreehugger Robot void *internal_memmove(void *dest, const void *src, uptr n); 35*7c3d14c8STreehugger Robot // Set [s, s + n) to 0. Both s and n should be 16-aligned. 36*7c3d14c8STreehugger Robot void internal_bzero_aligned16(void *s, uptr n); 37*7c3d14c8STreehugger Robot // Should not be used in performance-critical places. 38*7c3d14c8STreehugger Robot void *internal_memset(void *s, int c, uptr n); 39*7c3d14c8STreehugger Robot char* internal_strchr(const char *s, int c); 40*7c3d14c8STreehugger Robot char *internal_strchrnul(const char *s, int c); 41*7c3d14c8STreehugger Robot int internal_strcmp(const char *s1, const char *s2); 42*7c3d14c8STreehugger Robot uptr internal_strcspn(const char *s, const char *reject); 43*7c3d14c8STreehugger Robot char *internal_strdup(const char *s); 44*7c3d14c8STreehugger Robot char *internal_strndup(const char *s, uptr n); 45*7c3d14c8STreehugger Robot uptr internal_strlen(const char *s); 46*7c3d14c8STreehugger Robot uptr internal_strlcat(char *dst, const char *src, uptr maxlen); 47*7c3d14c8STreehugger Robot char *internal_strncat(char *dst, const char *src, uptr n); 48*7c3d14c8STreehugger Robot int internal_strncmp(const char *s1, const char *s2, uptr n); 49*7c3d14c8STreehugger Robot uptr internal_strlcpy(char *dst, const char *src, uptr maxlen); 50*7c3d14c8STreehugger Robot char *internal_strncpy(char *dst, const char *src, uptr n); 51*7c3d14c8STreehugger Robot uptr internal_strnlen(const char *s, uptr maxlen); 52*7c3d14c8STreehugger Robot char *internal_strrchr(const char *s, int c); 53*7c3d14c8STreehugger Robot // This is O(N^2), but we are not using it in hot places. 54*7c3d14c8STreehugger Robot char *internal_strstr(const char *haystack, const char *needle); 55*7c3d14c8STreehugger Robot // Works only for base=10 and doesn't set errno. 56*7c3d14c8STreehugger Robot s64 internal_simple_strtoll(const char *nptr, char **endptr, int base); 57*7c3d14c8STreehugger Robot int internal_snprintf(char *buffer, uptr length, const char *format, ...); 58*7c3d14c8STreehugger Robot 59*7c3d14c8STreehugger Robot // Return true if all bytes in [mem, mem+size) are zero. 60*7c3d14c8STreehugger Robot // Optimized for the case when the result is true. 61*7c3d14c8STreehugger Robot bool mem_is_zero(const char *mem, uptr size); 62*7c3d14c8STreehugger Robot 63*7c3d14c8STreehugger Robot // I/O 64*7c3d14c8STreehugger Robot const fd_t kInvalidFd = (fd_t)-1; 65*7c3d14c8STreehugger Robot const fd_t kStdinFd = 0; 66*7c3d14c8STreehugger Robot const fd_t kStdoutFd = (fd_t)1; 67*7c3d14c8STreehugger Robot const fd_t kStderrFd = (fd_t)2; 68*7c3d14c8STreehugger Robot 69*7c3d14c8STreehugger Robot uptr internal_ftruncate(fd_t fd, uptr size); 70*7c3d14c8STreehugger Robot 71*7c3d14c8STreehugger Robot // OS 72*7c3d14c8STreehugger Robot void NORETURN internal__exit(int exitcode); 73*7c3d14c8STreehugger Robot unsigned int internal_sleep(unsigned int seconds); 74*7c3d14c8STreehugger Robot 75*7c3d14c8STreehugger Robot uptr internal_getpid(); 76*7c3d14c8STreehugger Robot uptr internal_getppid(); 77*7c3d14c8STreehugger Robot 78*7c3d14c8STreehugger Robot // Threading 79*7c3d14c8STreehugger Robot uptr internal_sched_yield(); 80*7c3d14c8STreehugger Robot 81*7c3d14c8STreehugger Robot // Error handling 82*7c3d14c8STreehugger Robot bool internal_iserror(uptr retval, int *rverrno = nullptr); 83*7c3d14c8STreehugger Robot 84*7c3d14c8STreehugger Robot } // namespace __sanitizer 85*7c3d14c8STreehugger Robot 86*7c3d14c8STreehugger Robot #endif // SANITIZER_LIBC_H 87