]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
Update nvi to 2.1.3 which fixes the data corruption when locale conversion
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_libc.h
1 //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is shared between AddressSanitizer and ThreadSanitizer
11 // run-time libraries.
12 // These tools can not use some of the libc functions directly because those
13 // functions are intercepted. Instead, we implement a tiny subset of libc here.
14 //===----------------------------------------------------------------------===//
15 #ifndef SANITIZER_LIBC_H
16 #define SANITIZER_LIBC_H
17
18 // ----------- ATTENTION -------------
19 // This header should NOT include any other headers from sanitizer runtime.
20 #include "sanitizer_internal_defs.h"
21
22 namespace __sanitizer {
23
24 // internal_X() is a custom implementation of X() for use in RTL.
25
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, ...);
54
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);
58
59
60 // Memory
61 uptr internal_mmap(void *addr, uptr length, int prot, int flags,
62                    int fd, u64 offset);
63 uptr internal_munmap(void *addr, uptr length);
64
65 // I/O
66 const fd_t kInvalidFd = -1;
67 const fd_t kStdinFd = 0;
68 const fd_t kStdoutFd = 1;
69 const fd_t kStderrFd = 2;
70 uptr internal_close(fd_t fd);
71 int internal_isatty(fd_t fd);
72
73 // Use __sanitizer::OpenFile() instead.
74 uptr internal_open(const char *filename, int flags);
75 uptr internal_open(const char *filename, int flags, u32 mode);
76
77 uptr internal_read(fd_t fd, void *buf, uptr count);
78 uptr internal_write(fd_t fd, const void *buf, uptr count);
79 uptr internal_ftruncate(fd_t fd, uptr size);
80
81 // OS
82 uptr internal_filesize(fd_t fd);  // -1 on error.
83 uptr internal_stat(const char *path, void *buf);
84 uptr internal_lstat(const char *path, void *buf);
85 uptr internal_fstat(fd_t fd, void *buf);
86 uptr internal_dup2(int oldfd, int newfd);
87 uptr internal_readlink(const char *path, char *buf, uptr bufsize);
88 uptr internal_unlink(const char *path);
89 uptr internal_rename(const char *oldpath, const char *newpath);
90 void NORETURN internal__exit(int exitcode);
91 uptr internal_lseek(fd_t fd, OFF_T offset, int whence);
92
93 uptr internal_ptrace(int request, int pid, void *addr, void *data);
94 uptr internal_waitpid(int pid, int *status, int options);
95 uptr internal_getpid();
96 uptr internal_getppid();
97
98 int internal_fork();
99
100 // Threading
101 uptr internal_sched_yield();
102
103 // These functions call appropriate pthread_ functions directly, bypassing
104 // the interceptor. They are weak and may not be present in some tools.
105 SANITIZER_WEAK_ATTRIBUTE
106 int real_pthread_create(void *th, void *attr, void *(*callback)(void *),
107                         void *param);
108 SANITIZER_WEAK_ATTRIBUTE
109 int real_pthread_join(void *th, void **ret);
110
111 #define DEFINE_REAL_PTHREAD_FUNCTIONS                                          \
112   namespace __sanitizer {                                                      \
113   int real_pthread_create(void *th, void *attr, void *(*callback)(void *),     \
114                           void *param) {                                       \
115     return REAL(pthread_create)(th, attr, callback, param);                    \
116   }                                                                            \
117   int real_pthread_join(void *th, void **ret) {                                \
118     return REAL(pthread_join(th, ret));                                        \
119   }                                                                            \
120   }  // namespace __sanitizer
121
122 // Error handling
123 bool internal_iserror(uptr retval, int *rverrno = 0);
124
125 int internal_sigaction(int signum, const void *act, void *oldact);
126
127 }  // namespace __sanitizer
128
129 #endif  // SANITIZER_LIBC_H