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