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