1 //===-- sanitizer_posix.h -------------------------------------------------===// 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 and declares some useful POSIX-specific functions. 12 //===----------------------------------------------------------------------===// 13 #ifndef SANITIZER_POSIX_H 14 #define SANITIZER_POSIX_H 15 16 // ----------- ATTENTION ------------- 17 // This header should NOT include any other headers from sanitizer runtime. 18 #include "sanitizer_internal_defs.h" 19 #include "sanitizer_platform_limits_posix.h" 20 21 #if !SANITIZER_POSIX 22 // Make it hard to accidentally use any of functions declared in this file: 23 #error This file should only be included on POSIX 24 #endif 25 26 namespace __sanitizer { 27 28 // I/O 29 // Don't use directly, use __sanitizer::OpenFile() instead. 30 uptr internal_open(const char *filename, int flags); 31 uptr internal_open(const char *filename, int flags, u32 mode); 32 uptr internal_close(fd_t fd); 33 34 uptr internal_read(fd_t fd, void *buf, uptr count); 35 uptr internal_write(fd_t fd, const void *buf, uptr count); 36 37 // Memory 38 uptr internal_mmap(void *addr, uptr length, int prot, int flags, 39 int fd, OFF_T offset); 40 uptr internal_munmap(void *addr, uptr length); 41 int internal_mprotect(void *addr, uptr length, int prot); 42 43 // OS 44 uptr internal_filesize(fd_t fd); // -1 on error. 45 uptr internal_stat(const char *path, void *buf); 46 uptr internal_lstat(const char *path, void *buf); 47 uptr internal_fstat(fd_t fd, void *buf); 48 uptr internal_dup2(int oldfd, int newfd); 49 uptr internal_readlink(const char *path, char *buf, uptr bufsize); 50 uptr internal_unlink(const char *path); 51 uptr internal_rename(const char *oldpath, const char *newpath); 52 uptr internal_lseek(fd_t fd, OFF_T offset, int whence); 53 54 uptr internal_ptrace(int request, int pid, void *addr, void *data); 55 uptr internal_waitpid(int pid, int *status, int options); 56 57 int internal_fork(); 58 int internal_forkpty(int *amaster); 59 60 // These functions call appropriate pthread_ functions directly, bypassing 61 // the interceptor. They are weak and may not be present in some tools. 62 SANITIZER_WEAK_ATTRIBUTE 63 int real_pthread_create(void *th, void *attr, void *(*callback)(void *), 64 void *param); 65 SANITIZER_WEAK_ATTRIBUTE 66 int real_pthread_join(void *th, void **ret); 67 68 #define DEFINE_REAL_PTHREAD_FUNCTIONS \ 69 namespace __sanitizer { \ 70 int real_pthread_create(void *th, void *attr, void *(*callback)(void *), \ 71 void *param) { \ 72 return REAL(pthread_create)(th, attr, callback, param); \ 73 } \ 74 int real_pthread_join(void *th, void **ret) { \ 75 return REAL(pthread_join(th, ret)); \ 76 } \ 77 } // namespace __sanitizer 78 79 int my_pthread_attr_getstack(void *attr, void **addr, uptr *size); 80 81 // A routine named real_sigaction() must be implemented by each sanitizer in 82 // order for internal_sigaction() to bypass interceptors. 83 int internal_sigaction(int signum, const void *act, void *oldact); 84 void internal_sigfillset(__sanitizer_sigset_t *set); 85 void internal_sigemptyset(__sanitizer_sigset_t *set); 86 bool internal_sigismember(__sanitizer_sigset_t *set, int signum); 87 88 uptr internal_execve(const char *filename, char *const argv[], 89 char *const envp[]); 90 } // namespace __sanitizer 91 92 #endif // SANITIZER_POSIX_H 93