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

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