145
|
1 //===-- sanitizer_platform_limits_openbsd.cpp -----------------------------===//
|
|
2 //
|
|
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
|
|
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);
|
|
75 unsigned struct_itimerval_sz = sizeof(struct itimerval);
|
|
76 unsigned pthread_t_sz = sizeof(pthread_t);
|
|
77 unsigned pthread_mutex_t_sz = sizeof(pthread_mutex_t);
|
|
78 unsigned pthread_cond_t_sz = sizeof(pthread_cond_t);
|
|
79 unsigned pid_t_sz = sizeof(pid_t);
|
|
80 unsigned timeval_sz = sizeof(timeval);
|
|
81 unsigned uid_t_sz = sizeof(uid_t);
|
|
82 unsigned gid_t_sz = sizeof(gid_t);
|
|
83 unsigned mbstate_t_sz = sizeof(mbstate_t);
|
|
84 unsigned sigset_t_sz = sizeof(sigset_t);
|
|
85 unsigned struct_timezone_sz = sizeof(struct timezone);
|
|
86 unsigned struct_tms_sz = sizeof(struct tms);
|
|
87 unsigned struct_sched_param_sz = sizeof(struct sched_param);
|
|
88 unsigned struct_sockaddr_sz = sizeof(struct sockaddr);
|
|
89 unsigned struct_rlimit_sz = sizeof(struct rlimit);
|
|
90 unsigned struct_timespec_sz = sizeof(struct timespec);
|
|
91 unsigned struct_utimbuf_sz = sizeof(struct utimbuf);
|
|
92 unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
|
|
93 unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
|
|
94 unsigned struct_statvfs_sz = sizeof(struct statvfs);
|
|
95
|
|
96 const uptr sig_ign = (uptr)SIG_IGN;
|
|
97 const uptr sig_dfl = (uptr)SIG_DFL;
|
|
98 const uptr sig_err = (uptr)SIG_ERR;
|
|
99 const uptr sa_siginfo = (uptr)SA_SIGINFO;
|
|
100
|
|
101 int shmctl_ipc_stat = (int)IPC_STAT;
|
|
102
|
|
103 unsigned struct_utmp_sz = sizeof(struct utmp);
|
|
104
|
|
105 int map_fixed = MAP_FIXED;
|
|
106
|
|
107 int af_inet = (int)AF_INET;
|
|
108 int af_inet6 = (int)AF_INET6;
|
|
109
|
|
110 uptr __sanitizer_in_addr_sz(int af) {
|
|
111 if (af == AF_INET)
|
|
112 return sizeof(struct in_addr);
|
|
113 else if (af == AF_INET6)
|
|
114 return sizeof(struct in6_addr);
|
|
115 else
|
|
116 return 0;
|
|
117 }
|
|
118
|
|
119 unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
|
|
120
|
|
121 int glob_nomatch = GLOB_NOMATCH;
|
|
122 int glob_altdirfunc = GLOB_ALTDIRFUNC;
|
|
123
|
|
124 unsigned path_max = PATH_MAX;
|
|
125
|
|
126 const int si_SEGV_MAPERR = SEGV_MAPERR;
|
|
127 const int si_SEGV_ACCERR = SEGV_ACCERR;
|
|
128 } // namespace __sanitizer
|
|
129
|
|
130 using namespace __sanitizer;
|
|
131
|
|
132 COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
|
|
133
|
|
134 COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
|
|
135 CHECK_TYPE_SIZE(pthread_key_t);
|
|
136
|
|
137 CHECK_TYPE_SIZE(dl_phdr_info);
|
|
138 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr);
|
|
139 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
|
|
140 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
|
|
141 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
|
|
142
|
|
143 CHECK_TYPE_SIZE(glob_t);
|
|
144 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
|
|
145 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
|
|
146 CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
|
|
147 CHECK_SIZE_AND_OFFSET(glob_t, gl_flags);
|
|
148 CHECK_SIZE_AND_OFFSET(glob_t, gl_closedir);
|
|
149 CHECK_SIZE_AND_OFFSET(glob_t, gl_readdir);
|
|
150 CHECK_SIZE_AND_OFFSET(glob_t, gl_opendir);
|
|
151 CHECK_SIZE_AND_OFFSET(glob_t, gl_lstat);
|
|
152 CHECK_SIZE_AND_OFFSET(glob_t, gl_stat);
|
|
153
|
|
154 CHECK_TYPE_SIZE(addrinfo);
|
|
155 CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags);
|
|
156 CHECK_SIZE_AND_OFFSET(addrinfo, ai_family);
|
|
157 CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype);
|
|
158 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
|
|
159 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen);
|
|
160 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr);
|
|
161 CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname);
|
|
162 CHECK_SIZE_AND_OFFSET(addrinfo, ai_next);
|
|
163
|
|
164 CHECK_TYPE_SIZE(hostent);
|
|
165 CHECK_SIZE_AND_OFFSET(hostent, h_name);
|
|
166 CHECK_SIZE_AND_OFFSET(hostent, h_aliases);
|
|
167 CHECK_SIZE_AND_OFFSET(hostent, h_addrtype);
|
|
168 CHECK_SIZE_AND_OFFSET(hostent, h_length);
|
|
169 CHECK_SIZE_AND_OFFSET(hostent, h_addr_list);
|
|
170
|
|
171 CHECK_TYPE_SIZE(iovec);
|
|
172 CHECK_SIZE_AND_OFFSET(iovec, iov_base);
|
|
173 CHECK_SIZE_AND_OFFSET(iovec, iov_len);
|
|
174
|
|
175 CHECK_TYPE_SIZE(msghdr);
|
|
176 CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
|
|
177 CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
|
|
178 CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
|
|
179 CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
|
|
180 CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
|
|
181 CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
|
|
182 CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
|
|
183
|
|
184 CHECK_TYPE_SIZE(cmsghdr);
|
|
185 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
|
|
186 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
|
|
187 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
|
|
188
|
|
189 COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
|
|
190 CHECK_SIZE_AND_OFFSET(dirent, d_fileno);
|
|
191 CHECK_SIZE_AND_OFFSET(dirent, d_off);
|
|
192 CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
|
|
193
|
|
194 CHECK_TYPE_SIZE(ifconf);
|
|
195 CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
|
|
196 CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
|
|
197
|
|
198 CHECK_TYPE_SIZE(pollfd);
|
|
199 CHECK_SIZE_AND_OFFSET(pollfd, fd);
|
|
200 CHECK_SIZE_AND_OFFSET(pollfd, events);
|
|
201 CHECK_SIZE_AND_OFFSET(pollfd, revents);
|
|
202
|
|
203 CHECK_TYPE_SIZE(nfds_t);
|
|
204
|
|
205 CHECK_TYPE_SIZE(sigset_t);
|
|
206
|
|
207 COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction));
|
|
208 // Can't write checks for sa_handler and sa_sigaction due to them being
|
|
209 // preprocessor macros.
|
|
210 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
|
|
211
|
|
212 CHECK_TYPE_SIZE(tm);
|
|
213 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
|
|
214 CHECK_SIZE_AND_OFFSET(tm, tm_min);
|
|
215 CHECK_SIZE_AND_OFFSET(tm, tm_hour);
|
|
216 CHECK_SIZE_AND_OFFSET(tm, tm_mday);
|
|
217 CHECK_SIZE_AND_OFFSET(tm, tm_mon);
|
|
218 CHECK_SIZE_AND_OFFSET(tm, tm_year);
|
|
219 CHECK_SIZE_AND_OFFSET(tm, tm_wday);
|
|
220 CHECK_SIZE_AND_OFFSET(tm, tm_yday);
|
|
221 CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
|
|
222 CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff);
|
|
223 CHECK_SIZE_AND_OFFSET(tm, tm_zone);
|
|
224
|
|
225 CHECK_TYPE_SIZE(ipc_perm);
|
|
226 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
|
|
227 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
|
|
228 CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
|
|
229 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
|
|
230 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
|
|
231 CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
|
|
232 CHECK_SIZE_AND_OFFSET(ipc_perm, key);
|
|
233
|
|
234 CHECK_TYPE_SIZE(shmid_ds);
|
|
235 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);
|
|
236 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz);
|
|
237 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime);
|
|
238 CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_atimensec);
|
|
239 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime);
|
|
240 CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_dtimensec);
|
|
241 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime);
|
|
242 CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_ctimensec);
|
|
243 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid);
|
|
244 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
|
|
245 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
|
|
246
|
|
247 CHECK_TYPE_SIZE(clock_t);
|
|
248
|
|
249 CHECK_TYPE_SIZE(ifaddrs);
|
|
250 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
|
|
251 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
|
|
252 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
|
|
253 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask);
|
|
254 // Compare against the union, because we can't reach into the union in a
|
|
255 // compliant way.
|
|
256 #ifdef ifa_dstaddr
|
|
257 #undef ifa_dstaddr
|
|
258 #endif
|
|
259 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
|
|
260 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
|
|
261
|
|
262 CHECK_TYPE_SIZE(passwd);
|
|
263 CHECK_SIZE_AND_OFFSET(passwd, pw_name);
|
|
264 CHECK_SIZE_AND_OFFSET(passwd, pw_passwd);
|
|
265 CHECK_SIZE_AND_OFFSET(passwd, pw_uid);
|
|
266 CHECK_SIZE_AND_OFFSET(passwd, pw_gid);
|
|
267 CHECK_SIZE_AND_OFFSET(passwd, pw_dir);
|
|
268 CHECK_SIZE_AND_OFFSET(passwd, pw_shell);
|
|
269
|
|
270 CHECK_SIZE_AND_OFFSET(passwd, pw_gecos);
|
|
271
|
|
272 CHECK_TYPE_SIZE(group);
|
|
273 CHECK_SIZE_AND_OFFSET(group, gr_name);
|
|
274 CHECK_SIZE_AND_OFFSET(group, gr_passwd);
|
|
275 CHECK_SIZE_AND_OFFSET(group, gr_gid);
|
|
276 CHECK_SIZE_AND_OFFSET(group, gr_mem);
|
|
277
|
|
278 #endif // SANITIZER_OPENBSD
|