]>
Commit | Line | Data |
---|---|---|
b667dd70 | 1 | //===-- sanitizer_platform_limits_openbsd.cpp -----------------------------===// |
eac97531 | 2 | // |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
eac97531 ML |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is a part of Sanitizer common code. | |
10 | // | |
11 | // Sizes and layouts of platform-specific NetBSD data structures. | |
12 | //===----------------------------------------------------------------------===// | |
13 | ||
14 | #include "sanitizer_platform.h" | |
15 | ||
16 | #if SANITIZER_OPENBSD | |
17 | #include <arpa/inet.h> | |
18 | #include <dirent.h> | |
19 | #include <glob.h> | |
20 | #include <grp.h> | |
21 | #include <ifaddrs.h> | |
22 | #include <limits.h> | |
23 | #include <link_elf.h> | |
24 | #include <sys/socket.h> | |
25 | #include <net/if.h> | |
26 | #include <net/ppp_defs.h> | |
27 | #include <net/route.h> | |
28 | #include <netdb.h> | |
29 | #include <netinet/in.h> | |
30 | #include <netinet/ip_mroute.h> | |
31 | #include <poll.h> | |
32 | #include <pthread.h> | |
33 | #include <pwd.h> | |
34 | #include <semaphore.h> | |
35 | #include <signal.h> | |
36 | #include <soundcard.h> | |
37 | #include <stddef.h> | |
38 | #include <stdint.h> | |
39 | #include <sys/filio.h> | |
40 | #include <sys/ipc.h> | |
41 | #include <sys/mman.h> | |
42 | #include <sys/mount.h> | |
43 | #include <sys/msg.h> | |
44 | #include <sys/mtio.h> | |
45 | #include <sys/ptrace.h> | |
46 | #include <sys/resource.h> | |
47 | #include <sys/shm.h> | |
48 | #include <sys/signal.h> | |
49 | #include <sys/sockio.h> | |
50 | #include <sys/stat.h> | |
51 | #include <sys/statvfs.h> | |
52 | #include <sys/time.h> | |
53 | #include <sys/times.h> | |
54 | #include <sys/types.h> | |
55 | #include <sys/utsname.h> | |
56 | #include <term.h> | |
57 | #include <time.h> | |
58 | #include <utime.h> | |
59 | #include <utmp.h> | |
60 | #include <wchar.h> | |
61 | ||
62 | // Include these after system headers to avoid name clashes and ambiguities. | |
63 | #include "sanitizer_internal_defs.h" | |
64 | #include "sanitizer_platform_limits_openbsd.h" | |
65 | ||
66 | namespace __sanitizer { | |
67 | unsigned struct_utsname_sz = sizeof(struct utsname); | |
68 | unsigned struct_stat_sz = sizeof(struct stat); | |
69 | unsigned struct_rusage_sz = sizeof(struct rusage); | |
70 | unsigned struct_tm_sz = sizeof(struct tm); | |
71 | unsigned struct_passwd_sz = sizeof(struct passwd); | |
72 | unsigned struct_group_sz = sizeof(struct group); | |
73 | unsigned siginfo_t_sz = sizeof(siginfo_t); | |
74 | unsigned struct_sigaction_sz = sizeof(struct sigaction); | |
3c6331c2 | 75 | unsigned struct_stack_t_sz = sizeof(stack_t); |
eac97531 ML |
76 | unsigned struct_itimerval_sz = sizeof(struct itimerval); |
77 | unsigned pthread_t_sz = sizeof(pthread_t); | |
78 | unsigned pthread_mutex_t_sz = sizeof(pthread_mutex_t); | |
79 | unsigned pthread_cond_t_sz = sizeof(pthread_cond_t); | |
80 | unsigned pid_t_sz = sizeof(pid_t); | |
81 | unsigned timeval_sz = sizeof(timeval); | |
82 | unsigned uid_t_sz = sizeof(uid_t); | |
83 | unsigned gid_t_sz = sizeof(gid_t); | |
84 | unsigned mbstate_t_sz = sizeof(mbstate_t); | |
85 | unsigned sigset_t_sz = sizeof(sigset_t); | |
86 | unsigned struct_timezone_sz = sizeof(struct timezone); | |
87 | unsigned struct_tms_sz = sizeof(struct tms); | |
88 | unsigned struct_sched_param_sz = sizeof(struct sched_param); | |
89 | unsigned struct_sockaddr_sz = sizeof(struct sockaddr); | |
90 | unsigned struct_rlimit_sz = sizeof(struct rlimit); | |
91 | unsigned struct_timespec_sz = sizeof(struct timespec); | |
92 | unsigned struct_utimbuf_sz = sizeof(struct utimbuf); | |
93 | unsigned struct_itimerspec_sz = sizeof(struct itimerspec); | |
94 | unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds); | |
95 | unsigned struct_statvfs_sz = sizeof(struct statvfs); | |
96 | ||
97 | const uptr sig_ign = (uptr)SIG_IGN; | |
98 | const uptr sig_dfl = (uptr)SIG_DFL; | |
99 | const uptr sig_err = (uptr)SIG_ERR; | |
100 | const uptr sa_siginfo = (uptr)SA_SIGINFO; | |
101 | ||
102 | int shmctl_ipc_stat = (int)IPC_STAT; | |
103 | ||
104 | unsigned struct_utmp_sz = sizeof(struct utmp); | |
105 | ||
106 | int map_fixed = MAP_FIXED; | |
107 | ||
108 | int af_inet = (int)AF_INET; | |
109 | int af_inet6 = (int)AF_INET6; | |
110 | ||
111 | uptr __sanitizer_in_addr_sz(int af) { | |
112 | if (af == AF_INET) | |
113 | return sizeof(struct in_addr); | |
114 | else if (af == AF_INET6) | |
115 | return sizeof(struct in6_addr); | |
116 | else | |
117 | return 0; | |
118 | } | |
119 | ||
120 | unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); | |
121 | ||
122 | int glob_nomatch = GLOB_NOMATCH; | |
123 | int glob_altdirfunc = GLOB_ALTDIRFUNC; | |
124 | ||
125 | unsigned path_max = PATH_MAX; | |
126 | ||
127 | const int si_SEGV_MAPERR = SEGV_MAPERR; | |
128 | const int si_SEGV_ACCERR = SEGV_ACCERR; | |
129 | } // namespace __sanitizer | |
130 | ||
131 | using namespace __sanitizer; | |
132 | ||
133 | COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t)); | |
134 | ||
135 | COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned)); | |
136 | CHECK_TYPE_SIZE(pthread_key_t); | |
137 | ||
138 | CHECK_TYPE_SIZE(dl_phdr_info); | |
139 | CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr); | |
140 | CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name); | |
141 | CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr); | |
142 | CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum); | |
143 | ||
144 | CHECK_TYPE_SIZE(glob_t); | |
145 | CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc); | |
146 | CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv); | |
147 | CHECK_SIZE_AND_OFFSET(glob_t, gl_offs); | |
148 | CHECK_SIZE_AND_OFFSET(glob_t, gl_flags); | |
149 | CHECK_SIZE_AND_OFFSET(glob_t, gl_closedir); | |
150 | CHECK_SIZE_AND_OFFSET(glob_t, gl_readdir); | |
151 | CHECK_SIZE_AND_OFFSET(glob_t, gl_opendir); | |
152 | CHECK_SIZE_AND_OFFSET(glob_t, gl_lstat); | |
153 | CHECK_SIZE_AND_OFFSET(glob_t, gl_stat); | |
154 | ||
155 | CHECK_TYPE_SIZE(addrinfo); | |
156 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags); | |
157 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_family); | |
158 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype); | |
159 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol); | |
160 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen); | |
161 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr); | |
162 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname); | |
163 | CHECK_SIZE_AND_OFFSET(addrinfo, ai_next); | |
164 | ||
165 | CHECK_TYPE_SIZE(hostent); | |
166 | CHECK_SIZE_AND_OFFSET(hostent, h_name); | |
167 | CHECK_SIZE_AND_OFFSET(hostent, h_aliases); | |
168 | CHECK_SIZE_AND_OFFSET(hostent, h_addrtype); | |
169 | CHECK_SIZE_AND_OFFSET(hostent, h_length); | |
170 | CHECK_SIZE_AND_OFFSET(hostent, h_addr_list); | |
171 | ||
172 | CHECK_TYPE_SIZE(iovec); | |
173 | CHECK_SIZE_AND_OFFSET(iovec, iov_base); | |
174 | CHECK_SIZE_AND_OFFSET(iovec, iov_len); | |
175 | ||
176 | CHECK_TYPE_SIZE(msghdr); | |
177 | CHECK_SIZE_AND_OFFSET(msghdr, msg_name); | |
178 | CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen); | |
179 | CHECK_SIZE_AND_OFFSET(msghdr, msg_iov); | |
180 | CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen); | |
181 | CHECK_SIZE_AND_OFFSET(msghdr, msg_control); | |
182 | CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen); | |
183 | CHECK_SIZE_AND_OFFSET(msghdr, msg_flags); | |
184 | ||
185 | CHECK_TYPE_SIZE(cmsghdr); | |
186 | CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len); | |
187 | CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level); | |
188 | CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type); | |
189 | ||
190 | COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent)); | |
191 | CHECK_SIZE_AND_OFFSET(dirent, d_fileno); | |
192 | CHECK_SIZE_AND_OFFSET(dirent, d_off); | |
193 | CHECK_SIZE_AND_OFFSET(dirent, d_reclen); | |
194 | ||
195 | CHECK_TYPE_SIZE(ifconf); | |
196 | CHECK_SIZE_AND_OFFSET(ifconf, ifc_len); | |
197 | CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu); | |
198 | ||
199 | CHECK_TYPE_SIZE(pollfd); | |
200 | CHECK_SIZE_AND_OFFSET(pollfd, fd); | |
201 | CHECK_SIZE_AND_OFFSET(pollfd, events); | |
202 | CHECK_SIZE_AND_OFFSET(pollfd, revents); | |
203 | ||
204 | CHECK_TYPE_SIZE(nfds_t); | |
205 | ||
206 | CHECK_TYPE_SIZE(sigset_t); | |
207 | ||
208 | COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction)); | |
209 | // Can't write checks for sa_handler and sa_sigaction due to them being | |
210 | // preprocessor macros. | |
211 | CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask); | |
212 | ||
213 | CHECK_TYPE_SIZE(tm); | |
214 | CHECK_SIZE_AND_OFFSET(tm, tm_sec); | |
215 | CHECK_SIZE_AND_OFFSET(tm, tm_min); | |
216 | CHECK_SIZE_AND_OFFSET(tm, tm_hour); | |
217 | CHECK_SIZE_AND_OFFSET(tm, tm_mday); | |
218 | CHECK_SIZE_AND_OFFSET(tm, tm_mon); | |
219 | CHECK_SIZE_AND_OFFSET(tm, tm_year); | |
220 | CHECK_SIZE_AND_OFFSET(tm, tm_wday); | |
221 | CHECK_SIZE_AND_OFFSET(tm, tm_yday); | |
222 | CHECK_SIZE_AND_OFFSET(tm, tm_isdst); | |
223 | CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff); | |
224 | CHECK_SIZE_AND_OFFSET(tm, tm_zone); | |
225 | ||
226 | CHECK_TYPE_SIZE(ipc_perm); | |
227 | CHECK_SIZE_AND_OFFSET(ipc_perm, cuid); | |
228 | CHECK_SIZE_AND_OFFSET(ipc_perm, cgid); | |
229 | CHECK_SIZE_AND_OFFSET(ipc_perm, uid); | |
230 | CHECK_SIZE_AND_OFFSET(ipc_perm, gid); | |
231 | CHECK_SIZE_AND_OFFSET(ipc_perm, mode); | |
232 | CHECK_SIZE_AND_OFFSET(ipc_perm, seq); | |
233 | CHECK_SIZE_AND_OFFSET(ipc_perm, key); | |
234 | ||
235 | CHECK_TYPE_SIZE(shmid_ds); | |
236 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm); | |
237 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz); | |
238 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime); | |
239 | CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_atimensec); | |
240 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime); | |
241 | CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_dtimensec); | |
242 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime); | |
243 | CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_ctimensec); | |
244 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid); | |
245 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid); | |
246 | CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch); | |
247 | ||
248 | CHECK_TYPE_SIZE(clock_t); | |
249 | ||
250 | CHECK_TYPE_SIZE(ifaddrs); | |
251 | CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next); | |
252 | CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name); | |
253 | CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr); | |
254 | CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask); | |
255 | // Compare against the union, because we can't reach into the union in a | |
256 | // compliant way. | |
257 | #ifdef ifa_dstaddr | |
258 | #undef ifa_dstaddr | |
259 | #endif | |
260 | CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr); | |
261 | CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data); | |
262 | ||
263 | CHECK_TYPE_SIZE(passwd); | |
264 | CHECK_SIZE_AND_OFFSET(passwd, pw_name); | |
265 | CHECK_SIZE_AND_OFFSET(passwd, pw_passwd); | |
266 | CHECK_SIZE_AND_OFFSET(passwd, pw_uid); | |
267 | CHECK_SIZE_AND_OFFSET(passwd, pw_gid); | |
268 | CHECK_SIZE_AND_OFFSET(passwd, pw_dir); | |
269 | CHECK_SIZE_AND_OFFSET(passwd, pw_shell); | |
270 | ||
271 | CHECK_SIZE_AND_OFFSET(passwd, pw_gecos); | |
272 | ||
273 | CHECK_TYPE_SIZE(group); | |
274 | CHECK_SIZE_AND_OFFSET(group, gr_name); | |
275 | CHECK_SIZE_AND_OFFSET(group, gr_passwd); | |
276 | CHECK_SIZE_AND_OFFSET(group, gr_gid); | |
277 | CHECK_SIZE_AND_OFFSET(group, gr_mem); | |
278 | ||
279 | #endif // SANITIZER_OPENBSD |