* sanitizer_common/Makefile.am (AM_CXXFLAGS): Use -std=gnu++11.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_libc.h
blob680b888e219124b33d3932e3a49ed46b5c7ee045
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 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_LIBC_H
14 #define SANITIZER_LIBC_H
16 // ----------- ATTENTION -------------
17 // This header should NOT include any other headers from sanitizer runtime.
18 #include "sanitizer_internal_defs.h"
20 namespace __sanitizer {
22 // internal_X() is a custom implementation of X() for use in RTL.
24 // String functions
25 s64 internal_atoll(const char *nptr);
26 void *internal_memchr(const void *s, int c, uptr n);
27 int internal_memcmp(const void* s1, const void* s2, uptr n);
28 void *internal_memcpy(void *dest, const void *src, uptr n);
29 void *internal_memmove(void *dest, const void *src, uptr n);
30 // Set [s, s + n) to 0. Both s and n should be 16-aligned.
31 void internal_bzero_aligned16(void *s, uptr n);
32 // Should not be used in performance-critical places.
33 void *internal_memset(void *s, int c, uptr n);
34 char* internal_strchr(const char *s, int c);
35 char *internal_strchrnul(const char *s, int c);
36 int internal_strcmp(const char *s1, const char *s2);
37 uptr internal_strcspn(const char *s, const char *reject);
38 char *internal_strdup(const char *s);
39 uptr internal_strlen(const char *s);
40 char *internal_strncat(char *dst, const char *src, uptr n);
41 int internal_strncmp(const char *s1, const char *s2, uptr n);
42 char *internal_strncpy(char *dst, const char *src, uptr n);
43 uptr internal_strnlen(const char *s, uptr maxlen);
44 char *internal_strrchr(const char *s, int c);
45 // This is O(N^2), but we are not using it in hot places.
46 char *internal_strstr(const char *haystack, const char *needle);
47 // Works only for base=10 and doesn't set errno.
48 s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
49 int internal_snprintf(char *buffer, uptr length, const char *format, ...);
51 // Return true if all bytes in [mem, mem+size) are zero.
52 // Optimized for the case when the result is true.
53 bool mem_is_zero(const char *mem, uptr size);
56 // Memory
57 uptr internal_mmap(void *addr, uptr length, int prot, int flags,
58 int fd, u64 offset);
59 uptr internal_munmap(void *addr, uptr length);
61 // I/O
62 const fd_t kInvalidFd = -1;
63 const fd_t kStdinFd = 0;
64 const fd_t kStdoutFd = 1;
65 const fd_t kStderrFd = 2;
66 uptr internal_close(fd_t fd);
67 int internal_isatty(fd_t fd);
69 // Use __sanitizer::OpenFile() instead.
70 uptr internal_open(const char *filename, int flags);
71 uptr internal_open(const char *filename, int flags, u32 mode);
73 uptr internal_read(fd_t fd, void *buf, uptr count);
74 uptr internal_write(fd_t fd, const void *buf, uptr count);
75 uptr internal_ftruncate(fd_t fd, uptr size);
77 // OS
78 uptr internal_filesize(fd_t fd); // -1 on error.
79 uptr internal_stat(const char *path, void *buf);
80 uptr internal_lstat(const char *path, void *buf);
81 uptr internal_fstat(fd_t fd, void *buf);
82 uptr internal_dup2(int oldfd, int newfd);
83 uptr internal_readlink(const char *path, char *buf, uptr bufsize);
84 uptr internal_unlink(const char *path);
85 uptr internal_rename(const char *oldpath, const char *newpath);
86 void NORETURN internal__exit(int exitcode);
87 uptr internal_lseek(fd_t fd, OFF_T offset, int whence);
89 uptr internal_ptrace(int request, int pid, void *addr, void *data);
90 uptr internal_waitpid(int pid, int *status, int options);
91 uptr internal_getpid();
92 uptr internal_getppid();
94 int internal_fork();
96 // Threading
97 uptr internal_sched_yield();
99 // Error handling
100 bool internal_iserror(uptr retval, int *rverrno = 0);
102 int internal_sigaction(int signum, const void *act, void *oldact);
104 } // namespace __sanitizer
106 #endif // SANITIZER_LIBC_H