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
23namespace __sanitizer {
24
25// internal_X() is a custom implementation of X() for use in RTL.
26
27// String functions
28s64 internal_atoll(const char *nptr);
29void *internal_memchr(const void *s, int c, uptr n);
30void *internal_memrchr(const void *s, int c, uptr n);
31int internal_memcmp(const void* s1, const void* s2, uptr n);
32void *internal_memcpy(void *dest, const void *src, uptr n);
33void *internal_memmove(void *dest, const void *src, uptr n);
34// Should not be used in performance-critical places.
35void *internal_memset(void *s, int c, uptr n);
36char* internal_strchr(const char *s, int c);
37char *internal_strchrnul(const char *s, int c);
38int internal_strcmp(const char *s1, const char *s2);
39uptr internal_strcspn(const char *s, const char *reject);
40char *internal_strdup(const char *s);
41uptr internal_strlen(const char *s);
42uptr internal_strlcat(char *dst, const char *src, uptr maxlen);
43char *internal_strncat(char *dst, const char *src, uptr n);
44int internal_strncmp(const char *s1, const char *s2, uptr n);
45uptr internal_strlcpy(char *dst, const char *src, uptr maxlen);
46char *internal_strncpy(char *dst, const char *src, uptr n);
47uptr internal_strnlen(const char *s, uptr maxlen);
48char *internal_strrchr(const char *s, int c);
49char *internal_strstr(const char *haystack, const char *needle);
50// Works only for base=10 and doesn't set errno.
51s64 internal_simple_strtoll(const char *nptr, const char **endptr, int base);
52int 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.
56bool 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
66uptr internal_ftruncate(fd_t fd, uptr size);
67
68// OS
69void NORETURN internal__exit(int exitcode);
70unsigned int internal_sleep(unsigned int seconds);
71
72uptr internal_getpid();
73uptr internal_getppid();
74
75int internal_dlinfo(void *handle, int request, void *p);
76
77// Threading
78uptr internal_sched_yield();
79
80// Error handling
81bool internal_iserror(uptr retval, int *rverrno = nullptr);
82
83} // namespace __sanitizer
84
85#endif // SANITIZER_LIBC_H
86