1 //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
16 #ifndef SANITIZER_LIBC_H
17 #define SANITIZER_LIBC_H
19 // ----------- ATTENTION -------------
20 // This header should NOT include any other headers from sanitizer runtime.
21 #include "sanitizer_internal_defs.h"
23 namespace __sanitizer
{
25 // internal_X() is a custom implementation of X() for use in RTL.
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
, ...)
54 uptr
internal_wcslen(const wchar_t *s
);
55 uptr
internal_wcsnlen(const wchar_t *s
, uptr maxlen
);
57 // Return true if all bytes in [mem, mem+size) are zero.
58 // Optimized for the case when the result is true.
59 bool mem_is_zero(const char *mem
, uptr size
);
62 // Define these as macros so we can use them in linker initialized global
63 // structs without dynamic initialization.
64 #define kInvalidFd ((fd_t)-1)
65 #define kStdinFd ((fd_t)0)
66 #define kStdoutFd ((fd_t)1)
67 #define kStderrFd ((fd_t)2)
69 uptr
internal_ftruncate(fd_t fd
, uptr size
);
72 void NORETURN
internal__exit(int exitcode
);
73 void internal_sleep(unsigned seconds
);
74 void internal_usleep(u64 useconds
);
76 uptr
internal_getpid();
77 uptr
internal_getppid();
79 int internal_dlinfo(void *handle
, int request
, void *p
);
82 uptr
internal_sched_yield();
85 bool internal_iserror(uptr retval
, int *rverrno
= nullptr);
87 } // namespace __sanitizer
89 #endif // SANITIZER_LIBC_H