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