• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- sanitizer_platform_limits_freebsd.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 FreeBSD data structures.
12 //===----------------------------------------------------------------------===//
13 
14 #include "sanitizer_platform.h"
15 
16 #if SANITIZER_FREEBSD
17 
18 #include <sys/capsicum.h>
19 #include <sys/consio.h>
20 #include <sys/filio.h>
21 #include <sys/ipc.h>
22 #include <sys/kbio.h>
23 #include <sys/link_elf.h>
24 #include <sys/mman.h>
25 #include <sys/mount.h>
26 #include <sys/mqueue.h>
27 #include <sys/msg.h>
28 #include <sys/mtio.h>
29 #include <sys/ptrace.h>
30 #include <sys/resource.h>
31 #include <sys/signal.h>
32 #include <sys/socket.h>
33 #include <sys/sockio.h>
34 #include <sys/soundcard.h>
35 #include <sys/stat.h>
36 #include <sys/statvfs.h>
37 #include <sys/time.h>
38 #include <sys/timeb.h>
39 #include <sys/times.h>
40 #include <sys/timespec.h>
41 #include <sys/types.h>
42 #include <sys/ucontext.h>
43 #include <sys/utsname.h>
44 //
45 #include <arpa/inet.h>
46 #include <net/ethernet.h>
47 #include <net/if.h>
48 #include <net/ppp_defs.h>
49 #include <net/route.h>
50 #include <netdb.h>
51 #include <netinet/in.h>
52 #include <netinet/ip_mroute.h>
53 //
54 #include <dirent.h>
55 #include <dlfcn.h>
56 #include <fstab.h>
57 #include <fts.h>
58 #include <glob.h>
59 #include <grp.h>
60 #include <ifaddrs.h>
61 #include <limits.h>
62 #include <poll.h>
63 #include <pthread.h>
64 #include <pwd.h>
65 #include <regex.h>
66 #include <semaphore.h>
67 #include <signal.h>
68 #include <stddef.h>
69 #include <stdio.h>
70 #include <stringlist.h>
71 #include <term.h>
72 #include <termios.h>
73 #include <time.h>
74 #include <utime.h>
75 #include <utmpx.h>
76 #include <vis.h>
77 #include <wchar.h>
78 #include <wordexp.h>
79 
80 #define _KERNEL  // to declare 'shminfo' structure
81 #include <sys/shm.h>
82 #undef _KERNEL
83 
84 #undef IOC_DIRMASK
85 
86 // Include these after system headers to avoid name clashes and ambiguities.
87 #include "sanitizer_internal_defs.h"
88 #include "sanitizer_libc.h"
89 #include "sanitizer_platform_limits_freebsd.h"
90 
91 namespace __sanitizer {
__sanitizer_get_link_map_by_dlopen_handle(void * handle)92 void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) {
93   void *p = nullptr;
94   return internal_dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
95 }
96 
97 unsigned struct_cap_rights_sz = sizeof(cap_rights_t);
98 unsigned struct_utsname_sz = sizeof(struct utsname);
99 unsigned struct_stat_sz = sizeof(struct stat);
100 unsigned struct_rusage_sz = sizeof(struct rusage);
101 unsigned struct_tm_sz = sizeof(struct tm);
102 unsigned struct_passwd_sz = sizeof(struct passwd);
103 unsigned struct_group_sz = sizeof(struct group);
104 unsigned siginfo_t_sz = sizeof(siginfo_t);
105 unsigned struct_sigaction_sz = sizeof(struct sigaction);
106 unsigned struct_stack_t_sz = sizeof(stack_t);
107 unsigned struct_itimerval_sz = sizeof(struct itimerval);
108 unsigned pthread_t_sz = sizeof(pthread_t);
109 unsigned pthread_mutex_t_sz = sizeof(pthread_mutex_t);
110 unsigned pthread_cond_t_sz = sizeof(pthread_cond_t);
111 unsigned pid_t_sz = sizeof(pid_t);
112 unsigned timeval_sz = sizeof(timeval);
113 unsigned uid_t_sz = sizeof(uid_t);
114 unsigned gid_t_sz = sizeof(gid_t);
115 unsigned fpos_t_sz = sizeof(fpos_t);
116 unsigned mbstate_t_sz = sizeof(mbstate_t);
117 unsigned sigset_t_sz = sizeof(sigset_t);
118 unsigned struct_timezone_sz = sizeof(struct timezone);
119 unsigned struct_tms_sz = sizeof(struct tms);
120 unsigned struct_sigevent_sz = sizeof(struct sigevent);
121 unsigned struct_sched_param_sz = sizeof(struct sched_param);
122 unsigned struct_statfs_sz = sizeof(struct statfs);
123 unsigned struct_sockaddr_sz = sizeof(struct sockaddr);
124 unsigned ucontext_t_sz = sizeof(ucontext_t);
125 unsigned struct_rlimit_sz = sizeof(struct rlimit);
126 unsigned struct_timespec_sz = sizeof(struct timespec);
127 unsigned struct_utimbuf_sz = sizeof(struct utimbuf);
128 unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
129 unsigned struct_timeb_sz = sizeof(struct timeb);
130 unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
131 unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
132 unsigned struct_statvfs_sz = sizeof(struct statvfs);
133 unsigned struct_shminfo_sz = sizeof(struct shminfo);
134 unsigned struct_shm_info_sz = sizeof(struct shm_info);
135 unsigned struct_regmatch_sz = sizeof(regmatch_t);
136 unsigned struct_regex_sz = sizeof(regex_t);
137 unsigned struct_fstab_sz = sizeof(struct fstab);
138 unsigned struct_FTS_sz = sizeof(FTS);
139 unsigned struct_FTSENT_sz = sizeof(FTSENT);
140 unsigned struct_StringList_sz = sizeof(StringList);
141 
142 const uptr sig_ign = (uptr)SIG_IGN;
143 const uptr sig_dfl = (uptr)SIG_DFL;
144 const uptr sig_err = (uptr)SIG_ERR;
145 const uptr sa_siginfo = (uptr)SA_SIGINFO;
146 
147 int shmctl_ipc_stat = (int)IPC_STAT;
148 int shmctl_ipc_info = (int)IPC_INFO;
149 int shmctl_shm_info = (int)SHM_INFO;
150 int shmctl_shm_stat = (int)SHM_STAT;
151 unsigned struct_utmpx_sz = sizeof(struct utmpx);
152 
153 int map_fixed = MAP_FIXED;
154 
155 int af_inet = (int)AF_INET;
156 int af_inet6 = (int)AF_INET6;
157 
__sanitizer_in_addr_sz(int af)158 uptr __sanitizer_in_addr_sz(int af) {
159   if (af == AF_INET)
160     return sizeof(struct in_addr);
161   else if (af == AF_INET6)
162     return sizeof(struct in6_addr);
163   else
164     return 0;
165 }
166 
167 unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
168 int glob_nomatch = GLOB_NOMATCH;
169 int glob_altdirfunc = GLOB_ALTDIRFUNC;
170 
171 unsigned path_max = PATH_MAX;
172 
173 // ioctl arguments
174 unsigned struct_ifreq_sz = sizeof(struct ifreq);
175 unsigned struct_termios_sz = sizeof(struct termios);
176 unsigned struct_winsize_sz = sizeof(struct winsize);
177 #if SOUND_VERSION >= 0x040000
178 unsigned struct_copr_buffer_sz = 0;
179 unsigned struct_copr_debug_buf_sz = 0;
180 unsigned struct_copr_msg_sz = 0;
181 #else
182 unsigned struct_copr_buffer_sz = sizeof(struct copr_buffer);
183 unsigned struct_copr_debug_buf_sz = sizeof(struct copr_debug_buf);
184 unsigned struct_copr_msg_sz = sizeof(struct copr_msg);
185 #endif
186 unsigned struct_midi_info_sz = sizeof(struct midi_info);
187 unsigned struct_mtget_sz = sizeof(struct mtget);
188 unsigned struct_mtop_sz = sizeof(struct mtop);
189 unsigned struct_sbi_instrument_sz = sizeof(struct sbi_instrument);
190 unsigned struct_seq_event_rec_sz = sizeof(struct seq_event_rec);
191 unsigned struct_synth_info_sz = sizeof(struct synth_info);
192 unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info);
193 unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats);
194 unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req);
195 unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
196 const unsigned long __sanitizer_bufsiz = BUFSIZ;
197 
198 const unsigned IOCTL_NOT_PRESENT = 0;
199 
200 unsigned IOCTL_FIOASYNC = FIOASYNC;
201 unsigned IOCTL_FIOCLEX = FIOCLEX;
202 unsigned IOCTL_FIOGETOWN = FIOGETOWN;
203 unsigned IOCTL_FIONBIO = FIONBIO;
204 unsigned IOCTL_FIONCLEX = FIONCLEX;
205 unsigned IOCTL_FIOSETOWN = FIOSETOWN;
206 unsigned IOCTL_SIOCADDMULTI = SIOCADDMULTI;
207 unsigned IOCTL_SIOCATMARK = SIOCATMARK;
208 unsigned IOCTL_SIOCDELMULTI = SIOCDELMULTI;
209 unsigned IOCTL_SIOCGIFADDR = SIOCGIFADDR;
210 unsigned IOCTL_SIOCGIFBRDADDR = SIOCGIFBRDADDR;
211 unsigned IOCTL_SIOCGIFCONF = SIOCGIFCONF;
212 unsigned IOCTL_SIOCGIFDSTADDR = SIOCGIFDSTADDR;
213 unsigned IOCTL_SIOCGIFFLAGS = SIOCGIFFLAGS;
214 unsigned IOCTL_SIOCGIFMETRIC = SIOCGIFMETRIC;
215 unsigned IOCTL_SIOCGIFMTU = SIOCGIFMTU;
216 unsigned IOCTL_SIOCGIFNETMASK = SIOCGIFNETMASK;
217 unsigned IOCTL_SIOCGPGRP = SIOCGPGRP;
218 unsigned IOCTL_SIOCSIFADDR = SIOCSIFADDR;
219 unsigned IOCTL_SIOCSIFBRDADDR = SIOCSIFBRDADDR;
220 unsigned IOCTL_SIOCSIFDSTADDR = SIOCSIFDSTADDR;
221 unsigned IOCTL_SIOCSIFFLAGS = SIOCSIFFLAGS;
222 unsigned IOCTL_SIOCSIFMETRIC = SIOCSIFMETRIC;
223 unsigned IOCTL_SIOCSIFMTU = SIOCSIFMTU;
224 unsigned IOCTL_SIOCSIFNETMASK = SIOCSIFNETMASK;
225 unsigned IOCTL_SIOCSPGRP = SIOCSPGRP;
226 unsigned IOCTL_TIOCCONS = TIOCCONS;
227 unsigned IOCTL_TIOCEXCL = TIOCEXCL;
228 unsigned IOCTL_TIOCGETD = TIOCGETD;
229 unsigned IOCTL_TIOCGPGRP = TIOCGPGRP;
230 unsigned IOCTL_TIOCGWINSZ = TIOCGWINSZ;
231 unsigned IOCTL_TIOCMBIC = TIOCMBIC;
232 unsigned IOCTL_TIOCMBIS = TIOCMBIS;
233 unsigned IOCTL_TIOCMGET = TIOCMGET;
234 unsigned IOCTL_TIOCMSET = TIOCMSET;
235 unsigned IOCTL_TIOCNOTTY = TIOCNOTTY;
236 unsigned IOCTL_TIOCNXCL = TIOCNXCL;
237 unsigned IOCTL_TIOCOUTQ = TIOCOUTQ;
238 unsigned IOCTL_TIOCPKT = TIOCPKT;
239 unsigned IOCTL_TIOCSCTTY = TIOCSCTTY;
240 unsigned IOCTL_TIOCSETD = TIOCSETD;
241 unsigned IOCTL_TIOCSPGRP = TIOCSPGRP;
242 unsigned IOCTL_TIOCSTI = TIOCSTI;
243 unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ;
244 unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT;
245 unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT;
246 unsigned IOCTL_MTIOCGET = MTIOCGET;
247 unsigned IOCTL_MTIOCTOP = MTIOCTOP;
248 unsigned IOCTL_SNDCTL_DSP_GETBLKSIZE = SNDCTL_DSP_GETBLKSIZE;
249 unsigned IOCTL_SNDCTL_DSP_GETFMTS = SNDCTL_DSP_GETFMTS;
250 unsigned IOCTL_SNDCTL_DSP_NONBLOCK = SNDCTL_DSP_NONBLOCK;
251 unsigned IOCTL_SNDCTL_DSP_POST = SNDCTL_DSP_POST;
252 unsigned IOCTL_SNDCTL_DSP_RESET = SNDCTL_DSP_RESET;
253 unsigned IOCTL_SNDCTL_DSP_SETFMT = SNDCTL_DSP_SETFMT;
254 unsigned IOCTL_SNDCTL_DSP_SETFRAGMENT = SNDCTL_DSP_SETFRAGMENT;
255 unsigned IOCTL_SNDCTL_DSP_SPEED = SNDCTL_DSP_SPEED;
256 unsigned IOCTL_SNDCTL_DSP_STEREO = SNDCTL_DSP_STEREO;
257 unsigned IOCTL_SNDCTL_DSP_SUBDIVIDE = SNDCTL_DSP_SUBDIVIDE;
258 unsigned IOCTL_SNDCTL_DSP_SYNC = SNDCTL_DSP_SYNC;
259 unsigned IOCTL_SNDCTL_FM_4OP_ENABLE = SNDCTL_FM_4OP_ENABLE;
260 unsigned IOCTL_SNDCTL_FM_LOAD_INSTR = SNDCTL_FM_LOAD_INSTR;
261 unsigned IOCTL_SNDCTL_MIDI_INFO = SNDCTL_MIDI_INFO;
262 unsigned IOCTL_SNDCTL_MIDI_PRETIME = SNDCTL_MIDI_PRETIME;
263 unsigned IOCTL_SNDCTL_SEQ_CTRLRATE = SNDCTL_SEQ_CTRLRATE;
264 unsigned IOCTL_SNDCTL_SEQ_GETINCOUNT = SNDCTL_SEQ_GETINCOUNT;
265 unsigned IOCTL_SNDCTL_SEQ_GETOUTCOUNT = SNDCTL_SEQ_GETOUTCOUNT;
266 unsigned IOCTL_SNDCTL_SEQ_NRMIDIS = SNDCTL_SEQ_NRMIDIS;
267 unsigned IOCTL_SNDCTL_SEQ_NRSYNTHS = SNDCTL_SEQ_NRSYNTHS;
268 unsigned IOCTL_SNDCTL_SEQ_OUTOFBAND = SNDCTL_SEQ_OUTOFBAND;
269 unsigned IOCTL_SNDCTL_SEQ_PANIC = SNDCTL_SEQ_PANIC;
270 unsigned IOCTL_SNDCTL_SEQ_PERCMODE = SNDCTL_SEQ_PERCMODE;
271 unsigned IOCTL_SNDCTL_SEQ_RESET = SNDCTL_SEQ_RESET;
272 unsigned IOCTL_SNDCTL_SEQ_RESETSAMPLES = SNDCTL_SEQ_RESETSAMPLES;
273 unsigned IOCTL_SNDCTL_SEQ_SYNC = SNDCTL_SEQ_SYNC;
274 unsigned IOCTL_SNDCTL_SEQ_TESTMIDI = SNDCTL_SEQ_TESTMIDI;
275 unsigned IOCTL_SNDCTL_SEQ_THRESHOLD = SNDCTL_SEQ_THRESHOLD;
276 unsigned IOCTL_SNDCTL_SYNTH_INFO = SNDCTL_SYNTH_INFO;
277 unsigned IOCTL_SNDCTL_SYNTH_MEMAVL = SNDCTL_SYNTH_MEMAVL;
278 unsigned IOCTL_SNDCTL_TMR_CONTINUE = SNDCTL_TMR_CONTINUE;
279 unsigned IOCTL_SNDCTL_TMR_METRONOME = SNDCTL_TMR_METRONOME;
280 unsigned IOCTL_SNDCTL_TMR_SELECT = SNDCTL_TMR_SELECT;
281 unsigned IOCTL_SNDCTL_TMR_SOURCE = SNDCTL_TMR_SOURCE;
282 unsigned IOCTL_SNDCTL_TMR_START = SNDCTL_TMR_START;
283 unsigned IOCTL_SNDCTL_TMR_STOP = SNDCTL_TMR_STOP;
284 unsigned IOCTL_SNDCTL_TMR_TEMPO = SNDCTL_TMR_TEMPO;
285 unsigned IOCTL_SNDCTL_TMR_TIMEBASE = SNDCTL_TMR_TIMEBASE;
286 unsigned IOCTL_SOUND_MIXER_READ_ALTPCM = SOUND_MIXER_READ_ALTPCM;
287 unsigned IOCTL_SOUND_MIXER_READ_BASS = SOUND_MIXER_READ_BASS;
288 unsigned IOCTL_SOUND_MIXER_READ_CAPS = SOUND_MIXER_READ_CAPS;
289 unsigned IOCTL_SOUND_MIXER_READ_CD = SOUND_MIXER_READ_CD;
290 unsigned IOCTL_SOUND_MIXER_READ_DEVMASK = SOUND_MIXER_READ_DEVMASK;
291 unsigned IOCTL_SOUND_MIXER_READ_ENHANCE = SOUND_MIXER_READ_ENHANCE;
292 unsigned IOCTL_SOUND_MIXER_READ_IGAIN = SOUND_MIXER_READ_IGAIN;
293 unsigned IOCTL_SOUND_MIXER_READ_IMIX = SOUND_MIXER_READ_IMIX;
294 unsigned IOCTL_SOUND_MIXER_READ_LINE = SOUND_MIXER_READ_LINE;
295 unsigned IOCTL_SOUND_MIXER_READ_LINE1 = SOUND_MIXER_READ_LINE1;
296 unsigned IOCTL_SOUND_MIXER_READ_LINE2 = SOUND_MIXER_READ_LINE2;
297 unsigned IOCTL_SOUND_MIXER_READ_LINE3 = SOUND_MIXER_READ_LINE3;
298 unsigned IOCTL_SOUND_MIXER_READ_LOUD = SOUND_MIXER_READ_LOUD;
299 unsigned IOCTL_SOUND_MIXER_READ_MIC = SOUND_MIXER_READ_MIC;
300 unsigned IOCTL_SOUND_MIXER_READ_MUTE = SOUND_MIXER_READ_MUTE;
301 unsigned IOCTL_SOUND_MIXER_READ_OGAIN = SOUND_MIXER_READ_OGAIN;
302 unsigned IOCTL_SOUND_MIXER_READ_PCM = SOUND_MIXER_READ_PCM;
303 unsigned IOCTL_SOUND_MIXER_READ_RECLEV = SOUND_MIXER_READ_RECLEV;
304 unsigned IOCTL_SOUND_MIXER_READ_RECMASK = SOUND_MIXER_READ_RECMASK;
305 unsigned IOCTL_SOUND_MIXER_READ_RECSRC = SOUND_MIXER_READ_RECSRC;
306 unsigned IOCTL_SOUND_MIXER_READ_SPEAKER = SOUND_MIXER_READ_SPEAKER;
307 unsigned IOCTL_SOUND_MIXER_READ_STEREODEVS = SOUND_MIXER_READ_STEREODEVS;
308 unsigned IOCTL_SOUND_MIXER_READ_SYNTH = SOUND_MIXER_READ_SYNTH;
309 unsigned IOCTL_SOUND_MIXER_READ_TREBLE = SOUND_MIXER_READ_TREBLE;
310 unsigned IOCTL_SOUND_MIXER_READ_VOLUME = SOUND_MIXER_READ_VOLUME;
311 unsigned IOCTL_SOUND_MIXER_WRITE_ALTPCM = SOUND_MIXER_WRITE_ALTPCM;
312 unsigned IOCTL_SOUND_MIXER_WRITE_BASS = SOUND_MIXER_WRITE_BASS;
313 unsigned IOCTL_SOUND_MIXER_WRITE_CD = SOUND_MIXER_WRITE_CD;
314 unsigned IOCTL_SOUND_MIXER_WRITE_ENHANCE = SOUND_MIXER_WRITE_ENHANCE;
315 unsigned IOCTL_SOUND_MIXER_WRITE_IGAIN = SOUND_MIXER_WRITE_IGAIN;
316 unsigned IOCTL_SOUND_MIXER_WRITE_IMIX = SOUND_MIXER_WRITE_IMIX;
317 unsigned IOCTL_SOUND_MIXER_WRITE_LINE = SOUND_MIXER_WRITE_LINE;
318 unsigned IOCTL_SOUND_MIXER_WRITE_LINE1 = SOUND_MIXER_WRITE_LINE1;
319 unsigned IOCTL_SOUND_MIXER_WRITE_LINE2 = SOUND_MIXER_WRITE_LINE2;
320 unsigned IOCTL_SOUND_MIXER_WRITE_LINE3 = SOUND_MIXER_WRITE_LINE3;
321 unsigned IOCTL_SOUND_MIXER_WRITE_LOUD = SOUND_MIXER_WRITE_LOUD;
322 unsigned IOCTL_SOUND_MIXER_WRITE_MIC = SOUND_MIXER_WRITE_MIC;
323 unsigned IOCTL_SOUND_MIXER_WRITE_MUTE = SOUND_MIXER_WRITE_MUTE;
324 unsigned IOCTL_SOUND_MIXER_WRITE_OGAIN = SOUND_MIXER_WRITE_OGAIN;
325 unsigned IOCTL_SOUND_MIXER_WRITE_PCM = SOUND_MIXER_WRITE_PCM;
326 unsigned IOCTL_SOUND_MIXER_WRITE_RECLEV = SOUND_MIXER_WRITE_RECLEV;
327 unsigned IOCTL_SOUND_MIXER_WRITE_RECSRC = SOUND_MIXER_WRITE_RECSRC;
328 unsigned IOCTL_SOUND_MIXER_WRITE_SPEAKER = SOUND_MIXER_WRITE_SPEAKER;
329 unsigned IOCTL_SOUND_MIXER_WRITE_SYNTH = SOUND_MIXER_WRITE_SYNTH;
330 unsigned IOCTL_SOUND_MIXER_WRITE_TREBLE = SOUND_MIXER_WRITE_TREBLE;
331 unsigned IOCTL_SOUND_MIXER_WRITE_VOLUME = SOUND_MIXER_WRITE_VOLUME;
332 unsigned IOCTL_VT_ACTIVATE = VT_ACTIVATE;
333 unsigned IOCTL_VT_GETMODE = VT_GETMODE;
334 unsigned IOCTL_VT_OPENQRY = VT_OPENQRY;
335 unsigned IOCTL_VT_RELDISP = VT_RELDISP;
336 unsigned IOCTL_VT_SETMODE = VT_SETMODE;
337 unsigned IOCTL_VT_WAITACTIVE = VT_WAITACTIVE;
338 unsigned IOCTL_GIO_SCRNMAP = GIO_SCRNMAP;
339 unsigned IOCTL_KDDISABIO = KDDISABIO;
340 unsigned IOCTL_KDENABIO = KDENABIO;
341 unsigned IOCTL_KDGETLED = KDGETLED;
342 unsigned IOCTL_KDGETMODE = KDGETMODE;
343 unsigned IOCTL_KDGKBMODE = KDGKBMODE;
344 unsigned IOCTL_KDGKBTYPE = KDGKBTYPE;
345 unsigned IOCTL_KDMKTONE = KDMKTONE;
346 unsigned IOCTL_KDSETLED = KDSETLED;
347 unsigned IOCTL_KDSETMODE = KDSETMODE;
348 unsigned IOCTL_KDSKBMODE = KDSKBMODE;
349 unsigned IOCTL_KIOCSOUND = KIOCSOUND;
350 unsigned IOCTL_PIO_SCRNMAP = PIO_SCRNMAP;
351 unsigned IOCTL_SNDCTL_DSP_GETISPACE = SNDCTL_DSP_GETISPACE;
352 
353 const int si_SEGV_MAPERR = SEGV_MAPERR;
354 const int si_SEGV_ACCERR = SEGV_ACCERR;
355 const int unvis_valid = UNVIS_VALID;
356 const int unvis_validpush = UNVIS_VALIDPUSH;
357 }  // namespace __sanitizer
358 
359 using namespace __sanitizer;
360 
361 COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
362 
363 COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
364 CHECK_TYPE_SIZE(pthread_key_t);
365 
366 // There are more undocumented fields in dl_phdr_info that we are not interested
367 // in.
368 COMPILER_CHECK(sizeof(__sanitizer_dl_phdr_info) <= sizeof(dl_phdr_info));
369 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr);
370 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
371 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
372 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
373 
374 CHECK_TYPE_SIZE(glob_t);
375 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
376 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
377 CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
378 CHECK_SIZE_AND_OFFSET(glob_t, gl_flags);
379 CHECK_SIZE_AND_OFFSET(glob_t, gl_closedir);
380 CHECK_SIZE_AND_OFFSET(glob_t, gl_readdir);
381 CHECK_SIZE_AND_OFFSET(glob_t, gl_opendir);
382 CHECK_SIZE_AND_OFFSET(glob_t, gl_lstat);
383 CHECK_SIZE_AND_OFFSET(glob_t, gl_stat);
384 
385 CHECK_TYPE_SIZE(addrinfo);
386 CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags);
387 CHECK_SIZE_AND_OFFSET(addrinfo, ai_family);
388 CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype);
389 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
390 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
391 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen);
392 CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname);
393 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr);
394 
395 CHECK_TYPE_SIZE(hostent);
396 CHECK_SIZE_AND_OFFSET(hostent, h_name);
397 CHECK_SIZE_AND_OFFSET(hostent, h_aliases);
398 CHECK_SIZE_AND_OFFSET(hostent, h_addrtype);
399 CHECK_SIZE_AND_OFFSET(hostent, h_length);
400 CHECK_SIZE_AND_OFFSET(hostent, h_addr_list);
401 
402 CHECK_TYPE_SIZE(iovec);
403 CHECK_SIZE_AND_OFFSET(iovec, iov_base);
404 CHECK_SIZE_AND_OFFSET(iovec, iov_len);
405 
406 CHECK_TYPE_SIZE(msghdr);
407 CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
408 CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
409 CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
410 CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
411 CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
412 CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
413 CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
414 
415 CHECK_TYPE_SIZE(cmsghdr);
416 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
417 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
418 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
419 
420 COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
421 CHECK_SIZE_AND_OFFSET(dirent, d_ino);
422 CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
423 
424 CHECK_TYPE_SIZE(ifconf);
425 CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
426 CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
427 
428 CHECK_TYPE_SIZE(pollfd);
429 CHECK_SIZE_AND_OFFSET(pollfd, fd);
430 CHECK_SIZE_AND_OFFSET(pollfd, events);
431 CHECK_SIZE_AND_OFFSET(pollfd, revents);
432 
433 CHECK_TYPE_SIZE(nfds_t);
434 
435 CHECK_TYPE_SIZE(sigset_t);
436 
437 COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction));
438 // Can't write checks for sa_handler and sa_sigaction due to them being
439 // preprocessor macros.
440 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
441 
442 CHECK_TYPE_SIZE(wordexp_t);
443 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
444 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
445 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
446 
447 CHECK_TYPE_SIZE(tm);
448 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
449 CHECK_SIZE_AND_OFFSET(tm, tm_min);
450 CHECK_SIZE_AND_OFFSET(tm, tm_hour);
451 CHECK_SIZE_AND_OFFSET(tm, tm_mday);
452 CHECK_SIZE_AND_OFFSET(tm, tm_mon);
453 CHECK_SIZE_AND_OFFSET(tm, tm_year);
454 CHECK_SIZE_AND_OFFSET(tm, tm_wday);
455 CHECK_SIZE_AND_OFFSET(tm, tm_yday);
456 CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
457 CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff);
458 CHECK_SIZE_AND_OFFSET(tm, tm_zone);
459 
460 CHECK_TYPE_SIZE(ether_addr);
461 
462 CHECK_TYPE_SIZE(ipc_perm);
463 CHECK_SIZE_AND_OFFSET(ipc_perm, key);
464 CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
465 CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
466 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
467 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
468 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
469 
470 CHECK_TYPE_SIZE(shmid_ds);
471 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);
472 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz);
473 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime);
474 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime);
475 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime);
476 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid);
477 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
478 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
479 
480 CHECK_TYPE_SIZE(clock_t);
481 
482 CHECK_TYPE_SIZE(ifaddrs);
483 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
484 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
485 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
486 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask);
487 #undef ifa_dstaddr
488 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
489 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
490 
491 CHECK_TYPE_SIZE(timeb);
492 CHECK_SIZE_AND_OFFSET(timeb, time);
493 CHECK_SIZE_AND_OFFSET(timeb, millitm);
494 CHECK_SIZE_AND_OFFSET(timeb, timezone);
495 CHECK_SIZE_AND_OFFSET(timeb, dstflag);
496 
497 CHECK_TYPE_SIZE(passwd);
498 CHECK_SIZE_AND_OFFSET(passwd, pw_name);
499 CHECK_SIZE_AND_OFFSET(passwd, pw_passwd);
500 CHECK_SIZE_AND_OFFSET(passwd, pw_uid);
501 CHECK_SIZE_AND_OFFSET(passwd, pw_gid);
502 CHECK_SIZE_AND_OFFSET(passwd, pw_dir);
503 CHECK_SIZE_AND_OFFSET(passwd, pw_shell);
504 
505 CHECK_SIZE_AND_OFFSET(passwd, pw_gecos);
506 
507 CHECK_TYPE_SIZE(group);
508 CHECK_SIZE_AND_OFFSET(group, gr_name);
509 CHECK_SIZE_AND_OFFSET(group, gr_passwd);
510 CHECK_SIZE_AND_OFFSET(group, gr_gid);
511 CHECK_SIZE_AND_OFFSET(group, gr_mem);
512 
513 #if HAVE_RPC_XDR_H
514 CHECK_TYPE_SIZE(XDR);
515 CHECK_SIZE_AND_OFFSET(XDR, x_op);
516 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
517 CHECK_SIZE_AND_OFFSET(XDR, x_public);
518 CHECK_SIZE_AND_OFFSET(XDR, x_private);
519 CHECK_SIZE_AND_OFFSET(XDR, x_base);
520 CHECK_SIZE_AND_OFFSET(XDR, x_handy);
521 COMPILER_CHECK(__sanitizer_XDR_ENCODE == XDR_ENCODE);
522 COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE);
523 COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
524 #endif
525 
526 CHECK_TYPE_SIZE(sem_t);
527 
528 COMPILER_CHECK(sizeof(__sanitizer_cap_rights_t) >= sizeof(cap_rights_t));
529 #endif  // SANITIZER_FREEBSD
530