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// NOTE: This file may be included into user code.
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/common_interface_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);
30int internal_memcmp(const void* s1, const void* s2, uptr n);
31void *internal_memcpy(void *dest, const void *src, uptr n);
32// Should not be used in performance-critical places.
33void *internal_memset(void *s, int c, uptr n);
34char* internal_strchr(const char *s, int c);
35int internal_strcmp(const char *s1, const char *s2);
36uptr internal_strcspn(const char *s, const char *reject);
37char *internal_strdup(const char *s);
38uptr internal_strlen(const char *s);
39char *internal_strncat(char *dst, const char *src, uptr n);
40int internal_strncmp(const char *s1, const char *s2, uptr n);
41char *internal_strncpy(char *dst, const char *src, uptr n);
42uptr internal_strnlen(const char *s, uptr maxlen);
43char *internal_strrchr(const char *s, int c);
44// This is O(N^2), but we are not using it in hot places.
45char *internal_strstr(const char *haystack, const char *needle);
46// Works only for base=10 and doesn't set errno.
47s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
48
49// Memory
50void *internal_mmap(void *addr, uptr length, int prot, int flags,
51                    int fd, u64 offset);
52int internal_munmap(void *addr, uptr length);
53
54// I/O
55typedef int fd_t;
56const fd_t kInvalidFd = -1;
57int internal_close(fd_t fd);
58fd_t internal_open(const char *filename, bool write);
59uptr internal_read(fd_t fd, void *buf, uptr count);
60uptr internal_write(fd_t fd, const void *buf, uptr count);
61uptr internal_filesize(fd_t fd);  // -1 on error.
62int internal_dup2(int oldfd, int newfd);
63uptr internal_readlink(const char *path, char *buf, uptr bufsize);
64int internal_snprintf(char *buffer, uptr length, const char *format, ...);
65
66// Threading
67int internal_sched_yield();
68
69}  // namespace __sanitizer
70
71#endif  // SANITIZER_LIBC_H
72