1 | //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===// |
2 | // |
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 |
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. |
13 | // FIXME: Some of functions declared in this file are in fact POSIX, not libc. |
14 | //===----------------------------------------------------------------------===// |
15 | |
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. |
21 | #include "sanitizer_internal_defs.h" |
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); |
30 | void *internal_memrchr(const void *s, int c, uptr n); |
31 | int internal_memcmp(const void* s1, const void* s2, uptr n); |
32 | void *internal_memcpy(void *dest, const void *src, uptr n); |
33 | void *internal_memmove(void *dest, const void *src, uptr n); |
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); |
37 | char *internal_strchrnul(const char *s, int c); |
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); |
42 | uptr internal_strlcat(char *dst, const char *src, uptr maxlen); |
43 | char *internal_strncat(char *dst, const char *src, uptr n); |
44 | int internal_strncmp(const char *s1, const char *s2, uptr n); |
45 | uptr internal_strlcpy(char *dst, const char *src, uptr maxlen); |
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 | char *internal_strstr(const char *haystack, const char *needle); |
50 | // Works only for base=10 and doesn't set errno. |
51 | s64 internal_simple_strtoll(const char *nptr, const char **endptr, int base); |
52 | int internal_snprintf(char *buffer, uptr length, const char *format, ...); |
53 | |
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 | |
58 | // I/O |
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) |
65 | |
66 | uptr internal_ftruncate(fd_t fd, uptr size); |
67 | |
68 | // OS |
69 | void NORETURN internal__exit(int exitcode); |
70 | unsigned int internal_sleep(unsigned int seconds); |
71 | |
72 | uptr internal_getpid(); |
73 | uptr internal_getppid(); |
74 | |
75 | int internal_dlinfo(void *handle, int request, void *p); |
76 | |
77 | // Threading |
78 | uptr internal_sched_yield(); |
79 | |
80 | // Error handling |
81 | bool internal_iserror(uptr retval, int *rverrno = nullptr); |
82 | |
83 | } // namespace __sanitizer |
84 | |
85 | #endif // SANITIZER_LIBC_H |
86 | |