]>
Commit | Line | Data |
---|---|---|
f35db108 WM |
1 | //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===// |
2 | // | |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
f35db108 WM |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is shared between AddressSanitizer and ThreadSanitizer | |
10 | // run-time libraries. | |
11 | // These tools can not use some of the libc functions directly because those | |
12 | // functions are intercepted. Instead, we implement a tiny subset of libc here. | |
696d846a | 13 | // FIXME: Some of functions declared in this file are in fact POSIX, not libc. |
f35db108 | 14 | //===----------------------------------------------------------------------===// |
696d846a | 15 | |
f35db108 WM |
16 | #ifndef SANITIZER_LIBC_H |
17 | #define SANITIZER_LIBC_H | |
18 | ||
19 | // ----------- ATTENTION ------------- | |
20 | // This header should NOT include any other headers from sanitizer runtime. | |
b4ab7d34 | 21 | #include "sanitizer_internal_defs.h" |
f35db108 WM |
22 | |
23 | namespace __sanitizer { | |
24 | ||
25 | // internal_X() is a custom implementation of X() for use in RTL. | |
26 | ||
27 | // String functions | |
28 | s64 internal_atoll(const char *nptr); | |
29 | void *internal_memchr(const void *s, int c, uptr n); | |
696d846a | 30 | void *internal_memrchr(const void *s, int c, uptr n); |
f35db108 WM |
31 | int internal_memcmp(const void* s1, const void* s2, uptr n); |
32 | void *internal_memcpy(void *dest, const void *src, uptr n); | |
e297eb60 | 33 | void *internal_memmove(void *dest, const void *src, uptr n); |
f35db108 WM |
34 | // Should not be used in performance-critical places. |
35 | void *internal_memset(void *s, int c, uptr n); | |
36 | char* internal_strchr(const char *s, int c); | |
ef1b3fda | 37 | char *internal_strchrnul(const char *s, int c); |
f35db108 WM |
38 | int internal_strcmp(const char *s1, const char *s2); |
39 | uptr internal_strcspn(const char *s, const char *reject); | |
40 | char *internal_strdup(const char *s); | |
41 | uptr internal_strlen(const char *s); | |
10189819 | 42 | uptr internal_strlcat(char *dst, const char *src, uptr maxlen); |
f35db108 WM |
43 | char *internal_strncat(char *dst, const char *src, uptr n); |
44 | int internal_strncmp(const char *s1, const char *s2, uptr n); | |
10189819 | 45 | uptr internal_strlcpy(char *dst, const char *src, uptr maxlen); |
f35db108 WM |
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); | |
f35db108 WM |
49 | char *internal_strstr(const char *haystack, const char *needle); |
50 | // Works only for base=10 and doesn't set errno. | |
eac97531 | 51 | s64 internal_simple_strtoll(const char *nptr, const char **endptr, int base); |
7df59255 | 52 | int internal_snprintf(char *buffer, uptr length, const char *format, ...); |
f35db108 | 53 | |
e9772e16 KS |
54 | // Return true if all bytes in [mem, mem+size) are zero. |
55 | // Optimized for the case when the result is true. | |
56 | bool mem_is_zero(const char *mem, uptr size); | |
57 | ||
f35db108 | 58 | // I/O |
10189819 MO |
59 | // Define these as macros so we can use them in linker initialized global |
60 | // structs without dynamic initialization. | |
61 | #define kInvalidFd ((fd_t)-1) | |
62 | #define kStdinFd ((fd_t)0) | |
63 | #define kStdoutFd ((fd_t)1) | |
64 | #define kStderrFd ((fd_t)2) | |
b4ab7d34 | 65 | |
866e32ad | 66 | uptr internal_ftruncate(fd_t fd, uptr size); |
7df59255 KS |
67 | |
68 | // OS | |
7df59255 | 69 | void NORETURN internal__exit(int exitcode); |
10189819 | 70 | unsigned int internal_sleep(unsigned int seconds); |
ef1b3fda | 71 | |
ef1b3fda KS |
72 | uptr internal_getpid(); |
73 | uptr internal_getppid(); | |
f35db108 | 74 | |
3c6331c2 ML |
75 | int internal_dlinfo(void *handle, int request, void *p); |
76 | ||
f35db108 | 77 | // Threading |
ef1b3fda KS |
78 | uptr internal_sched_yield(); |
79 | ||
80 | // Error handling | |
696d846a | 81 | bool internal_iserror(uptr retval, int *rverrno = nullptr); |
dee5ea7a | 82 | |
696d846a | 83 | } // namespace __sanitizer |
f35db108 | 84 | |
696d846a | 85 | #endif // SANITIZER_LIBC_H |