• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // FIXME: Some of functions declared in this file are in fact POSIX, not libc.
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef SANITIZER_LIBC_H
18 #define SANITIZER_LIBC_H
19 
20 // ----------- ATTENTION -------------
21 // This header should NOT include any other headers from sanitizer runtime.
22 #include "sanitizer_internal_defs.h"
23 
24 namespace __sanitizer {
25 
26 // internal_X() is a custom implementation of X() for use in RTL.
27 
28 // String functions
29 s64 internal_atoll(const char *nptr);
30 void *internal_memchr(const void *s, int c, uptr n);
31 void *internal_memrchr(const void *s, int c, uptr n);
32 int internal_memcmp(const void* s1, const void* s2, uptr n);
33 void *internal_memcpy(void *dest, const void *src, uptr n);
34 void *internal_memmove(void *dest, const void *src, uptr n);
35 // Set [s, s + n) to 0. Both s and n should be 16-aligned.
36 void internal_bzero_aligned16(void *s, uptr n);
37 // Should not be used in performance-critical places.
38 void *internal_memset(void *s, int c, uptr n);
39 char* internal_strchr(const char *s, int c);
40 char *internal_strchrnul(const char *s, int c);
41 int internal_strcmp(const char *s1, const char *s2);
42 uptr internal_strcspn(const char *s, const char *reject);
43 char *internal_strdup(const char *s);
44 char *internal_strndup(const char *s, uptr n);
45 uptr internal_strlen(const char *s);
46 uptr internal_strlcat(char *dst, const char *src, uptr maxlen);
47 char *internal_strncat(char *dst, const char *src, uptr n);
48 int internal_strncmp(const char *s1, const char *s2, uptr n);
49 uptr internal_strlcpy(char *dst, const char *src, uptr maxlen);
50 char *internal_strncpy(char *dst, const char *src, uptr n);
51 uptr internal_strnlen(const char *s, uptr maxlen);
52 char *internal_strrchr(const char *s, int c);
53 // This is O(N^2), but we are not using it in hot places.
54 char *internal_strstr(const char *haystack, const char *needle);
55 // Works only for base=10 and doesn't set errno.
56 s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
57 int internal_snprintf(char *buffer, uptr length, const char *format, ...);
58 
59 // Return true if all bytes in [mem, mem+size) are zero.
60 // Optimized for the case when the result is true.
61 bool mem_is_zero(const char *mem, uptr size);
62 
63 // I/O
64 const fd_t kInvalidFd = (fd_t)-1;
65 const fd_t kStdinFd = 0;
66 const fd_t kStdoutFd = (fd_t)1;
67 const fd_t kStderrFd = (fd_t)2;
68 
69 uptr internal_ftruncate(fd_t fd, uptr size);
70 
71 // OS
72 void NORETURN internal__exit(int exitcode);
73 
74 uptr internal_getpid();
75 uptr internal_getppid();
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