[Sanitizer] extend internal libc with stat/fstat/lstat functions
[blocksruntime.git] / lib / sanitizer_common / sanitizer_libc.h
blob6bdca3c9b16283ccece7563416c2ff351677a685
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 //===----------------------------------------------------------------------===//
15 #ifndef SANITIZER_LIBC_H
16 #define SANITIZER_LIBC_H
18 // ----------- ATTENTION -------------
19 // This header should NOT include any other headers from sanitizer runtime.
20 #include "sanitizer_internal_defs.h"
22 namespace __sanitizer {
24 // internal_X() is a custom implementation of X() for use in RTL.
26 // String functions
27 s64 internal_atoll(const char *nptr);
28 void *internal_memchr(const void *s, int c, uptr n);
29 int internal_memcmp(const void* s1, const void* s2, uptr n);
30 void *internal_memcpy(void *dest, const void *src, uptr n);
31 void *internal_memmove(void *dest, const void *src, uptr n);
32 // Should not be used in performance-critical places.
33 void *internal_memset(void *s, int c, uptr n);
34 char* internal_strchr(const char *s, int c);
35 int internal_strcmp(const char *s1, const char *s2);
36 uptr internal_strcspn(const char *s, const char *reject);
37 char *internal_strdup(const char *s);
38 uptr internal_strlen(const char *s);
39 char *internal_strncat(char *dst, const char *src, uptr n);
40 int internal_strncmp(const char *s1, const char *s2, uptr n);
41 char *internal_strncpy(char *dst, const char *src, uptr n);
42 uptr internal_strnlen(const char *s, uptr maxlen);
43 char *internal_strrchr(const char *s, int c);
44 // This is O(N^2), but we are not using it in hot places.
45 char *internal_strstr(const char *haystack, const char *needle);
46 // Works only for base=10 and doesn't set errno.
47 s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
49 // Return true if all bytes in [mem, mem+size) are zero.
50 // Optimized for the case when the result is true.
51 bool mem_is_zero(const char *mem, uptr size);
54 // Memory
55 void *internal_mmap(void *addr, uptr length, int prot, int flags,
56 int fd, u64 offset);
57 int internal_munmap(void *addr, uptr length);
59 // I/O
60 const fd_t kInvalidFd = -1;
61 const fd_t kStdinFd = 0;
62 const fd_t kStdoutFd = 1;
63 const fd_t kStderrFd = 2;
64 int internal_close(fd_t fd);
65 int internal_isatty(fd_t fd);
67 // Use __sanitizer::OpenFile() instead.
68 fd_t internal_open(const char *filename, int flags);
69 fd_t internal_open(const char *filename, int flags, u32 mode);
71 uptr internal_read(fd_t fd, void *buf, uptr count);
72 uptr internal_write(fd_t fd, const void *buf, uptr count);
73 uptr internal_filesize(fd_t fd); // -1 on error.
74 int internal_stat(const char *path, void *buf);
75 int internal_lstat(const char *path, void *buf);
76 int internal_fstat(fd_t fd, void *buf);
78 int internal_dup2(int oldfd, int newfd);
79 uptr internal_readlink(const char *path, char *buf, uptr bufsize);
80 int internal_snprintf(char *buffer, uptr length, const char *format, ...);
82 // Threading
83 int internal_sched_yield();
85 } // namespace __sanitizer
87 #endif // SANITIZER_LIBC_H