• 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 #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 // Set [s, s + n) to 0. Both s and n should be 16-aligned.
35 void internal_bzero_aligned16(void *s, uptr n);
36 // Should not be used in performance-critical places.
37 void *internal_memset(void *s, int c, uptr n);
38 char* internal_strchr(const char *s, int c);
39 char *internal_strchrnul(const char *s, int c);
40 int internal_strcmp(const char *s1, const char *s2);
41 uptr internal_strcspn(const char *s, const char *reject);
42 char *internal_strdup(const char *s);
43 char *internal_strndup(const char *s, uptr n);
44 uptr internal_strlen(const char *s);
45 char *internal_strncat(char *dst, const char *src, uptr n);
46 int internal_strncmp(const char *s1, const char *s2, uptr n);
47 char *internal_strncpy(char *dst, const char *src, uptr n);
48 uptr internal_strnlen(const char *s, uptr maxlen);
49 char *internal_strrchr(const char *s, int c);
50 // This is O(N^2), but we are not using it in hot places.
51 char *internal_strstr(const char *haystack, const char *needle);
52 // Works only for base=10 and doesn't set errno.
53 s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
54 int internal_snprintf(char *buffer, uptr length, const char *format, ...);
55 
56 // Return true if all bytes in [mem, mem+size) are zero.
57 // Optimized for the case when the result is true.
58 bool mem_is_zero(const char *mem, uptr size);
59 
60 // I/O
61 const fd_t kInvalidFd = (fd_t)-1;
62 const fd_t kStdinFd = 0;
63 const fd_t kStdoutFd = (fd_t)1;
64 const fd_t 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 
71 uptr internal_getpid();
72 uptr internal_getppid();
73 
74 // Threading
75 uptr internal_sched_yield();
76 
77 // Error handling
78 bool internal_iserror(uptr retval, int *rverrno = 0);
79 
80 }  // namespace __sanitizer
81 
82 #endif  // SANITIZER_LIBC_H
83