1//===-- sanitizer_platform_limits_posix.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 POSIX data structures.
12//===----------------------------------------------------------------------===//
13
14#if defined(__linux__) || defined(__APPLE__)
15// Tests in this file assume that off_t-dependent data structures match the
16// libc ABI. For example, struct dirent here is what readdir() function (as
17// exported from libc) returns, and not the user-facing "dirent", which
18// depends on _FILE_OFFSET_BITS setting.
19// To get this "true" dirent definition, we undefine _FILE_OFFSET_BITS below.
20#undef _FILE_OFFSET_BITS
21#undef _TIME_BITS
22#endif
23
24// Must go after undef _FILE_OFFSET_BITS.
25#include "sanitizer_platform.h"
26
27#if SANITIZER_LINUX || SANITIZER_APPLE
28// Must go after undef _FILE_OFFSET_BITS.
29#include "sanitizer_glibc_version.h"
30
31#include <arpa/inet.h>
32#include <dirent.h>
33#include <grp.h>
34#include <limits.h>
35#include <net/if.h>
36#include <netdb.h>
37#include <poll.h>
38#include <pthread.h>
39#include <pwd.h>
40#include <signal.h>
41#include <stddef.h>
42#include <stdio.h>
43#include <sys/mman.h>
44#include <sys/resource.h>
45#include <sys/socket.h>
46#include <sys/stat.h>
47#include <sys/time.h>
48#include <sys/times.h>
49#include <sys/types.h>
50#include <sys/utsname.h>
51#include <termios.h>
52#include <time.h>
53#include <wchar.h>
54#include <regex.h>
55#if !SANITIZER_APPLE
56#include <utmp.h>
57#endif
58
59#if !SANITIZER_IOS
60#include <net/route.h>
61#endif
62
63#if !SANITIZER_ANDROID
64#include <sys/mount.h>
65#include <sys/timeb.h>
66#include <utmpx.h>
67#endif
68
69#if SANITIZER_LINUX
70#include <malloc.h>
71#include <mntent.h>
72#include <netinet/ether.h>
73#include <sys/sysinfo.h>
74#include <sys/vt.h>
75#include <linux/cdrom.h>
76#include <linux/fd.h>
77#if SANITIZER_ANDROID
78#include <linux/fs.h>
79#endif
80#include <linux/hdreg.h>
81#include <linux/input.h>
82#include <linux/ioctl.h>
83#include <linux/soundcard.h>
84#include <linux/sysctl.h>
85#include <linux/utsname.h>
86#include <linux/posix_types.h>
87#include <net/if_arp.h>
88#endif
89
90#if SANITIZER_IOS
91#undef IOC_DIRMASK
92#endif
93
94#if SANITIZER_LINUX
95# include <utime.h>
96# include <sys/ptrace.h>
97# if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \
98 defined(__hexagon__) || defined(__loongarch__) ||SANITIZER_RISCV64
99# include <asm/ptrace.h>
100# ifdef __arm__
101typedef struct user_fpregs elf_fpregset_t;
102# define ARM_VFPREGS_SIZE_ASAN (32 * 8 /*fpregs*/ + 4 /*fpscr*/)
103# if !defined(ARM_VFPREGS_SIZE)
104# define ARM_VFPREGS_SIZE ARM_VFPREGS_SIZE_ASAN
105# endif
106# endif
107# endif
108# include <semaphore.h>
109#endif
110
111#if !SANITIZER_ANDROID
112#include <ifaddrs.h>
113#include <sys/ucontext.h>
114#include <wordexp.h>
115#endif
116
117#if SANITIZER_LINUX
118#if SANITIZER_GLIBC
119#include <fstab.h>
120#include <net/if_ppp.h>
121#include <netax25/ax25.h>
122#include <netipx/ipx.h>
123#include <netrom/netrom.h>
124#include <obstack.h>
125#if HAVE_RPC_XDR_H
126# include <rpc/xdr.h>
127#endif
128#include <scsi/scsi.h>
129#else
130#include <linux/if_ppp.h>
131#include <linux/kd.h>
132#include <linux/ppp_defs.h>
133#endif // SANITIZER_GLIBC
134
135#if SANITIZER_ANDROID
136#include <linux/mtio.h>
137#else
138#include <glob.h>
139#include <mqueue.h>
140#include <sys/kd.h>
141#include <sys/mtio.h>
142#include <sys/shm.h>
143#include <sys/statvfs.h>
144#include <sys/timex.h>
145#if defined(__mips64)
146# include <sys/procfs.h>
147#endif
148#include <sys/user.h>
149#include <linux/if_eql.h>
150#include <linux/if_plip.h>
151#include <linux/lp.h>
152#include <linux/mroute.h>
153#include <linux/mroute6.h>
154#include <linux/scc.h>
155#include <linux/serial.h>
156#include <sys/msg.h>
157#include <sys/ipc.h>
158#endif // SANITIZER_ANDROID
159
160#include <link.h>
161#include <sys/vfs.h>
162#include <sys/epoll.h>
163#include <linux/capability.h>
164#else
165#include <fstab.h>
166#endif // SANITIZER_LINUX
167
168#if SANITIZER_APPLE
169#include <net/ethernet.h>
170#include <sys/filio.h>
171#include <sys/sockio.h>
172#endif
173
174// Include these after system headers to avoid name clashes and ambiguities.
175# include "sanitizer_common.h"
176# include "sanitizer_internal_defs.h"
177# include "sanitizer_platform_interceptors.h"
178# include "sanitizer_platform_limits_posix.h"
179
180namespace __sanitizer {
181 unsigned struct_utsname_sz = sizeof(struct utsname);
182 unsigned struct_stat_sz = sizeof(struct stat);
183#if SANITIZER_HAS_STAT64
184 unsigned struct_stat64_sz = sizeof(struct stat64);
185#endif // SANITIZER_HAS_STAT64
186 unsigned struct_rusage_sz = sizeof(struct rusage);
187 unsigned struct_tm_sz = sizeof(struct tm);
188 unsigned struct_passwd_sz = sizeof(struct passwd);
189 unsigned struct_group_sz = sizeof(struct group);
190 unsigned siginfo_t_sz = sizeof(siginfo_t);
191 unsigned struct_sigaction_sz = sizeof(struct sigaction);
192 unsigned struct_stack_t_sz = sizeof(stack_t);
193 unsigned struct_itimerval_sz = sizeof(struct itimerval);
194 unsigned pthread_t_sz = sizeof(pthread_t);
195 unsigned pthread_mutex_t_sz = sizeof(pthread_mutex_t);
196 unsigned pthread_cond_t_sz = sizeof(pthread_cond_t);
197 unsigned pid_t_sz = sizeof(pid_t);
198 unsigned timeval_sz = sizeof(timeval);
199 unsigned uid_t_sz = sizeof(uid_t);
200 unsigned gid_t_sz = sizeof(gid_t);
201 unsigned mbstate_t_sz = sizeof(mbstate_t);
202 unsigned sigset_t_sz = sizeof(sigset_t);
203 unsigned struct_timezone_sz = sizeof(struct timezone);
204 unsigned struct_tms_sz = sizeof(struct tms);
205 unsigned struct_sigevent_sz = sizeof(struct sigevent);
206 unsigned struct_sched_param_sz = sizeof(struct sched_param);
207 unsigned struct_regex_sz = sizeof(regex_t);
208 unsigned struct_regmatch_sz = sizeof(regmatch_t);
209
210#if SANITIZER_HAS_STATFS64
211 unsigned struct_statfs64_sz = sizeof(struct statfs64);
212#endif // SANITIZER_HAS_STATFS64
213
214#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_APPLE
215 unsigned struct_fstab_sz = sizeof(struct fstab);
216#endif // SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
217 // SANITIZER_APPLE
218#if !SANITIZER_ANDROID
219 unsigned struct_statfs_sz = sizeof(struct statfs);
220 unsigned struct_sockaddr_sz = sizeof(struct sockaddr);
221
222 unsigned ucontext_t_sz(void *ctx) {
223# if SANITIZER_GLIBC && SANITIZER_X64
224 // Added in Linux kernel 3.4.0, merged to glibc in 2.16
225# ifndef FP_XSTATE_MAGIC1
226# define FP_XSTATE_MAGIC1 0x46505853U
227# endif
228 // See kernel arch/x86/kernel/fpu/signal.c for details.
229 const auto *fpregs = static_cast<ucontext_t *>(ctx)->uc_mcontext.fpregs;
230 // The member names differ across header versions, but the actual layout
231 // is always the same. So avoid using members, just use arithmetic.
232 const uint32_t *after_xmm =
233 reinterpret_cast<const uint32_t *>(fpregs + 1) - 24;
234 if (after_xmm[12] == FP_XSTATE_MAGIC1)
235 return reinterpret_cast<const char *>(fpregs) + after_xmm[13] -
236 static_cast<const char *>(ctx);
237# endif
238 return sizeof(ucontext_t);
239 }
240# endif // !SANITIZER_ANDROID
241
242# if SANITIZER_LINUX
243 unsigned struct_epoll_event_sz = sizeof(struct epoll_event);
244 unsigned struct_sysinfo_sz = sizeof(struct sysinfo);
245 unsigned __user_cap_header_struct_sz =
246 sizeof(struct __user_cap_header_struct);
247 unsigned __user_cap_data_struct_sz(void *hdrp) {
248 int u32s = 0;
249 if (hdrp) {
250 switch (((struct __user_cap_header_struct *)hdrp)->version) {
251 case _LINUX_CAPABILITY_VERSION_1:
252 u32s = _LINUX_CAPABILITY_U32S_1;
253 break;
254 case _LINUX_CAPABILITY_VERSION_2:
255 u32s = _LINUX_CAPABILITY_U32S_2;
256 break;
257 case _LINUX_CAPABILITY_VERSION_3:
258 u32s = _LINUX_CAPABILITY_U32S_3;
259 break;
260 }
261 }
262 return sizeof(struct __user_cap_data_struct) * u32s;
263 }
264 unsigned struct_new_utsname_sz = sizeof(struct new_utsname);
265 unsigned struct_old_utsname_sz = sizeof(struct old_utsname);
266 unsigned struct_oldold_utsname_sz = sizeof(struct oldold_utsname);
267#endif // SANITIZER_LINUX
268
269#if SANITIZER_LINUX
270 unsigned struct_rlimit_sz = sizeof(struct rlimit);
271 unsigned struct_timespec_sz = sizeof(struct timespec);
272 unsigned struct_utimbuf_sz = sizeof(struct utimbuf);
273 unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
274#endif // SANITIZER_LINUX
275
276#if SANITIZER_GLIBC
277 // Use pre-computed size of struct ustat to avoid <sys/ustat.h> which
278 // has been removed from glibc 2.28.
279#if defined(__aarch64__) || defined(__s390x__) || defined(__mips64) || \
280 defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) || \
281 defined(__x86_64__) || SANITIZER_RISCV64
282#define SIZEOF_STRUCT_USTAT 32
283# elif defined(__arm__) || defined(__i386__) || defined(__mips__) || \
284 defined(__powerpc__) || defined(__s390__) || defined(__sparc__) || \
285 defined(__hexagon__)
286# define SIZEOF_STRUCT_USTAT 20
287# elif defined(__loongarch__)
288 // Not used. The minimum Glibc version available for LoongArch is 2.36
289 // so ustat() wrapper is already gone.
290# define SIZEOF_STRUCT_USTAT 0
291# else
292# error Unknown size of struct ustat
293# endif
294 unsigned struct_ustat_sz = SIZEOF_STRUCT_USTAT;
295 unsigned struct_rlimit64_sz = sizeof(struct rlimit64);
296 unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
297#endif // SANITIZER_GLIBC
298
299#if SANITIZER_LINUX && !SANITIZER_ANDROID
300 unsigned struct_timex_sz = sizeof(struct timex);
301 unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
302 unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
303 unsigned struct_statvfs_sz = sizeof(struct statvfs);
304#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
305
306 const uptr sig_ign = (uptr)SIG_IGN;
307 const uptr sig_dfl = (uptr)SIG_DFL;
308 const uptr sig_err = (uptr)SIG_ERR;
309 const uptr sa_siginfo = (uptr)SA_SIGINFO;
310
311#if SANITIZER_LINUX
312 int e_tabsz = (int)E_TABSZ;
313#endif
314
315
316#if SANITIZER_LINUX && !SANITIZER_ANDROID
317 unsigned struct_shminfo_sz = sizeof(struct shminfo);
318 unsigned struct_shm_info_sz = sizeof(struct shm_info);
319 int shmctl_ipc_stat = (int)IPC_STAT;
320 int shmctl_ipc_info = (int)IPC_INFO;
321 int shmctl_shm_info = (int)SHM_INFO;
322 int shmctl_shm_stat = (int)SHM_STAT;
323#endif
324
325#if !SANITIZER_APPLE && !SANITIZER_FREEBSD
326 unsigned struct_utmp_sz = sizeof(struct utmp);
327#endif
328#if !SANITIZER_ANDROID
329 unsigned struct_utmpx_sz = sizeof(struct utmpx);
330#endif
331
332 int map_fixed = MAP_FIXED;
333
334 int af_inet = (int)AF_INET;
335 int af_inet6 = (int)AF_INET6;
336
337 uptr __sanitizer_in_addr_sz(int af) {
338 if (af == AF_INET)
339 return sizeof(struct in_addr);
340 else if (af == AF_INET6)
341 return sizeof(struct in6_addr);
342 else
343 return 0;
344 }
345
346#if SANITIZER_LINUX
347unsigned struct_ElfW_Phdr_sz = sizeof(ElfW(Phdr));
348#elif SANITIZER_FREEBSD
349unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
350#endif
351
352#if SANITIZER_GLIBC
353 int glob_nomatch = GLOB_NOMATCH;
354 int glob_altdirfunc = GLOB_ALTDIRFUNC;
355#endif
356
357# if !SANITIZER_ANDROID
358 const int wordexp_wrde_dooffs = WRDE_DOOFFS;
359# endif // !SANITIZER_ANDROID
360
361#if SANITIZER_LINUX && !SANITIZER_ANDROID && \
362 (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
363 defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \
364 defined(__s390__) || defined(__loongarch__)|| SANITIZER_RISCV64)
365#if defined(__mips64) || defined(__powerpc64__) || defined(__arm__)
366 unsigned struct_user_regs_struct_sz = sizeof(struct pt_regs);
367 unsigned struct_user_fpregs_struct_sz = sizeof(elf_fpregset_t);
368#elif SANITIZER_RISCV64
369 unsigned struct_user_regs_struct_sz = sizeof(struct user_regs_struct);
370 unsigned struct_user_fpregs_struct_sz = sizeof(struct __riscv_q_ext_state);
371#elif defined(__aarch64__)
372 unsigned struct_user_regs_struct_sz = sizeof(struct user_pt_regs);
373 unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fpsimd_state);
374#elif defined(__loongarch__)
375 unsigned struct_user_regs_struct_sz = sizeof(struct user_pt_regs);
376 unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fp_state);
377#elif defined(__s390__)
378 unsigned struct_user_regs_struct_sz = sizeof(struct _user_regs_struct);
379 unsigned struct_user_fpregs_struct_sz = sizeof(struct _user_fpregs_struct);
380#else
381 unsigned struct_user_regs_struct_sz = sizeof(struct user_regs_struct);
382 unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fpregs_struct);
383#endif // __mips64 || __powerpc64__ || __aarch64__ || __loongarch__
384#if defined(__x86_64) || defined(__mips64) || defined(__powerpc64__) || \
385 defined(__aarch64__) || defined(__arm__) || defined(__s390__) || \
386 defined(__loongarch__) || SANITIZER_RISCV64
387 unsigned struct_user_fpxregs_struct_sz = 0;
388#else
389 unsigned struct_user_fpxregs_struct_sz = sizeof(struct user_fpxregs_struct);
390#endif // __x86_64 || __mips64 || __powerpc64__ || __aarch64__ || __arm__
391// || __s390__ || __loongarch__
392#ifdef __arm__
393 unsigned struct_user_vfpregs_struct_sz = ARM_VFPREGS_SIZE;
394#else
395 unsigned struct_user_vfpregs_struct_sz = 0;
396#endif
397
398 int ptrace_peektext = PTRACE_PEEKTEXT;
399 int ptrace_peekdata = PTRACE_PEEKDATA;
400 int ptrace_peekuser = PTRACE_PEEKUSER;
401#if (defined(PTRACE_GETREGS) && defined(PTRACE_SETREGS)) || \
402 (defined(PT_GETREGS) && defined(PT_SETREGS))
403 int ptrace_getregs = PTRACE_GETREGS;
404 int ptrace_setregs = PTRACE_SETREGS;
405#else
406 int ptrace_getregs = -1;
407 int ptrace_setregs = -1;
408#endif
409#if (defined(PTRACE_GETFPREGS) && defined(PTRACE_SETFPREGS)) || \
410 (defined(PT_GETFPREGS) && defined(PT_SETFPREGS))
411 int ptrace_getfpregs = PTRACE_GETFPREGS;
412 int ptrace_setfpregs = PTRACE_SETFPREGS;
413#else
414 int ptrace_getfpregs = -1;
415 int ptrace_setfpregs = -1;
416#endif
417#if (defined(PTRACE_GETFPXREGS) && defined(PTRACE_SETFPXREGS)) || \
418 (defined(PT_GETFPXREGS) && defined(PT_SETFPXREGS))
419 int ptrace_getfpxregs = PTRACE_GETFPXREGS;
420 int ptrace_setfpxregs = PTRACE_SETFPXREGS;
421#else
422 int ptrace_getfpxregs = -1;
423 int ptrace_setfpxregs = -1;
424#endif // PTRACE_GETFPXREGS/PTRACE_SETFPXREGS
425#if defined(PTRACE_GETVFPREGS) && defined(PTRACE_SETVFPREGS)
426 int ptrace_getvfpregs = PTRACE_GETVFPREGS;
427 int ptrace_setvfpregs = PTRACE_SETVFPREGS;
428#else
429 int ptrace_getvfpregs = -1;
430 int ptrace_setvfpregs = -1;
431#endif
432 int ptrace_geteventmsg = PTRACE_GETEVENTMSG;
433#if (defined(PTRACE_GETSIGINFO) && defined(PTRACE_SETSIGINFO)) || \
434 (defined(PT_GETSIGINFO) && defined(PT_SETSIGINFO))
435 int ptrace_getsiginfo = PTRACE_GETSIGINFO;
436 int ptrace_setsiginfo = PTRACE_SETSIGINFO;
437#else
438 int ptrace_getsiginfo = -1;
439 int ptrace_setsiginfo = -1;
440#endif // PTRACE_GETSIGINFO/PTRACE_SETSIGINFO
441#if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET)
442 int ptrace_getregset = PTRACE_GETREGSET;
443 int ptrace_setregset = PTRACE_SETREGSET;
444#else
445 int ptrace_getregset = -1;
446 int ptrace_setregset = -1;
447#endif // PTRACE_GETREGSET/PTRACE_SETREGSET
448#endif
449
450 unsigned path_max = PATH_MAX;
451
452 // ioctl arguments
453 unsigned struct_ifreq_sz = sizeof(struct ifreq);
454 unsigned struct_termios_sz = sizeof(struct termios);
455 unsigned struct_winsize_sz = sizeof(struct winsize);
456
457#if SANITIZER_LINUX
458 unsigned struct_arpreq_sz = sizeof(struct arpreq);
459 unsigned struct_cdrom_msf_sz = sizeof(struct cdrom_msf);
460 unsigned struct_cdrom_multisession_sz = sizeof(struct cdrom_multisession);
461 unsigned struct_cdrom_read_audio_sz = sizeof(struct cdrom_read_audio);
462 unsigned struct_cdrom_subchnl_sz = sizeof(struct cdrom_subchnl);
463 unsigned struct_cdrom_ti_sz = sizeof(struct cdrom_ti);
464 unsigned struct_cdrom_tocentry_sz = sizeof(struct cdrom_tocentry);
465 unsigned struct_cdrom_tochdr_sz = sizeof(struct cdrom_tochdr);
466 unsigned struct_cdrom_volctrl_sz = sizeof(struct cdrom_volctrl);
467 unsigned struct_ff_effect_sz = sizeof(struct ff_effect);
468 unsigned struct_floppy_drive_params_sz = sizeof(struct floppy_drive_params);
469 unsigned struct_floppy_drive_struct_sz = sizeof(struct floppy_drive_struct);
470 unsigned struct_floppy_fdc_state_sz = sizeof(struct floppy_fdc_state);
471 unsigned struct_floppy_max_errors_sz = sizeof(struct floppy_max_errors);
472 unsigned struct_floppy_raw_cmd_sz = sizeof(struct floppy_raw_cmd);
473 unsigned struct_floppy_struct_sz = sizeof(struct floppy_struct);
474 unsigned struct_floppy_write_errors_sz = sizeof(struct floppy_write_errors);
475 unsigned struct_format_descr_sz = sizeof(struct format_descr);
476 unsigned struct_hd_driveid_sz = sizeof(struct hd_driveid);
477 unsigned struct_hd_geometry_sz = sizeof(struct hd_geometry);
478 unsigned struct_input_absinfo_sz = sizeof(struct input_absinfo);
479 unsigned struct_input_id_sz = sizeof(struct input_id);
480 unsigned struct_mtpos_sz = sizeof(struct mtpos);
481 unsigned struct_rtentry_sz = sizeof(struct rtentry);
482#if SANITIZER_GLIBC || SANITIZER_ANDROID
483 unsigned struct_termio_sz = sizeof(struct termio);
484#endif
485 unsigned struct_vt_consize_sz = sizeof(struct vt_consize);
486 unsigned struct_vt_sizes_sz = sizeof(struct vt_sizes);
487 unsigned struct_vt_stat_sz = sizeof(struct vt_stat);
488#endif // SANITIZER_LINUX
489
490#if SANITIZER_LINUX
491#if SOUND_VERSION >= 0x040000
492 unsigned struct_copr_buffer_sz = 0;
493 unsigned struct_copr_debug_buf_sz = 0;
494 unsigned struct_copr_msg_sz = 0;
495#else
496 unsigned struct_copr_buffer_sz = sizeof(struct copr_buffer);
497 unsigned struct_copr_debug_buf_sz = sizeof(struct copr_debug_buf);
498 unsigned struct_copr_msg_sz = sizeof(struct copr_msg);
499#endif
500 unsigned struct_midi_info_sz = sizeof(struct midi_info);
501 unsigned struct_mtget_sz = sizeof(struct mtget);
502 unsigned struct_mtop_sz = sizeof(struct mtop);
503 unsigned struct_sbi_instrument_sz = sizeof(struct sbi_instrument);
504 unsigned struct_seq_event_rec_sz = sizeof(struct seq_event_rec);
505 unsigned struct_synth_info_sz = sizeof(struct synth_info);
506 unsigned struct_vt_mode_sz = sizeof(struct vt_mode);
507#endif // SANITIZER_LINUX
508
509#if SANITIZER_GLIBC
510 unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct);
511#if EV_VERSION > (0x010000)
512 unsigned struct_input_keymap_entry_sz = sizeof(struct input_keymap_entry);
513#else
514 unsigned struct_input_keymap_entry_sz = 0;
515#endif
516 unsigned struct_ipx_config_data_sz = sizeof(struct ipx_config_data);
517 unsigned struct_kbdiacrs_sz = sizeof(struct kbdiacrs);
518 unsigned struct_kbentry_sz = sizeof(struct kbentry);
519 unsigned struct_kbkeycode_sz = sizeof(struct kbkeycode);
520 unsigned struct_kbsentry_sz = sizeof(struct kbsentry);
521 unsigned struct_mtconfiginfo_sz = sizeof(struct mtconfiginfo);
522 unsigned struct_nr_parms_struct_sz = sizeof(struct nr_parms_struct);
523 unsigned struct_scc_modem_sz = sizeof(struct scc_modem);
524 unsigned struct_scc_stat_sz = sizeof(struct scc_stat);
525 unsigned struct_serial_multiport_struct_sz
526 = sizeof(struct serial_multiport_struct);
527 unsigned struct_serial_struct_sz = sizeof(struct serial_struct);
528 unsigned struct_sockaddr_ax25_sz = sizeof(struct sockaddr_ax25);
529 unsigned struct_unimapdesc_sz = sizeof(struct unimapdesc);
530 unsigned struct_unimapinit_sz = sizeof(struct unimapinit);
531
532 unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info);
533 unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats);
534#endif // SANITIZER_GLIBC
535
536#if !SANITIZER_ANDROID && !SANITIZER_APPLE
537 unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req);
538 unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
539#endif
540
541 const unsigned long __sanitizer_bufsiz = BUFSIZ;
542
543 const unsigned IOCTL_NOT_PRESENT = 0;
544
545 unsigned IOCTL_FIOASYNC = FIOASYNC;
546 unsigned IOCTL_FIOCLEX = FIOCLEX;
547 unsigned IOCTL_FIOGETOWN = FIOGETOWN;
548 unsigned IOCTL_FIONBIO = FIONBIO;
549 unsigned IOCTL_FIONCLEX = FIONCLEX;
550 unsigned IOCTL_FIOSETOWN = FIOSETOWN;
551 unsigned IOCTL_SIOCADDMULTI = SIOCADDMULTI;
552 unsigned IOCTL_SIOCATMARK = SIOCATMARK;
553 unsigned IOCTL_SIOCDELMULTI = SIOCDELMULTI;
554 unsigned IOCTL_SIOCGIFADDR = SIOCGIFADDR;
555 unsigned IOCTL_SIOCGIFBRDADDR = SIOCGIFBRDADDR;
556 unsigned IOCTL_SIOCGIFCONF = SIOCGIFCONF;
557 unsigned IOCTL_SIOCGIFDSTADDR = SIOCGIFDSTADDR;
558 unsigned IOCTL_SIOCGIFFLAGS = SIOCGIFFLAGS;
559 unsigned IOCTL_SIOCGIFMETRIC = SIOCGIFMETRIC;
560 unsigned IOCTL_SIOCGIFMTU = SIOCGIFMTU;
561 unsigned IOCTL_SIOCGIFNETMASK = SIOCGIFNETMASK;
562 unsigned IOCTL_SIOCGPGRP = SIOCGPGRP;
563 unsigned IOCTL_SIOCSIFADDR = SIOCSIFADDR;
564 unsigned IOCTL_SIOCSIFBRDADDR = SIOCSIFBRDADDR;
565 unsigned IOCTL_SIOCSIFDSTADDR = SIOCSIFDSTADDR;
566 unsigned IOCTL_SIOCSIFFLAGS = SIOCSIFFLAGS;
567 unsigned IOCTL_SIOCSIFMETRIC = SIOCSIFMETRIC;
568 unsigned IOCTL_SIOCSIFMTU = SIOCSIFMTU;
569 unsigned IOCTL_SIOCSIFNETMASK = SIOCSIFNETMASK;
570 unsigned IOCTL_SIOCSPGRP = SIOCSPGRP;
571 unsigned IOCTL_TIOCCONS = TIOCCONS;
572 unsigned IOCTL_TIOCEXCL = TIOCEXCL;
573 unsigned IOCTL_TIOCGETD = TIOCGETD;
574 unsigned IOCTL_TIOCGPGRP = TIOCGPGRP;
575 unsigned IOCTL_TIOCGWINSZ = TIOCGWINSZ;
576 unsigned IOCTL_TIOCMBIC = TIOCMBIC;
577 unsigned IOCTL_TIOCMBIS = TIOCMBIS;
578 unsigned IOCTL_TIOCMGET = TIOCMGET;
579 unsigned IOCTL_TIOCMSET = TIOCMSET;
580 unsigned IOCTL_TIOCNOTTY = TIOCNOTTY;
581 unsigned IOCTL_TIOCNXCL = TIOCNXCL;
582 unsigned IOCTL_TIOCOUTQ = TIOCOUTQ;
583 unsigned IOCTL_TIOCPKT = TIOCPKT;
584 unsigned IOCTL_TIOCSCTTY = TIOCSCTTY;
585 unsigned IOCTL_TIOCSETD = TIOCSETD;
586 unsigned IOCTL_TIOCSPGRP = TIOCSPGRP;
587 unsigned IOCTL_TIOCSTI = TIOCSTI;
588 unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ;
589#if SANITIZER_LINUX && !SANITIZER_ANDROID
590 unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT;
591 unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT;
592#endif
593
594#if SANITIZER_LINUX
595 unsigned IOCTL_EVIOCGABS = EVIOCGABS(0);
596 unsigned IOCTL_EVIOCGBIT = EVIOCGBIT(0, 0);
597 unsigned IOCTL_EVIOCGEFFECTS = EVIOCGEFFECTS;
598 unsigned IOCTL_EVIOCGID = EVIOCGID;
599 unsigned IOCTL_EVIOCGKEY = EVIOCGKEY(0);
600 unsigned IOCTL_EVIOCGKEYCODE = EVIOCGKEYCODE;
601 unsigned IOCTL_EVIOCGLED = EVIOCGLED(0);
602 unsigned IOCTL_EVIOCGNAME = EVIOCGNAME(0);
603 unsigned IOCTL_EVIOCGPHYS = EVIOCGPHYS(0);
604 unsigned IOCTL_EVIOCGRAB = EVIOCGRAB;
605 unsigned IOCTL_EVIOCGREP = EVIOCGREP;
606 unsigned IOCTL_EVIOCGSND = EVIOCGSND(0);
607 unsigned IOCTL_EVIOCGSW = EVIOCGSW(0);
608 unsigned IOCTL_EVIOCGUNIQ = EVIOCGUNIQ(0);
609 unsigned IOCTL_EVIOCGVERSION = EVIOCGVERSION;
610 unsigned IOCTL_EVIOCRMFF = EVIOCRMFF;
611 unsigned IOCTL_EVIOCSABS = EVIOCSABS(0);
612 unsigned IOCTL_EVIOCSFF = EVIOCSFF;
613 unsigned IOCTL_EVIOCSKEYCODE = EVIOCSKEYCODE;
614 unsigned IOCTL_EVIOCSREP = EVIOCSREP;
615 unsigned IOCTL_BLKFLSBUF = BLKFLSBUF;
616 unsigned IOCTL_BLKGETSIZE = BLKGETSIZE;
617 unsigned IOCTL_BLKRAGET = BLKRAGET;
618 unsigned IOCTL_BLKRASET = BLKRASET;
619 unsigned IOCTL_BLKROGET = BLKROGET;
620 unsigned IOCTL_BLKROSET = BLKROSET;
621 unsigned IOCTL_BLKRRPART = BLKRRPART;
622 unsigned IOCTL_BLKFRASET = BLKFRASET;
623 unsigned IOCTL_BLKFRAGET = BLKFRAGET;
624 unsigned IOCTL_BLKSECTSET = BLKSECTSET;
625 unsigned IOCTL_BLKSECTGET = BLKSECTGET;
626 unsigned IOCTL_BLKSSZGET = BLKSSZGET;
627 unsigned IOCTL_BLKBSZGET = BLKBSZGET;
628 unsigned IOCTL_BLKBSZSET = BLKBSZSET;
629 unsigned IOCTL_BLKGETSIZE64 = BLKGETSIZE64;
630 unsigned IOCTL_CDROMAUDIOBUFSIZ = CDROMAUDIOBUFSIZ;
631 unsigned IOCTL_CDROMEJECT = CDROMEJECT;
632 unsigned IOCTL_CDROMEJECT_SW = CDROMEJECT_SW;
633 unsigned IOCTL_CDROMMULTISESSION = CDROMMULTISESSION;
634 unsigned IOCTL_CDROMPAUSE = CDROMPAUSE;
635 unsigned IOCTL_CDROMPLAYMSF = CDROMPLAYMSF;
636 unsigned IOCTL_CDROMPLAYTRKIND = CDROMPLAYTRKIND;
637 unsigned IOCTL_CDROMREADAUDIO = CDROMREADAUDIO;
638 unsigned IOCTL_CDROMREADCOOKED = CDROMREADCOOKED;
639 unsigned IOCTL_CDROMREADMODE1 = CDROMREADMODE1;
640 unsigned IOCTL_CDROMREADMODE2 = CDROMREADMODE2;
641 unsigned IOCTL_CDROMREADRAW = CDROMREADRAW;
642 unsigned IOCTL_CDROMREADTOCENTRY = CDROMREADTOCENTRY;
643 unsigned IOCTL_CDROMREADTOCHDR = CDROMREADTOCHDR;
644 unsigned IOCTL_CDROMRESET = CDROMRESET;
645 unsigned IOCTL_CDROMRESUME = CDROMRESUME;
646 unsigned IOCTL_CDROMSEEK = CDROMSEEK;
647 unsigned IOCTL_CDROMSTART = CDROMSTART;
648 unsigned IOCTL_CDROMSTOP = CDROMSTOP;
649 unsigned IOCTL_CDROMSUBCHNL = CDROMSUBCHNL;
650 unsigned IOCTL_CDROMVOLCTRL = CDROMVOLCTRL;
651 unsigned IOCTL_CDROMVOLREAD = CDROMVOLREAD;
652 unsigned IOCTL_CDROM_GET_UPC = CDROM_GET_UPC;
653 unsigned IOCTL_FDCLRPRM = FDCLRPRM;
654 unsigned IOCTL_FDDEFPRM = FDDEFPRM;
655 unsigned IOCTL_FDFLUSH = FDFLUSH;
656 unsigned IOCTL_FDFMTBEG = FDFMTBEG;
657 unsigned IOCTL_FDFMTEND = FDFMTEND;
658 unsigned IOCTL_FDFMTTRK = FDFMTTRK;
659 unsigned IOCTL_FDGETDRVPRM = FDGETDRVPRM;
660 unsigned IOCTL_FDGETDRVSTAT = FDGETDRVSTAT;
661 unsigned IOCTL_FDGETDRVTYP = FDGETDRVTYP;
662 unsigned IOCTL_FDGETFDCSTAT = FDGETFDCSTAT;
663 unsigned IOCTL_FDGETMAXERRS = FDGETMAXERRS;
664 unsigned IOCTL_FDGETPRM = FDGETPRM;
665 unsigned IOCTL_FDMSGOFF = FDMSGOFF;
666 unsigned IOCTL_FDMSGON = FDMSGON;
667 unsigned IOCTL_FDPOLLDRVSTAT = FDPOLLDRVSTAT;
668 unsigned IOCTL_FDRAWCMD = FDRAWCMD;
669 unsigned IOCTL_FDRESET = FDRESET;
670 unsigned IOCTL_FDSETDRVPRM = FDSETDRVPRM;
671 unsigned IOCTL_FDSETEMSGTRESH = FDSETEMSGTRESH;
672 unsigned IOCTL_FDSETMAXERRS = FDSETMAXERRS;
673 unsigned IOCTL_FDSETPRM = FDSETPRM;
674 unsigned IOCTL_FDTWADDLE = FDTWADDLE;
675 unsigned IOCTL_FDWERRORCLR = FDWERRORCLR;
676 unsigned IOCTL_FDWERRORGET = FDWERRORGET;
677 unsigned IOCTL_HDIO_DRIVE_CMD = HDIO_DRIVE_CMD;
678 unsigned IOCTL_HDIO_GETGEO = HDIO_GETGEO;
679 unsigned IOCTL_HDIO_GET_32BIT = HDIO_GET_32BIT;
680 unsigned IOCTL_HDIO_GET_DMA = HDIO_GET_DMA;
681 unsigned IOCTL_HDIO_GET_IDENTITY = HDIO_GET_IDENTITY;
682 unsigned IOCTL_HDIO_GET_KEEPSETTINGS = HDIO_GET_KEEPSETTINGS;
683 unsigned IOCTL_HDIO_GET_MULTCOUNT = HDIO_GET_MULTCOUNT;
684 unsigned IOCTL_HDIO_GET_NOWERR = HDIO_GET_NOWERR;
685 unsigned IOCTL_HDIO_GET_UNMASKINTR = HDIO_GET_UNMASKINTR;
686 unsigned IOCTL_HDIO_SET_32BIT = HDIO_SET_32BIT;
687 unsigned IOCTL_HDIO_SET_DMA = HDIO_SET_DMA;
688 unsigned IOCTL_HDIO_SET_KEEPSETTINGS = HDIO_SET_KEEPSETTINGS;
689 unsigned IOCTL_HDIO_SET_MULTCOUNT = HDIO_SET_MULTCOUNT;
690 unsigned IOCTL_HDIO_SET_NOWERR = HDIO_SET_NOWERR;
691 unsigned IOCTL_HDIO_SET_UNMASKINTR = HDIO_SET_UNMASKINTR;
692 unsigned IOCTL_MTIOCPOS = MTIOCPOS;
693 unsigned IOCTL_PPPIOCGASYNCMAP = PPPIOCGASYNCMAP;
694 unsigned IOCTL_PPPIOCGDEBUG = PPPIOCGDEBUG;
695 unsigned IOCTL_PPPIOCGFLAGS = PPPIOCGFLAGS;
696 unsigned IOCTL_PPPIOCGUNIT = PPPIOCGUNIT;
697 unsigned IOCTL_PPPIOCGXASYNCMAP = PPPIOCGXASYNCMAP;
698 unsigned IOCTL_PPPIOCSASYNCMAP = PPPIOCSASYNCMAP;
699 unsigned IOCTL_PPPIOCSDEBUG = PPPIOCSDEBUG;
700 unsigned IOCTL_PPPIOCSFLAGS = PPPIOCSFLAGS;
701 unsigned IOCTL_PPPIOCSMAXCID = PPPIOCSMAXCID;
702 unsigned IOCTL_PPPIOCSMRU = PPPIOCSMRU;
703 unsigned IOCTL_PPPIOCSXASYNCMAP = PPPIOCSXASYNCMAP;
704 unsigned IOCTL_SIOCADDRT = SIOCADDRT;
705 unsigned IOCTL_SIOCDARP = SIOCDARP;
706 unsigned IOCTL_SIOCDELRT = SIOCDELRT;
707 unsigned IOCTL_SIOCDRARP = SIOCDRARP;
708 unsigned IOCTL_SIOCGARP = SIOCGARP;
709 unsigned IOCTL_SIOCGIFENCAP = SIOCGIFENCAP;
710 unsigned IOCTL_SIOCGIFHWADDR = SIOCGIFHWADDR;
711 unsigned IOCTL_SIOCGIFMAP = SIOCGIFMAP;
712 unsigned IOCTL_SIOCGIFMEM = SIOCGIFMEM;
713 unsigned IOCTL_SIOCGIFNAME = SIOCGIFNAME;
714 unsigned IOCTL_SIOCGIFSLAVE = SIOCGIFSLAVE;
715 unsigned IOCTL_SIOCGRARP = SIOCGRARP;
716 unsigned IOCTL_SIOCGSTAMP = SIOCGSTAMP;
717 unsigned IOCTL_SIOCSARP = SIOCSARP;
718 unsigned IOCTL_SIOCSIFENCAP = SIOCSIFENCAP;
719 unsigned IOCTL_SIOCSIFHWADDR = SIOCSIFHWADDR;
720 unsigned IOCTL_SIOCSIFLINK = SIOCSIFLINK;
721 unsigned IOCTL_SIOCSIFMAP = SIOCSIFMAP;
722 unsigned IOCTL_SIOCSIFMEM = SIOCSIFMEM;
723 unsigned IOCTL_SIOCSIFSLAVE = SIOCSIFSLAVE;
724 unsigned IOCTL_SIOCSRARP = SIOCSRARP;
725# if SOUND_VERSION >= 0x040000
726 unsigned IOCTL_SNDCTL_COPR_HALT = IOCTL_NOT_PRESENT;
727 unsigned IOCTL_SNDCTL_COPR_LOAD = IOCTL_NOT_PRESENT;
728 unsigned IOCTL_SNDCTL_COPR_RCODE = IOCTL_NOT_PRESENT;
729 unsigned IOCTL_SNDCTL_COPR_RCVMSG = IOCTL_NOT_PRESENT;
730 unsigned IOCTL_SNDCTL_COPR_RDATA = IOCTL_NOT_PRESENT;
731 unsigned IOCTL_SNDCTL_COPR_RESET = IOCTL_NOT_PRESENT;
732 unsigned IOCTL_SNDCTL_COPR_RUN = IOCTL_NOT_PRESENT;
733 unsigned IOCTL_SNDCTL_COPR_SENDMSG = IOCTL_NOT_PRESENT;
734 unsigned IOCTL_SNDCTL_COPR_WCODE = IOCTL_NOT_PRESENT;
735 unsigned IOCTL_SNDCTL_COPR_WDATA = IOCTL_NOT_PRESENT;
736 unsigned IOCTL_SOUND_PCM_READ_BITS = IOCTL_NOT_PRESENT;
737 unsigned IOCTL_SOUND_PCM_READ_CHANNELS = IOCTL_NOT_PRESENT;
738 unsigned IOCTL_SOUND_PCM_READ_FILTER = IOCTL_NOT_PRESENT;
739 unsigned IOCTL_SOUND_PCM_READ_RATE = IOCTL_NOT_PRESENT;
740 unsigned IOCTL_SOUND_PCM_WRITE_CHANNELS = IOCTL_NOT_PRESENT;
741 unsigned IOCTL_SOUND_PCM_WRITE_FILTER = IOCTL_NOT_PRESENT;
742# else // SOUND_VERSION
743 unsigned IOCTL_SNDCTL_COPR_HALT = SNDCTL_COPR_HALT;
744 unsigned IOCTL_SNDCTL_COPR_LOAD = SNDCTL_COPR_LOAD;
745 unsigned IOCTL_SNDCTL_COPR_RCODE = SNDCTL_COPR_RCODE;
746 unsigned IOCTL_SNDCTL_COPR_RCVMSG = SNDCTL_COPR_RCVMSG;
747 unsigned IOCTL_SNDCTL_COPR_RDATA = SNDCTL_COPR_RDATA;
748 unsigned IOCTL_SNDCTL_COPR_RESET = SNDCTL_COPR_RESET;
749 unsigned IOCTL_SNDCTL_COPR_RUN = SNDCTL_COPR_RUN;
750 unsigned IOCTL_SNDCTL_COPR_SENDMSG = SNDCTL_COPR_SENDMSG;
751 unsigned IOCTL_SNDCTL_COPR_WCODE = SNDCTL_COPR_WCODE;
752 unsigned IOCTL_SNDCTL_COPR_WDATA = SNDCTL_COPR_WDATA;
753 unsigned IOCTL_SOUND_PCM_READ_BITS = SOUND_PCM_READ_BITS;
754 unsigned IOCTL_SOUND_PCM_READ_CHANNELS = SOUND_PCM_READ_CHANNELS;
755 unsigned IOCTL_SOUND_PCM_READ_FILTER = SOUND_PCM_READ_FILTER;
756 unsigned IOCTL_SOUND_PCM_READ_RATE = SOUND_PCM_READ_RATE;
757 unsigned IOCTL_SOUND_PCM_WRITE_CHANNELS = SOUND_PCM_WRITE_CHANNELS;
758 unsigned IOCTL_SOUND_PCM_WRITE_FILTER = SOUND_PCM_WRITE_FILTER;
759#endif // SOUND_VERSION
760 unsigned IOCTL_TCFLSH = TCFLSH;
761 unsigned IOCTL_TCGETA = TCGETA;
762 unsigned IOCTL_TCGETS = TCGETS;
763 unsigned IOCTL_TCSBRK = TCSBRK;
764 unsigned IOCTL_TCSBRKP = TCSBRKP;
765 unsigned IOCTL_TCSETA = TCSETA;
766 unsigned IOCTL_TCSETAF = TCSETAF;
767 unsigned IOCTL_TCSETAW = TCSETAW;
768 unsigned IOCTL_TCSETS = TCSETS;
769 unsigned IOCTL_TCSETSF = TCSETSF;
770 unsigned IOCTL_TCSETSW = TCSETSW;
771 unsigned IOCTL_TCXONC = TCXONC;
772 unsigned IOCTL_TIOCGLCKTRMIOS = TIOCGLCKTRMIOS;
773 unsigned IOCTL_TIOCGSOFTCAR = TIOCGSOFTCAR;
774 unsigned IOCTL_TIOCINQ = TIOCINQ;
775 unsigned IOCTL_TIOCLINUX = TIOCLINUX;
776 unsigned IOCTL_TIOCSERCONFIG = TIOCSERCONFIG;
777 unsigned IOCTL_TIOCSERGETLSR = TIOCSERGETLSR;
778 unsigned IOCTL_TIOCSERGWILD = TIOCSERGWILD;
779 unsigned IOCTL_TIOCSERSWILD = TIOCSERSWILD;
780 unsigned IOCTL_TIOCSLCKTRMIOS = TIOCSLCKTRMIOS;
781 unsigned IOCTL_TIOCSSOFTCAR = TIOCSSOFTCAR;
782 unsigned IOCTL_VT_DISALLOCATE = VT_DISALLOCATE;
783 unsigned IOCTL_VT_GETSTATE = VT_GETSTATE;
784 unsigned IOCTL_VT_RESIZE = VT_RESIZE;
785 unsigned IOCTL_VT_RESIZEX = VT_RESIZEX;
786 unsigned IOCTL_VT_SENDSIG = VT_SENDSIG;
787 unsigned IOCTL_MTIOCGET = MTIOCGET;
788 unsigned IOCTL_MTIOCTOP = MTIOCTOP;
789 unsigned IOCTL_SNDCTL_DSP_GETBLKSIZE = SNDCTL_DSP_GETBLKSIZE;
790 unsigned IOCTL_SNDCTL_DSP_GETFMTS = SNDCTL_DSP_GETFMTS;
791 unsigned IOCTL_SNDCTL_DSP_NONBLOCK = SNDCTL_DSP_NONBLOCK;
792 unsigned IOCTL_SNDCTL_DSP_POST = SNDCTL_DSP_POST;
793 unsigned IOCTL_SNDCTL_DSP_RESET = SNDCTL_DSP_RESET;
794 unsigned IOCTL_SNDCTL_DSP_SETFMT = SNDCTL_DSP_SETFMT;
795 unsigned IOCTL_SNDCTL_DSP_SETFRAGMENT = SNDCTL_DSP_SETFRAGMENT;
796 unsigned IOCTL_SNDCTL_DSP_SPEED = SNDCTL_DSP_SPEED;
797 unsigned IOCTL_SNDCTL_DSP_STEREO = SNDCTL_DSP_STEREO;
798 unsigned IOCTL_SNDCTL_DSP_SUBDIVIDE = SNDCTL_DSP_SUBDIVIDE;
799 unsigned IOCTL_SNDCTL_DSP_SYNC = SNDCTL_DSP_SYNC;
800 unsigned IOCTL_SNDCTL_FM_4OP_ENABLE = SNDCTL_FM_4OP_ENABLE;
801 unsigned IOCTL_SNDCTL_FM_LOAD_INSTR = SNDCTL_FM_LOAD_INSTR;
802 unsigned IOCTL_SNDCTL_MIDI_INFO = SNDCTL_MIDI_INFO;
803 unsigned IOCTL_SNDCTL_MIDI_PRETIME = SNDCTL_MIDI_PRETIME;
804 unsigned IOCTL_SNDCTL_SEQ_CTRLRATE = SNDCTL_SEQ_CTRLRATE;
805 unsigned IOCTL_SNDCTL_SEQ_GETINCOUNT = SNDCTL_SEQ_GETINCOUNT;
806 unsigned IOCTL_SNDCTL_SEQ_GETOUTCOUNT = SNDCTL_SEQ_GETOUTCOUNT;
807 unsigned IOCTL_SNDCTL_SEQ_NRMIDIS = SNDCTL_SEQ_NRMIDIS;
808 unsigned IOCTL_SNDCTL_SEQ_NRSYNTHS = SNDCTL_SEQ_NRSYNTHS;
809 unsigned IOCTL_SNDCTL_SEQ_OUTOFBAND = SNDCTL_SEQ_OUTOFBAND;
810 unsigned IOCTL_SNDCTL_SEQ_PANIC = SNDCTL_SEQ_PANIC;
811 unsigned IOCTL_SNDCTL_SEQ_PERCMODE = SNDCTL_SEQ_PERCMODE;
812 unsigned IOCTL_SNDCTL_SEQ_RESET = SNDCTL_SEQ_RESET;
813 unsigned IOCTL_SNDCTL_SEQ_RESETSAMPLES = SNDCTL_SEQ_RESETSAMPLES;
814 unsigned IOCTL_SNDCTL_SEQ_SYNC = SNDCTL_SEQ_SYNC;
815 unsigned IOCTL_SNDCTL_SEQ_TESTMIDI = SNDCTL_SEQ_TESTMIDI;
816 unsigned IOCTL_SNDCTL_SEQ_THRESHOLD = SNDCTL_SEQ_THRESHOLD;
817 unsigned IOCTL_SNDCTL_SYNTH_INFO = SNDCTL_SYNTH_INFO;
818 unsigned IOCTL_SNDCTL_SYNTH_MEMAVL = SNDCTL_SYNTH_MEMAVL;
819 unsigned IOCTL_SNDCTL_TMR_CONTINUE = SNDCTL_TMR_CONTINUE;
820 unsigned IOCTL_SNDCTL_TMR_METRONOME = SNDCTL_TMR_METRONOME;
821 unsigned IOCTL_SNDCTL_TMR_SELECT = SNDCTL_TMR_SELECT;
822 unsigned IOCTL_SNDCTL_TMR_SOURCE = SNDCTL_TMR_SOURCE;
823 unsigned IOCTL_SNDCTL_TMR_START = SNDCTL_TMR_START;
824 unsigned IOCTL_SNDCTL_TMR_STOP = SNDCTL_TMR_STOP;
825 unsigned IOCTL_SNDCTL_TMR_TEMPO = SNDCTL_TMR_TEMPO;
826 unsigned IOCTL_SNDCTL_TMR_TIMEBASE = SNDCTL_TMR_TIMEBASE;
827 unsigned IOCTL_SOUND_MIXER_READ_ALTPCM = SOUND_MIXER_READ_ALTPCM;
828 unsigned IOCTL_SOUND_MIXER_READ_BASS = SOUND_MIXER_READ_BASS;
829 unsigned IOCTL_SOUND_MIXER_READ_CAPS = SOUND_MIXER_READ_CAPS;
830 unsigned IOCTL_SOUND_MIXER_READ_CD = SOUND_MIXER_READ_CD;
831 unsigned IOCTL_SOUND_MIXER_READ_DEVMASK = SOUND_MIXER_READ_DEVMASK;
832 unsigned IOCTL_SOUND_MIXER_READ_ENHANCE = SOUND_MIXER_READ_ENHANCE;
833 unsigned IOCTL_SOUND_MIXER_READ_IGAIN = SOUND_MIXER_READ_IGAIN;
834 unsigned IOCTL_SOUND_MIXER_READ_IMIX = SOUND_MIXER_READ_IMIX;
835 unsigned IOCTL_SOUND_MIXER_READ_LINE = SOUND_MIXER_READ_LINE;
836 unsigned IOCTL_SOUND_MIXER_READ_LINE1 = SOUND_MIXER_READ_LINE1;
837 unsigned IOCTL_SOUND_MIXER_READ_LINE2 = SOUND_MIXER_READ_LINE2;
838 unsigned IOCTL_SOUND_MIXER_READ_LINE3 = SOUND_MIXER_READ_LINE3;
839 unsigned IOCTL_SOUND_MIXER_READ_LOUD = SOUND_MIXER_READ_LOUD;
840 unsigned IOCTL_SOUND_MIXER_READ_MIC = SOUND_MIXER_READ_MIC;
841 unsigned IOCTL_SOUND_MIXER_READ_MUTE = SOUND_MIXER_READ_MUTE;
842 unsigned IOCTL_SOUND_MIXER_READ_OGAIN = SOUND_MIXER_READ_OGAIN;
843 unsigned IOCTL_SOUND_MIXER_READ_PCM = SOUND_MIXER_READ_PCM;
844 unsigned IOCTL_SOUND_MIXER_READ_RECLEV = SOUND_MIXER_READ_RECLEV;
845 unsigned IOCTL_SOUND_MIXER_READ_RECMASK = SOUND_MIXER_READ_RECMASK;
846 unsigned IOCTL_SOUND_MIXER_READ_RECSRC = SOUND_MIXER_READ_RECSRC;
847 unsigned IOCTL_SOUND_MIXER_READ_SPEAKER = SOUND_MIXER_READ_SPEAKER;
848 unsigned IOCTL_SOUND_MIXER_READ_STEREODEVS = SOUND_MIXER_READ_STEREODEVS;
849 unsigned IOCTL_SOUND_MIXER_READ_SYNTH = SOUND_MIXER_READ_SYNTH;
850 unsigned IOCTL_SOUND_MIXER_READ_TREBLE = SOUND_MIXER_READ_TREBLE;
851 unsigned IOCTL_SOUND_MIXER_READ_VOLUME = SOUND_MIXER_READ_VOLUME;
852 unsigned IOCTL_SOUND_MIXER_WRITE_ALTPCM = SOUND_MIXER_WRITE_ALTPCM;
853 unsigned IOCTL_SOUND_MIXER_WRITE_BASS = SOUND_MIXER_WRITE_BASS;
854 unsigned IOCTL_SOUND_MIXER_WRITE_CD = SOUND_MIXER_WRITE_CD;
855 unsigned IOCTL_SOUND_MIXER_WRITE_ENHANCE = SOUND_MIXER_WRITE_ENHANCE;
856 unsigned IOCTL_SOUND_MIXER_WRITE_IGAIN = SOUND_MIXER_WRITE_IGAIN;
857 unsigned IOCTL_SOUND_MIXER_WRITE_IMIX = SOUND_MIXER_WRITE_IMIX;
858 unsigned IOCTL_SOUND_MIXER_WRITE_LINE = SOUND_MIXER_WRITE_LINE;
859 unsigned IOCTL_SOUND_MIXER_WRITE_LINE1 = SOUND_MIXER_WRITE_LINE1;
860 unsigned IOCTL_SOUND_MIXER_WRITE_LINE2 = SOUND_MIXER_WRITE_LINE2;
861 unsigned IOCTL_SOUND_MIXER_WRITE_LINE3 = SOUND_MIXER_WRITE_LINE3;
862 unsigned IOCTL_SOUND_MIXER_WRITE_LOUD = SOUND_MIXER_WRITE_LOUD;
863 unsigned IOCTL_SOUND_MIXER_WRITE_MIC = SOUND_MIXER_WRITE_MIC;
864 unsigned IOCTL_SOUND_MIXER_WRITE_MUTE = SOUND_MIXER_WRITE_MUTE;
865 unsigned IOCTL_SOUND_MIXER_WRITE_OGAIN = SOUND_MIXER_WRITE_OGAIN;
866 unsigned IOCTL_SOUND_MIXER_WRITE_PCM = SOUND_MIXER_WRITE_PCM;
867 unsigned IOCTL_SOUND_MIXER_WRITE_RECLEV = SOUND_MIXER_WRITE_RECLEV;
868 unsigned IOCTL_SOUND_MIXER_WRITE_RECSRC = SOUND_MIXER_WRITE_RECSRC;
869 unsigned IOCTL_SOUND_MIXER_WRITE_SPEAKER = SOUND_MIXER_WRITE_SPEAKER;
870 unsigned IOCTL_SOUND_MIXER_WRITE_SYNTH = SOUND_MIXER_WRITE_SYNTH;
871 unsigned IOCTL_SOUND_MIXER_WRITE_TREBLE = SOUND_MIXER_WRITE_TREBLE;
872 unsigned IOCTL_SOUND_MIXER_WRITE_VOLUME = SOUND_MIXER_WRITE_VOLUME;
873 unsigned IOCTL_VT_ACTIVATE = VT_ACTIVATE;
874 unsigned IOCTL_VT_GETMODE = VT_GETMODE;
875 unsigned IOCTL_VT_OPENQRY = VT_OPENQRY;
876 unsigned IOCTL_VT_RELDISP = VT_RELDISP;
877 unsigned IOCTL_VT_SETMODE = VT_SETMODE;
878 unsigned IOCTL_VT_WAITACTIVE = VT_WAITACTIVE;
879#endif // SANITIZER_LINUX
880
881#if SANITIZER_LINUX && !SANITIZER_ANDROID
882 unsigned IOCTL_EQL_EMANCIPATE = EQL_EMANCIPATE;
883 unsigned IOCTL_EQL_ENSLAVE = EQL_ENSLAVE;
884 unsigned IOCTL_EQL_GETMASTRCFG = EQL_GETMASTRCFG;
885 unsigned IOCTL_EQL_GETSLAVECFG = EQL_GETSLAVECFG;
886 unsigned IOCTL_EQL_SETMASTRCFG = EQL_SETMASTRCFG;
887 unsigned IOCTL_EQL_SETSLAVECFG = EQL_SETSLAVECFG;
888#if EV_VERSION > (0x010000)
889 unsigned IOCTL_EVIOCGKEYCODE_V2 = EVIOCGKEYCODE_V2;
890 unsigned IOCTL_EVIOCGPROP = EVIOCGPROP(0);
891 unsigned IOCTL_EVIOCSKEYCODE_V2 = EVIOCSKEYCODE_V2;
892#else
893 unsigned IOCTL_EVIOCGKEYCODE_V2 = IOCTL_NOT_PRESENT;
894 unsigned IOCTL_EVIOCGPROP = IOCTL_NOT_PRESENT;
895 unsigned IOCTL_EVIOCSKEYCODE_V2 = IOCTL_NOT_PRESENT;
896#endif
897 unsigned IOCTL_FS_IOC_GETFLAGS = _IOR('f', 1, long);
898 unsigned IOCTL_FS_IOC_GETVERSION = _IOR('v', 1, long);
899 unsigned IOCTL_FS_IOC_SETFLAGS = _IOW('f', 2, long);
900 unsigned IOCTL_FS_IOC_SETVERSION = _IOW('v', 2, long);
901 unsigned IOCTL_GIO_CMAP = GIO_CMAP;
902 unsigned IOCTL_GIO_FONT = GIO_FONT;
903 unsigned IOCTL_GIO_UNIMAP = GIO_UNIMAP;
904 unsigned IOCTL_GIO_UNISCRNMAP = GIO_UNISCRNMAP;
905 unsigned IOCTL_KDADDIO = KDADDIO;
906 unsigned IOCTL_KDDELIO = KDDELIO;
907 unsigned IOCTL_KDGETKEYCODE = KDGETKEYCODE;
908 unsigned IOCTL_KDGKBDIACR = KDGKBDIACR;
909 unsigned IOCTL_KDGKBENT = KDGKBENT;
910 unsigned IOCTL_KDGKBLED = KDGKBLED;
911 unsigned IOCTL_KDGKBMETA = KDGKBMETA;
912 unsigned IOCTL_KDGKBSENT = KDGKBSENT;
913 unsigned IOCTL_KDMAPDISP = KDMAPDISP;
914 unsigned IOCTL_KDSETKEYCODE = KDSETKEYCODE;
915 unsigned IOCTL_KDSIGACCEPT = KDSIGACCEPT;
916 unsigned IOCTL_KDSKBDIACR = KDSKBDIACR;
917 unsigned IOCTL_KDSKBENT = KDSKBENT;
918 unsigned IOCTL_KDSKBLED = KDSKBLED;
919 unsigned IOCTL_KDSKBMETA = KDSKBMETA;
920 unsigned IOCTL_KDSKBSENT = KDSKBSENT;
921 unsigned IOCTL_KDUNMAPDISP = KDUNMAPDISP;
922 unsigned IOCTL_LPABORT = LPABORT;
923 unsigned IOCTL_LPABORTOPEN = LPABORTOPEN;
924 unsigned IOCTL_LPCAREFUL = LPCAREFUL;
925 unsigned IOCTL_LPCHAR = LPCHAR;
926 unsigned IOCTL_LPGETIRQ = LPGETIRQ;
927 unsigned IOCTL_LPGETSTATUS = LPGETSTATUS;
928 unsigned IOCTL_LPRESET = LPRESET;
929 unsigned IOCTL_LPSETIRQ = LPSETIRQ;
930 unsigned IOCTL_LPTIME = LPTIME;
931 unsigned IOCTL_LPWAIT = LPWAIT;
932 unsigned IOCTL_MTIOCGETCONFIG = MTIOCGETCONFIG;
933 unsigned IOCTL_MTIOCSETCONFIG = MTIOCSETCONFIG;
934 unsigned IOCTL_PIO_CMAP = PIO_CMAP;
935 unsigned IOCTL_PIO_FONT = PIO_FONT;
936 unsigned IOCTL_PIO_UNIMAP = PIO_UNIMAP;
937 unsigned IOCTL_PIO_UNIMAPCLR = PIO_UNIMAPCLR;
938 unsigned IOCTL_PIO_UNISCRNMAP = PIO_UNISCRNMAP;
939#if SANITIZER_GLIBC
940 unsigned IOCTL_SCSI_IOCTL_GET_IDLUN = SCSI_IOCTL_GET_IDLUN;
941 unsigned IOCTL_SCSI_IOCTL_PROBE_HOST = SCSI_IOCTL_PROBE_HOST;
942 unsigned IOCTL_SCSI_IOCTL_TAGGED_DISABLE = SCSI_IOCTL_TAGGED_DISABLE;
943 unsigned IOCTL_SCSI_IOCTL_TAGGED_ENABLE = SCSI_IOCTL_TAGGED_ENABLE;
944 unsigned IOCTL_SIOCAIPXITFCRT = SIOCAIPXITFCRT;
945 unsigned IOCTL_SIOCAIPXPRISLT = SIOCAIPXPRISLT;
946 unsigned IOCTL_SIOCAX25ADDUID = SIOCAX25ADDUID;
947 unsigned IOCTL_SIOCAX25DELUID = SIOCAX25DELUID;
948 unsigned IOCTL_SIOCAX25GETPARMS = SIOCAX25GETPARMS;
949 unsigned IOCTL_SIOCAX25GETUID = SIOCAX25GETUID;
950 unsigned IOCTL_SIOCAX25NOUID = SIOCAX25NOUID;
951 unsigned IOCTL_SIOCAX25SETPARMS = SIOCAX25SETPARMS;
952 unsigned IOCTL_SIOCDEVPLIP = SIOCDEVPLIP;
953 unsigned IOCTL_SIOCIPXCFGDATA = SIOCIPXCFGDATA;
954 unsigned IOCTL_SIOCNRDECOBS = SIOCNRDECOBS;
955 unsigned IOCTL_SIOCNRGETPARMS = SIOCNRGETPARMS;
956 unsigned IOCTL_SIOCNRRTCTL = SIOCNRRTCTL;
957 unsigned IOCTL_SIOCNRSETPARMS = SIOCNRSETPARMS;
958#endif
959 unsigned IOCTL_TIOCGSERIAL = TIOCGSERIAL;
960 unsigned IOCTL_TIOCSERGETMULTI = TIOCSERGETMULTI;
961 unsigned IOCTL_TIOCSERSETMULTI = TIOCSERSETMULTI;
962 unsigned IOCTL_TIOCSSERIAL = TIOCSSERIAL;
963#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
964
965#if SANITIZER_LINUX && !SANITIZER_ANDROID
966 unsigned IOCTL_GIO_SCRNMAP = GIO_SCRNMAP;
967 unsigned IOCTL_KDDISABIO = KDDISABIO;
968 unsigned IOCTL_KDENABIO = KDENABIO;
969 unsigned IOCTL_KDGETLED = KDGETLED;
970 unsigned IOCTL_KDGETMODE = KDGETMODE;
971 unsigned IOCTL_KDGKBMODE = KDGKBMODE;
972 unsigned IOCTL_KDGKBTYPE = KDGKBTYPE;
973 unsigned IOCTL_KDMKTONE = KDMKTONE;
974 unsigned IOCTL_KDSETLED = KDSETLED;
975 unsigned IOCTL_KDSETMODE = KDSETMODE;
976 unsigned IOCTL_KDSKBMODE = KDSKBMODE;
977 unsigned IOCTL_KIOCSOUND = KIOCSOUND;
978 unsigned IOCTL_PIO_SCRNMAP = PIO_SCRNMAP;
979 unsigned IOCTL_SNDCTL_DSP_GETISPACE = SNDCTL_DSP_GETISPACE;
980 unsigned IOCTL_SNDCTL_DSP_GETOSPACE = SNDCTL_DSP_GETOSPACE;
981#endif // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
982
983 const int si_SEGV_MAPERR = SEGV_MAPERR;
984 const int si_SEGV_ACCERR = SEGV_ACCERR;
985} // namespace __sanitizer
986
987using namespace __sanitizer;
988
989COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
990
991COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
992CHECK_TYPE_SIZE(pthread_key_t);
993
994#if SANITIZER_LINUX
995// FIXME: We define those on Linux and Mac, but only check on Linux.
996COMPILER_CHECK(IOC_NRBITS == _IOC_NRBITS);
997COMPILER_CHECK(IOC_TYPEBITS == _IOC_TYPEBITS);
998COMPILER_CHECK(IOC_SIZEBITS == _IOC_SIZEBITS);
999COMPILER_CHECK(IOC_DIRBITS == _IOC_DIRBITS);
1000COMPILER_CHECK(IOC_NRMASK == _IOC_NRMASK);
1001COMPILER_CHECK(IOC_TYPEMASK == _IOC_TYPEMASK);
1002COMPILER_CHECK(IOC_SIZEMASK == _IOC_SIZEMASK);
1003COMPILER_CHECK(IOC_DIRMASK == _IOC_DIRMASK);
1004COMPILER_CHECK(IOC_NRSHIFT == _IOC_NRSHIFT);
1005COMPILER_CHECK(IOC_TYPESHIFT == _IOC_TYPESHIFT);
1006COMPILER_CHECK(IOC_SIZESHIFT == _IOC_SIZESHIFT);
1007COMPILER_CHECK(IOC_DIRSHIFT == _IOC_DIRSHIFT);
1008COMPILER_CHECK(IOC_NONE == _IOC_NONE);
1009COMPILER_CHECK(IOC_WRITE == _IOC_WRITE);
1010COMPILER_CHECK(IOC_READ == _IOC_READ);
1011COMPILER_CHECK(EVIOC_ABS_MAX == ABS_MAX);
1012COMPILER_CHECK(EVIOC_EV_MAX == EV_MAX);
1013COMPILER_CHECK(IOC_SIZE(0x12345678) == _IOC_SIZE(0x12345678));
1014COMPILER_CHECK(IOC_DIR(0x12345678) == _IOC_DIR(0x12345678));
1015COMPILER_CHECK(IOC_NR(0x12345678) == _IOC_NR(0x12345678));
1016COMPILER_CHECK(IOC_TYPE(0x12345678) == _IOC_TYPE(0x12345678));
1017#endif // SANITIZER_LINUX
1018
1019#if SANITIZER_LINUX || SANITIZER_FREEBSD
1020// There are more undocumented fields in dl_phdr_info that we are not interested
1021// in.
1022COMPILER_CHECK(sizeof(__sanitizer_dl_phdr_info) <= sizeof(dl_phdr_info));
1023CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr);
1024CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
1025CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
1026CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
1027#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
1028
1029#if SANITIZER_GLIBC || SANITIZER_FREEBSD
1030CHECK_TYPE_SIZE(glob_t);
1031CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
1032CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
1033CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
1034CHECK_SIZE_AND_OFFSET(glob_t, gl_flags);
1035CHECK_SIZE_AND_OFFSET(glob_t, gl_closedir);
1036CHECK_SIZE_AND_OFFSET(glob_t, gl_readdir);
1037CHECK_SIZE_AND_OFFSET(glob_t, gl_opendir);
1038CHECK_SIZE_AND_OFFSET(glob_t, gl_lstat);
1039CHECK_SIZE_AND_OFFSET(glob_t, gl_stat);
1040#endif // SANITIZER_GLIBC || SANITIZER_FREEBSD
1041
1042CHECK_TYPE_SIZE(addrinfo);
1043CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags);
1044CHECK_SIZE_AND_OFFSET(addrinfo, ai_family);
1045CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype);
1046CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
1047CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
1048CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen);
1049CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname);
1050CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr);
1051
1052CHECK_TYPE_SIZE(hostent);
1053CHECK_SIZE_AND_OFFSET(hostent, h_name);
1054CHECK_SIZE_AND_OFFSET(hostent, h_aliases);
1055CHECK_SIZE_AND_OFFSET(hostent, h_addrtype);
1056CHECK_SIZE_AND_OFFSET(hostent, h_length);
1057CHECK_SIZE_AND_OFFSET(hostent, h_addr_list);
1058
1059CHECK_TYPE_SIZE(iovec);
1060CHECK_SIZE_AND_OFFSET(iovec, iov_base);
1061CHECK_SIZE_AND_OFFSET(iovec, iov_len);
1062
1063// In POSIX, int msg_iovlen; socklen_t msg_controllen; socklen_t cmsg_len; but
1064// many implementations don't conform to the standard. Since we pick the
1065// non-conforming glibc definition, exclude the checks for musl (incompatible
1066// sizes but compatible offsets).
1067CHECK_TYPE_SIZE(msghdr);
1068CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
1069CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
1070CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
1071#if SANITIZER_GLIBC || SANITIZER_ANDROID
1072CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
1073#endif
1074CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
1075#if SANITIZER_GLIBC || SANITIZER_ANDROID
1076CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
1077#endif
1078CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
1079
1080CHECK_TYPE_SIZE(cmsghdr);
1081#if SANITIZER_GLIBC || SANITIZER_ANDROID
1082CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
1083#endif
1084CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
1085CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
1086
1087#if SANITIZER_LINUX && (__ANDROID_API__ >= 21 || __GLIBC_PREREQ (2, 14))
1088CHECK_TYPE_SIZE(mmsghdr);
1089CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr);
1090CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);
1091#endif
1092
1093COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
1094CHECK_SIZE_AND_OFFSET(dirent, d_ino);
1095#if SANITIZER_APPLE
1096CHECK_SIZE_AND_OFFSET(dirent, d_seekoff);
1097#elif SANITIZER_FREEBSD
1098// There is no 'd_off' field on FreeBSD.
1099#else
1100CHECK_SIZE_AND_OFFSET(dirent, d_off);
1101#endif
1102CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
1103
1104#if SANITIZER_GLIBC
1105COMPILER_CHECK(sizeof(__sanitizer_dirent64) <= sizeof(dirent64));
1106CHECK_SIZE_AND_OFFSET(dirent64, d_ino);
1107CHECK_SIZE_AND_OFFSET(dirent64, d_off);
1108CHECK_SIZE_AND_OFFSET(dirent64, d_reclen);
1109#endif
1110
1111CHECK_TYPE_SIZE(ifconf);
1112CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
1113CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
1114
1115CHECK_TYPE_SIZE(pollfd);
1116CHECK_SIZE_AND_OFFSET(pollfd, fd);
1117CHECK_SIZE_AND_OFFSET(pollfd, events);
1118CHECK_SIZE_AND_OFFSET(pollfd, revents);
1119
1120CHECK_TYPE_SIZE(nfds_t);
1121
1122CHECK_TYPE_SIZE(sigset_t);
1123
1124COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction));
1125// Can't write checks for sa_handler and sa_sigaction due to them being
1126// preprocessor macros.
1127CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
1128#if !defined(__s390x__) || __GLIBC_PREREQ (2, 20)
1129// On s390x glibc 2.19 and earlier sa_flags was unsigned long, and sa_resv
1130// didn't exist.
1131CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_flags);
1132#endif
1133#if SANITIZER_LINUX && (!SANITIZER_ANDROID || !SANITIZER_MIPS32)
1134CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_restorer);
1135#endif
1136
1137#if SANITIZER_HAS_SIGINFO
1138COMPILER_CHECK(alignof(siginfo_t) == alignof(__sanitizer_siginfo));
1139using __sanitizer_siginfo_t = __sanitizer_siginfo;
1140CHECK_TYPE_SIZE(siginfo_t);
1141CHECK_SIZE_AND_OFFSET(siginfo_t, si_signo);
1142CHECK_SIZE_AND_OFFSET(siginfo_t, si_errno);
1143CHECK_SIZE_AND_OFFSET(siginfo_t, si_code);
1144#endif
1145
1146#if SANITIZER_LINUX
1147CHECK_TYPE_SIZE(__sysctl_args);
1148CHECK_SIZE_AND_OFFSET(__sysctl_args, name);
1149CHECK_SIZE_AND_OFFSET(__sysctl_args, nlen);
1150CHECK_SIZE_AND_OFFSET(__sysctl_args, oldval);
1151CHECK_SIZE_AND_OFFSET(__sysctl_args, oldlenp);
1152CHECK_SIZE_AND_OFFSET(__sysctl_args, newval);
1153CHECK_SIZE_AND_OFFSET(__sysctl_args, newlen);
1154
1155CHECK_TYPE_SIZE(__kernel_uid_t);
1156CHECK_TYPE_SIZE(__kernel_gid_t);
1157
1158#if SANITIZER_USES_UID16_SYSCALLS
1159CHECK_TYPE_SIZE(__kernel_old_uid_t);
1160CHECK_TYPE_SIZE(__kernel_old_gid_t);
1161#endif
1162
1163CHECK_TYPE_SIZE(__kernel_off_t);
1164CHECK_TYPE_SIZE(__kernel_loff_t);
1165CHECK_TYPE_SIZE(__kernel_fd_set);
1166#endif
1167
1168#if !SANITIZER_ANDROID
1169CHECK_TYPE_SIZE(wordexp_t);
1170CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
1171CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
1172CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
1173#endif
1174
1175CHECK_TYPE_SIZE(tm);
1176CHECK_SIZE_AND_OFFSET(tm, tm_sec);
1177CHECK_SIZE_AND_OFFSET(tm, tm_min);
1178CHECK_SIZE_AND_OFFSET(tm, tm_hour);
1179CHECK_SIZE_AND_OFFSET(tm, tm_mday);
1180CHECK_SIZE_AND_OFFSET(tm, tm_mon);
1181CHECK_SIZE_AND_OFFSET(tm, tm_year);
1182CHECK_SIZE_AND_OFFSET(tm, tm_wday);
1183CHECK_SIZE_AND_OFFSET(tm, tm_yday);
1184CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
1185CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff);
1186CHECK_SIZE_AND_OFFSET(tm, tm_zone);
1187
1188#if SANITIZER_LINUX
1189CHECK_TYPE_SIZE(mntent);
1190CHECK_SIZE_AND_OFFSET(mntent, mnt_fsname);
1191CHECK_SIZE_AND_OFFSET(mntent, mnt_dir);
1192CHECK_SIZE_AND_OFFSET(mntent, mnt_type);
1193CHECK_SIZE_AND_OFFSET(mntent, mnt_opts);
1194CHECK_SIZE_AND_OFFSET(mntent, mnt_freq);
1195CHECK_SIZE_AND_OFFSET(mntent, mnt_passno);
1196#endif
1197
1198CHECK_TYPE_SIZE(ether_addr);
1199
1200#if SANITIZER_GLIBC || SANITIZER_FREEBSD
1201CHECK_TYPE_SIZE(ipc_perm);
1202# if SANITIZER_FREEBSD
1203CHECK_SIZE_AND_OFFSET(ipc_perm, key);
1204CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
1205# else
1206CHECK_SIZE_AND_OFFSET(ipc_perm, __key);
1207CHECK_SIZE_AND_OFFSET(ipc_perm, __seq);
1208# endif
1209CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
1210CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
1211CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
1212CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
1213#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
1214/* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit
1215 on many architectures. */
1216CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
1217#endif
1218
1219CHECK_TYPE_SIZE(shmid_ds);
1220CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);
1221CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz);
1222CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime);
1223CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime);
1224CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime);
1225CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid);
1226CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
1227CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
1228#endif
1229
1230CHECK_TYPE_SIZE(clock_t);
1231
1232#if SANITIZER_LINUX
1233CHECK_TYPE_SIZE(clockid_t);
1234#endif
1235
1236#if !SANITIZER_ANDROID
1237CHECK_TYPE_SIZE(ifaddrs);
1238CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
1239CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
1240CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
1241CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask);
1242#if SANITIZER_LINUX || SANITIZER_FREEBSD
1243// Compare against the union, because we can't reach into the union in a
1244// compliant way.
1245#ifdef ifa_dstaddr
1246#undef ifa_dstaddr
1247#endif
1248# if SANITIZER_FREEBSD
1249CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
1250# else
1251COMPILER_CHECK(sizeof(((__sanitizer_ifaddrs *)nullptr)->ifa_dstaddr) ==
1252 sizeof(((ifaddrs *)nullptr)->ifa_ifu));
1253COMPILER_CHECK(offsetof(__sanitizer_ifaddrs, ifa_dstaddr) ==
1254 offsetof(ifaddrs, ifa_ifu));
1255# endif // SANITIZER_FREEBSD
1256#else
1257CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
1258#endif // SANITIZER_LINUX
1259CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
1260#endif
1261
1262#if SANITIZER_GLIBC || SANITIZER_ANDROID
1263COMPILER_CHECK(sizeof(__sanitizer_struct_mallinfo) == sizeof(struct mallinfo));
1264#endif
1265
1266#if !SANITIZER_ANDROID
1267CHECK_TYPE_SIZE(timeb);
1268CHECK_SIZE_AND_OFFSET(timeb, time);
1269CHECK_SIZE_AND_OFFSET(timeb, millitm);
1270CHECK_SIZE_AND_OFFSET(timeb, timezone);
1271CHECK_SIZE_AND_OFFSET(timeb, dstflag);
1272#endif
1273
1274CHECK_TYPE_SIZE(passwd);
1275CHECK_SIZE_AND_OFFSET(passwd, pw_name);
1276CHECK_SIZE_AND_OFFSET(passwd, pw_passwd);
1277CHECK_SIZE_AND_OFFSET(passwd, pw_uid);
1278CHECK_SIZE_AND_OFFSET(passwd, pw_gid);
1279CHECK_SIZE_AND_OFFSET(passwd, pw_dir);
1280CHECK_SIZE_AND_OFFSET(passwd, pw_shell);
1281
1282#if !SANITIZER_ANDROID
1283CHECK_SIZE_AND_OFFSET(passwd, pw_gecos);
1284#endif
1285
1286#if SANITIZER_APPLE
1287CHECK_SIZE_AND_OFFSET(passwd, pw_change);
1288CHECK_SIZE_AND_OFFSET(passwd, pw_expire);
1289CHECK_SIZE_AND_OFFSET(passwd, pw_class);
1290#endif
1291
1292
1293CHECK_TYPE_SIZE(group);
1294CHECK_SIZE_AND_OFFSET(group, gr_name);
1295CHECK_SIZE_AND_OFFSET(group, gr_passwd);
1296CHECK_SIZE_AND_OFFSET(group, gr_gid);
1297CHECK_SIZE_AND_OFFSET(group, gr_mem);
1298
1299#if HAVE_RPC_XDR_H && !SANITIZER_APPLE
1300CHECK_TYPE_SIZE(XDR);
1301CHECK_SIZE_AND_OFFSET(XDR, x_op);
1302CHECK_SIZE_AND_OFFSET(XDR, x_ops);
1303CHECK_SIZE_AND_OFFSET(XDR, x_public);
1304CHECK_SIZE_AND_OFFSET(XDR, x_private);
1305CHECK_SIZE_AND_OFFSET(XDR, x_base);
1306CHECK_SIZE_AND_OFFSET(XDR, x_handy);
1307COMPILER_CHECK(__sanitizer_XDR_ENCODE == XDR_ENCODE);
1308COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE);
1309COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
1310#endif
1311
1312#if SANITIZER_GLIBC
1313COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
1314CHECK_SIZE_AND_OFFSET(FILE, _flags);
1315CHECK_SIZE_AND_OFFSET(FILE, _IO_read_ptr);
1316CHECK_SIZE_AND_OFFSET(FILE, _IO_read_end);
1317CHECK_SIZE_AND_OFFSET(FILE, _IO_read_base);
1318CHECK_SIZE_AND_OFFSET(FILE, _IO_write_ptr);
1319CHECK_SIZE_AND_OFFSET(FILE, _IO_write_end);
1320CHECK_SIZE_AND_OFFSET(FILE, _IO_write_base);
1321CHECK_SIZE_AND_OFFSET(FILE, _IO_buf_base);
1322CHECK_SIZE_AND_OFFSET(FILE, _IO_buf_end);
1323CHECK_SIZE_AND_OFFSET(FILE, _IO_save_base);
1324CHECK_SIZE_AND_OFFSET(FILE, _IO_backup_base);
1325CHECK_SIZE_AND_OFFSET(FILE, _IO_save_end);
1326CHECK_SIZE_AND_OFFSET(FILE, _markers);
1327CHECK_SIZE_AND_OFFSET(FILE, _chain);
1328CHECK_SIZE_AND_OFFSET(FILE, _fileno);
1329
1330COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk));
1331CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit);
1332CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev);
1333CHECK_TYPE_SIZE(obstack);
1334CHECK_SIZE_AND_OFFSET(obstack, chunk_size);
1335CHECK_SIZE_AND_OFFSET(obstack, chunk);
1336CHECK_SIZE_AND_OFFSET(obstack, object_base);
1337CHECK_SIZE_AND_OFFSET(obstack, next_free);
1338
1339CHECK_TYPE_SIZE(cookie_io_functions_t);
1340CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, read);
1341CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, write);
1342CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, seek);
1343CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, close);
1344#endif // SANITIZER_GLIBC
1345
1346#if SANITIZER_LINUX || SANITIZER_FREEBSD
1347CHECK_TYPE_SIZE(sem_t);
1348#endif
1349
1350#if SANITIZER_LINUX && defined(__arm__)
1351COMPILER_CHECK(ARM_VFPREGS_SIZE == ARM_VFPREGS_SIZE_ASAN);
1352#endif
1353
1354#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_APPLE
1355

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