sanitizer_libc.h revision a4e4744778e6b3067f5cf223cf28bb586c1ecf67
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_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);
36char *internal_strdup(const char *s);
37uptr internal_strlen(const char *s);
38char *internal_strncat(char *dst, const char *src, uptr n);
39int internal_strncmp(const char *s1, const char *s2, uptr n);
40char *internal_strncpy(char *dst, const char *src, uptr n);
41uptr internal_strnlen(const char *s, uptr maxlen);
42char *internal_strrchr(const char *s, int c);
43// This is O(N^2), but we are not using it in hot places.
44char *internal_strstr(const char *haystack, const char *needle);
45// Works only for base=10 and doesn't set errno.
46s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
47
48// Memory
49void *internal_mmap(void *addr, uptr length, int prot, int flags,
50                    int fd, u64 offset);
51int internal_munmap(void *addr, uptr length);
52
53// I/O
54typedef int fd_t;
55const fd_t kInvalidFd = -1;
56int internal_close(fd_t fd);
57fd_t internal_open(const char *filename, bool write);
58uptr internal_read(fd_t fd, void *buf, uptr count);
59uptr internal_write(fd_t fd, const void *buf, uptr count);
60uptr internal_filesize(fd_t fd);  // -1 on error.
61int internal_dup2(int oldfd, int newfd);
62int internal_snprintf(char *buffer, uptr length, const char *format, ...);
63
64// Threading
65int internal_sched_yield();
66
67}  // namespace __sanitizer
68
69#endif  // SANITIZER_LIBC_H
70