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

source code of compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp