annotate libsanitizer/sanitizer_common/sanitizer_posix.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 //===-- sanitizer_posix.h -------------------------------------------------===//
kono
parents:
diff changeset
2 //
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
111
kono
parents:
diff changeset
6 //
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
8 //
kono
parents:
diff changeset
9 // This file is shared between AddressSanitizer and ThreadSanitizer
kono
parents:
diff changeset
10 // run-time libraries and declares some useful POSIX-specific functions.
kono
parents:
diff changeset
11 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
12 #ifndef SANITIZER_POSIX_H
kono
parents:
diff changeset
13 #define SANITIZER_POSIX_H
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 // ----------- ATTENTION -------------
kono
parents:
diff changeset
16 // This header should NOT include any other headers from sanitizer runtime.
kono
parents:
diff changeset
17 #include "sanitizer_internal_defs.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
18 #include "sanitizer_platform_limits_freebsd.h"
111
kono
parents:
diff changeset
19 #include "sanitizer_platform_limits_netbsd.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
20 #include "sanitizer_platform_limits_openbsd.h"
111
kono
parents:
diff changeset
21 #include "sanitizer_platform_limits_posix.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
22 #include "sanitizer_platform_limits_solaris.h"
111
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #if !SANITIZER_POSIX
kono
parents:
diff changeset
25 // Make it hard to accidentally use any of functions declared in this file:
kono
parents:
diff changeset
26 #error This file should only be included on POSIX
kono
parents:
diff changeset
27 #endif
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 namespace __sanitizer {
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 // I/O
kono
parents:
diff changeset
32 // Don't use directly, use __sanitizer::OpenFile() instead.
kono
parents:
diff changeset
33 uptr internal_open(const char *filename, int flags);
kono
parents:
diff changeset
34 uptr internal_open(const char *filename, int flags, u32 mode);
kono
parents:
diff changeset
35 uptr internal_close(fd_t fd);
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 uptr internal_read(fd_t fd, void *buf, uptr count);
kono
parents:
diff changeset
38 uptr internal_write(fd_t fd, const void *buf, uptr count);
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 // Memory
kono
parents:
diff changeset
41 uptr internal_mmap(void *addr, uptr length, int prot, int flags,
kono
parents:
diff changeset
42 int fd, OFF_T offset);
kono
parents:
diff changeset
43 uptr internal_munmap(void *addr, uptr length);
kono
parents:
diff changeset
44 int internal_mprotect(void *addr, uptr length, int prot);
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 // OS
kono
parents:
diff changeset
47 uptr internal_filesize(fd_t fd); // -1 on error.
kono
parents:
diff changeset
48 uptr internal_stat(const char *path, void *buf);
kono
parents:
diff changeset
49 uptr internal_lstat(const char *path, void *buf);
kono
parents:
diff changeset
50 uptr internal_fstat(fd_t fd, void *buf);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
51 uptr internal_dup(int oldfd);
111
kono
parents:
diff changeset
52 uptr internal_dup2(int oldfd, int newfd);
kono
parents:
diff changeset
53 uptr internal_readlink(const char *path, char *buf, uptr bufsize);
kono
parents:
diff changeset
54 uptr internal_unlink(const char *path);
kono
parents:
diff changeset
55 uptr internal_rename(const char *oldpath, const char *newpath);
kono
parents:
diff changeset
56 uptr internal_lseek(fd_t fd, OFF_T offset, int whence);
kono
parents:
diff changeset
57
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
58 #if SANITIZER_NETBSD
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
59 uptr internal_ptrace(int request, int pid, void *addr, int data);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
60 #else
111
kono
parents:
diff changeset
61 uptr internal_ptrace(int request, int pid, void *addr, void *data);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
62 #endif
111
kono
parents:
diff changeset
63 uptr internal_waitpid(int pid, int *status, int options);
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 int internal_fork();
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
66 fd_t internal_spawn(const char *argv[], pid_t *pid);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
67
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
68 int internal_sysctl(const int *name, unsigned int namelen, void *oldp,
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
69 uptr *oldlenp, const void *newp, uptr newlen);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
70 int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
71 const void *newp, uptr newlen);
111
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 // These functions call appropriate pthread_ functions directly, bypassing
kono
parents:
diff changeset
74 // the interceptor. They are weak and may not be present in some tools.
kono
parents:
diff changeset
75 SANITIZER_WEAK_ATTRIBUTE
kono
parents:
diff changeset
76 int real_pthread_create(void *th, void *attr, void *(*callback)(void *),
kono
parents:
diff changeset
77 void *param);
kono
parents:
diff changeset
78 SANITIZER_WEAK_ATTRIBUTE
kono
parents:
diff changeset
79 int real_pthread_join(void *th, void **ret);
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 #define DEFINE_REAL_PTHREAD_FUNCTIONS \
kono
parents:
diff changeset
82 namespace __sanitizer { \
kono
parents:
diff changeset
83 int real_pthread_create(void *th, void *attr, void *(*callback)(void *), \
kono
parents:
diff changeset
84 void *param) { \
kono
parents:
diff changeset
85 return REAL(pthread_create)(th, attr, callback, param); \
kono
parents:
diff changeset
86 } \
kono
parents:
diff changeset
87 int real_pthread_join(void *th, void **ret) { \
kono
parents:
diff changeset
88 return REAL(pthread_join(th, ret)); \
kono
parents:
diff changeset
89 } \
kono
parents:
diff changeset
90 } // namespace __sanitizer
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 int my_pthread_attr_getstack(void *attr, void **addr, uptr *size);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 // A routine named real_sigaction() must be implemented by each sanitizer in
kono
parents:
diff changeset
95 // order for internal_sigaction() to bypass interceptors.
kono
parents:
diff changeset
96 int internal_sigaction(int signum, const void *act, void *oldact);
kono
parents:
diff changeset
97 void internal_sigfillset(__sanitizer_sigset_t *set);
kono
parents:
diff changeset
98 void internal_sigemptyset(__sanitizer_sigset_t *set);
kono
parents:
diff changeset
99 bool internal_sigismember(__sanitizer_sigset_t *set, int signum);
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 uptr internal_execve(const char *filename, char *const argv[],
kono
parents:
diff changeset
102 char *const envp[]);
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 bool IsStateDetached(int state);
kono
parents:
diff changeset
105
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
106 // Move the fd out of {0, 1, 2} range.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
107 fd_t ReserveStandardFds(fd_t fd);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
108
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
109 bool ShouldMockFailureToOpen(const char *path);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
110
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
111 // Create a non-file mapping with a given /proc/self/maps name.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
112 uptr MmapNamed(void *addr, uptr length, int prot, int flags, const char *name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
113
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
114 // Platforms should implement at most one of these.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
115 // 1. Provide a pre-decorated file descriptor to use instead of an anonymous
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
116 // mapping.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
117 int GetNamedMappingFd(const char *name, uptr size, int *flags);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
118 // 2. Add name to an existing anonymous mapping. The caller must keep *name
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
119 // alive at least as long as the mapping exists.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
120 void DecorateMapping(uptr addr, uptr size, const char *name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
121
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
122
111
kono
parents:
diff changeset
123 } // namespace __sanitizer
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 #endif // SANITIZER_POSIX_H