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