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__) || defined(__loongarch__) ||SANITIZER_RISCV64
98 #      include <asm/ptrace.h>
99 #      ifdef __arm__
100 typedef 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 
183 namespace __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 
ucontext_t_sz(void * ctx)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_GLIBC
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_GLIBC
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 
__sanitizer_in_addr_sz(int af)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
338 unsigned struct_ElfW_Phdr_sz = sizeof(ElfW(Phdr));
339 #elif SANITIZER_FREEBSD
340 unsigned 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__) || defined(__loongarch__)|| 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(__loongarch__)
366   unsigned struct_user_regs_struct_sz = sizeof(struct user_pt_regs);
367   unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fp_state);
368 #elif defined(__s390__)
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 #else
372   unsigned struct_user_regs_struct_sz = sizeof(struct user_regs_struct);
373   unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fpregs_struct);
374 #endif // __mips64 || __powerpc64__ || __aarch64__ || __loongarch__
375 #if defined(__x86_64) || defined(__mips64) || defined(__powerpc64__) || \
376     defined(__aarch64__) || defined(__arm__) || defined(__s390__) ||    \
377     defined(__loongarch__) || SANITIZER_RISCV64
378   unsigned struct_user_fpxregs_struct_sz = 0;
379 #else
380   unsigned struct_user_fpxregs_struct_sz = sizeof(struct user_fpxregs_struct);
381 #endif // __x86_64 || __mips64 || __powerpc64__ || __aarch64__ || __arm__
382 // || __s390__ || __loongarch__
383 #ifdef __arm__
384   unsigned struct_user_vfpregs_struct_sz = ARM_VFPREGS_SIZE;
385 #else
386   unsigned struct_user_vfpregs_struct_sz = 0;
387 #endif
388 
389   int ptrace_peektext = PTRACE_PEEKTEXT;
390   int ptrace_peekdata = PTRACE_PEEKDATA;
391   int ptrace_peekuser = PTRACE_PEEKUSER;
392 #if (defined(PTRACE_GETREGS) && defined(PTRACE_SETREGS)) || \
393     (defined(PT_GETREGS) && defined(PT_SETREGS))
394   int ptrace_getregs = PTRACE_GETREGS;
395   int ptrace_setregs = PTRACE_SETREGS;
396 #else
397   int ptrace_getregs = -1;
398   int ptrace_setregs = -1;
399 #endif
400 #if (defined(PTRACE_GETFPREGS) && defined(PTRACE_SETFPREGS)) || \
401     (defined(PT_GETFPREGS) && defined(PT_SETFPREGS))
402   int ptrace_getfpregs = PTRACE_GETFPREGS;
403   int ptrace_setfpregs = PTRACE_SETFPREGS;
404 #else
405   int ptrace_getfpregs = -1;
406   int ptrace_setfpregs = -1;
407 #endif
408 #if (defined(PTRACE_GETFPXREGS) && defined(PTRACE_SETFPXREGS)) || \
409     (defined(PT_GETFPXREGS) && defined(PT_SETFPXREGS))
410   int ptrace_getfpxregs = PTRACE_GETFPXREGS;
411   int ptrace_setfpxregs = PTRACE_SETFPXREGS;
412 #else
413   int ptrace_getfpxregs = -1;
414   int ptrace_setfpxregs = -1;
415 #endif // PTRACE_GETFPXREGS/PTRACE_SETFPXREGS
416 #if defined(PTRACE_GETVFPREGS) && defined(PTRACE_SETVFPREGS)
417   int ptrace_getvfpregs = PTRACE_GETVFPREGS;
418   int ptrace_setvfpregs = PTRACE_SETVFPREGS;
419 #else
420   int ptrace_getvfpregs = -1;
421   int ptrace_setvfpregs = -1;
422 #endif
423   int ptrace_geteventmsg = PTRACE_GETEVENTMSG;
424 #if (defined(PTRACE_GETSIGINFO) && defined(PTRACE_SETSIGINFO)) ||              \
425     (defined(PT_GETSIGINFO) && defined(PT_SETSIGINFO))
426   int ptrace_getsiginfo = PTRACE_GETSIGINFO;
427   int ptrace_setsiginfo = PTRACE_SETSIGINFO;
428 #else
429   int ptrace_getsiginfo = -1;
430   int ptrace_setsiginfo = -1;
431 #endif // PTRACE_GETSIGINFO/PTRACE_SETSIGINFO
432 #if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET)
433   int ptrace_getregset = PTRACE_GETREGSET;
434   int ptrace_setregset = PTRACE_SETREGSET;
435 #else
436   int ptrace_getregset = -1;
437   int ptrace_setregset = -1;
438 #endif // PTRACE_GETREGSET/PTRACE_SETREGSET
439 #endif
440 
441   unsigned path_max = PATH_MAX;
442 
443   // ioctl arguments
444   unsigned struct_ifreq_sz = sizeof(struct ifreq);
445   unsigned struct_termios_sz = sizeof(struct termios);
446   unsigned struct_winsize_sz = sizeof(struct winsize);
447 
448 #if SANITIZER_LINUX
449   unsigned struct_arpreq_sz = sizeof(struct arpreq);
450   unsigned struct_cdrom_msf_sz = sizeof(struct cdrom_msf);
451   unsigned struct_cdrom_multisession_sz = sizeof(struct cdrom_multisession);
452   unsigned struct_cdrom_read_audio_sz = sizeof(struct cdrom_read_audio);
453   unsigned struct_cdrom_subchnl_sz = sizeof(struct cdrom_subchnl);
454   unsigned struct_cdrom_ti_sz = sizeof(struct cdrom_ti);
455   unsigned struct_cdrom_tocentry_sz = sizeof(struct cdrom_tocentry);
456   unsigned struct_cdrom_tochdr_sz = sizeof(struct cdrom_tochdr);
457   unsigned struct_cdrom_volctrl_sz = sizeof(struct cdrom_volctrl);
458   unsigned struct_ff_effect_sz = sizeof(struct ff_effect);
459   unsigned struct_floppy_drive_params_sz = sizeof(struct floppy_drive_params);
460   unsigned struct_floppy_drive_struct_sz = sizeof(struct floppy_drive_struct);
461   unsigned struct_floppy_fdc_state_sz = sizeof(struct floppy_fdc_state);
462   unsigned struct_floppy_max_errors_sz = sizeof(struct floppy_max_errors);
463   unsigned struct_floppy_raw_cmd_sz = sizeof(struct floppy_raw_cmd);
464   unsigned struct_floppy_struct_sz = sizeof(struct floppy_struct);
465   unsigned struct_floppy_write_errors_sz = sizeof(struct floppy_write_errors);
466   unsigned struct_format_descr_sz = sizeof(struct format_descr);
467   unsigned struct_hd_driveid_sz = sizeof(struct hd_driveid);
468   unsigned struct_hd_geometry_sz = sizeof(struct hd_geometry);
469   unsigned struct_input_absinfo_sz = sizeof(struct input_absinfo);
470   unsigned struct_input_id_sz = sizeof(struct input_id);
471   unsigned struct_mtpos_sz = sizeof(struct mtpos);
472   unsigned struct_rtentry_sz = sizeof(struct rtentry);
473 #if SANITIZER_GLIBC || SANITIZER_ANDROID
474   unsigned struct_termio_sz = sizeof(struct termio);
475 #endif
476   unsigned struct_vt_consize_sz = sizeof(struct vt_consize);
477   unsigned struct_vt_sizes_sz = sizeof(struct vt_sizes);
478   unsigned struct_vt_stat_sz = sizeof(struct vt_stat);
479 #endif // SANITIZER_LINUX
480 
481 #if SANITIZER_LINUX
482 #if SOUND_VERSION >= 0x040000
483   unsigned struct_copr_buffer_sz = 0;
484   unsigned struct_copr_debug_buf_sz = 0;
485   unsigned struct_copr_msg_sz = 0;
486 #else
487   unsigned struct_copr_buffer_sz = sizeof(struct copr_buffer);
488   unsigned struct_copr_debug_buf_sz = sizeof(struct copr_debug_buf);
489   unsigned struct_copr_msg_sz = sizeof(struct copr_msg);
490 #endif
491   unsigned struct_midi_info_sz = sizeof(struct midi_info);
492   unsigned struct_mtget_sz = sizeof(struct mtget);
493   unsigned struct_mtop_sz = sizeof(struct mtop);
494   unsigned struct_sbi_instrument_sz = sizeof(struct sbi_instrument);
495   unsigned struct_seq_event_rec_sz = sizeof(struct seq_event_rec);
496   unsigned struct_synth_info_sz = sizeof(struct synth_info);
497   unsigned struct_vt_mode_sz = sizeof(struct vt_mode);
498 #endif // SANITIZER_LINUX
499 
500 #if SANITIZER_GLIBC
501   unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct);
502 #if EV_VERSION > (0x010000)
503   unsigned struct_input_keymap_entry_sz = sizeof(struct input_keymap_entry);
504 #else
505   unsigned struct_input_keymap_entry_sz = 0;
506 #endif
507   unsigned struct_ipx_config_data_sz = sizeof(struct ipx_config_data);
508   unsigned struct_kbdiacrs_sz = sizeof(struct kbdiacrs);
509   unsigned struct_kbentry_sz = sizeof(struct kbentry);
510   unsigned struct_kbkeycode_sz = sizeof(struct kbkeycode);
511   unsigned struct_kbsentry_sz = sizeof(struct kbsentry);
512   unsigned struct_mtconfiginfo_sz = sizeof(struct mtconfiginfo);
513   unsigned struct_nr_parms_struct_sz = sizeof(struct nr_parms_struct);
514   unsigned struct_scc_modem_sz = sizeof(struct scc_modem);
515   unsigned struct_scc_stat_sz = sizeof(struct scc_stat);
516   unsigned struct_serial_multiport_struct_sz
517       = sizeof(struct serial_multiport_struct);
518   unsigned struct_serial_struct_sz = sizeof(struct serial_struct);
519   unsigned struct_sockaddr_ax25_sz = sizeof(struct sockaddr_ax25);
520   unsigned struct_unimapdesc_sz = sizeof(struct unimapdesc);
521   unsigned struct_unimapinit_sz = sizeof(struct unimapinit);
522 
523   unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info);
524   unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats);
525 #endif  // SANITIZER_GLIBC
526 
527 #if !SANITIZER_ANDROID && !SANITIZER_APPLE
528   unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req);
529   unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
530 #endif
531 
532   const unsigned long __sanitizer_bufsiz = BUFSIZ;
533 
534   const unsigned IOCTL_NOT_PRESENT = 0;
535 
536   unsigned IOCTL_FIOASYNC = FIOASYNC;
537   unsigned IOCTL_FIOCLEX = FIOCLEX;
538   unsigned IOCTL_FIOGETOWN = FIOGETOWN;
539   unsigned IOCTL_FIONBIO = FIONBIO;
540   unsigned IOCTL_FIONCLEX = FIONCLEX;
541   unsigned IOCTL_FIOSETOWN = FIOSETOWN;
542   unsigned IOCTL_SIOCADDMULTI = SIOCADDMULTI;
543   unsigned IOCTL_SIOCATMARK = SIOCATMARK;
544   unsigned IOCTL_SIOCDELMULTI = SIOCDELMULTI;
545   unsigned IOCTL_SIOCGIFADDR = SIOCGIFADDR;
546   unsigned IOCTL_SIOCGIFBRDADDR = SIOCGIFBRDADDR;
547   unsigned IOCTL_SIOCGIFCONF = SIOCGIFCONF;
548   unsigned IOCTL_SIOCGIFDSTADDR = SIOCGIFDSTADDR;
549   unsigned IOCTL_SIOCGIFFLAGS = SIOCGIFFLAGS;
550   unsigned IOCTL_SIOCGIFMETRIC = SIOCGIFMETRIC;
551   unsigned IOCTL_SIOCGIFMTU = SIOCGIFMTU;
552   unsigned IOCTL_SIOCGIFNETMASK = SIOCGIFNETMASK;
553   unsigned IOCTL_SIOCGPGRP = SIOCGPGRP;
554   unsigned IOCTL_SIOCSIFADDR = SIOCSIFADDR;
555   unsigned IOCTL_SIOCSIFBRDADDR = SIOCSIFBRDADDR;
556   unsigned IOCTL_SIOCSIFDSTADDR = SIOCSIFDSTADDR;
557   unsigned IOCTL_SIOCSIFFLAGS = SIOCSIFFLAGS;
558   unsigned IOCTL_SIOCSIFMETRIC = SIOCSIFMETRIC;
559   unsigned IOCTL_SIOCSIFMTU = SIOCSIFMTU;
560   unsigned IOCTL_SIOCSIFNETMASK = SIOCSIFNETMASK;
561   unsigned IOCTL_SIOCSPGRP = SIOCSPGRP;
562   unsigned IOCTL_TIOCCONS = TIOCCONS;
563   unsigned IOCTL_TIOCEXCL = TIOCEXCL;
564   unsigned IOCTL_TIOCGETD = TIOCGETD;
565   unsigned IOCTL_TIOCGPGRP = TIOCGPGRP;
566   unsigned IOCTL_TIOCGWINSZ = TIOCGWINSZ;
567   unsigned IOCTL_TIOCMBIC = TIOCMBIC;
568   unsigned IOCTL_TIOCMBIS = TIOCMBIS;
569   unsigned IOCTL_TIOCMGET = TIOCMGET;
570   unsigned IOCTL_TIOCMSET = TIOCMSET;
571   unsigned IOCTL_TIOCNOTTY = TIOCNOTTY;
572   unsigned IOCTL_TIOCNXCL = TIOCNXCL;
573   unsigned IOCTL_TIOCOUTQ = TIOCOUTQ;
574   unsigned IOCTL_TIOCPKT = TIOCPKT;
575   unsigned IOCTL_TIOCSCTTY = TIOCSCTTY;
576   unsigned IOCTL_TIOCSETD = TIOCSETD;
577   unsigned IOCTL_TIOCSPGRP = TIOCSPGRP;
578   unsigned IOCTL_TIOCSTI = TIOCSTI;
579   unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ;
580 #if SANITIZER_LINUX && !SANITIZER_ANDROID
581   unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT;
582   unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT;
583 #endif
584 
585 #if SANITIZER_LINUX
586   unsigned IOCTL_EVIOCGABS = EVIOCGABS(0);
587   unsigned IOCTL_EVIOCGBIT = EVIOCGBIT(0, 0);
588   unsigned IOCTL_EVIOCGEFFECTS = EVIOCGEFFECTS;
589   unsigned IOCTL_EVIOCGID = EVIOCGID;
590   unsigned IOCTL_EVIOCGKEY = EVIOCGKEY(0);
591   unsigned IOCTL_EVIOCGKEYCODE = EVIOCGKEYCODE;
592   unsigned IOCTL_EVIOCGLED = EVIOCGLED(0);
593   unsigned IOCTL_EVIOCGNAME = EVIOCGNAME(0);
594   unsigned IOCTL_EVIOCGPHYS = EVIOCGPHYS(0);
595   unsigned IOCTL_EVIOCGRAB = EVIOCGRAB;
596   unsigned IOCTL_EVIOCGREP = EVIOCGREP;
597   unsigned IOCTL_EVIOCGSND = EVIOCGSND(0);
598   unsigned IOCTL_EVIOCGSW = EVIOCGSW(0);
599   unsigned IOCTL_EVIOCGUNIQ = EVIOCGUNIQ(0);
600   unsigned IOCTL_EVIOCGVERSION = EVIOCGVERSION;
601   unsigned IOCTL_EVIOCRMFF = EVIOCRMFF;
602   unsigned IOCTL_EVIOCSABS = EVIOCSABS(0);
603   unsigned IOCTL_EVIOCSFF = EVIOCSFF;
604   unsigned IOCTL_EVIOCSKEYCODE = EVIOCSKEYCODE;
605   unsigned IOCTL_EVIOCSREP = EVIOCSREP;
606   unsigned IOCTL_BLKFLSBUF = BLKFLSBUF;
607   unsigned IOCTL_BLKGETSIZE = BLKGETSIZE;
608   unsigned IOCTL_BLKRAGET = BLKRAGET;
609   unsigned IOCTL_BLKRASET = BLKRASET;
610   unsigned IOCTL_BLKROGET = BLKROGET;
611   unsigned IOCTL_BLKROSET = BLKROSET;
612   unsigned IOCTL_BLKRRPART = BLKRRPART;
613   unsigned IOCTL_BLKFRASET = BLKFRASET;
614   unsigned IOCTL_BLKFRAGET = BLKFRAGET;
615   unsigned IOCTL_BLKSECTSET = BLKSECTSET;
616   unsigned IOCTL_BLKSECTGET = BLKSECTGET;
617   unsigned IOCTL_BLKSSZGET = BLKSSZGET;
618   unsigned IOCTL_BLKBSZGET = BLKBSZGET;
619   unsigned IOCTL_BLKBSZSET = BLKBSZSET;
620   unsigned IOCTL_BLKGETSIZE64 = BLKGETSIZE64;
621   unsigned IOCTL_CDROMAUDIOBUFSIZ = CDROMAUDIOBUFSIZ;
622   unsigned IOCTL_CDROMEJECT = CDROMEJECT;
623   unsigned IOCTL_CDROMEJECT_SW = CDROMEJECT_SW;
624   unsigned IOCTL_CDROMMULTISESSION = CDROMMULTISESSION;
625   unsigned IOCTL_CDROMPAUSE = CDROMPAUSE;
626   unsigned IOCTL_CDROMPLAYMSF = CDROMPLAYMSF;
627   unsigned IOCTL_CDROMPLAYTRKIND = CDROMPLAYTRKIND;
628   unsigned IOCTL_CDROMREADAUDIO = CDROMREADAUDIO;
629   unsigned IOCTL_CDROMREADCOOKED = CDROMREADCOOKED;
630   unsigned IOCTL_CDROMREADMODE1 = CDROMREADMODE1;
631   unsigned IOCTL_CDROMREADMODE2 = CDROMREADMODE2;
632   unsigned IOCTL_CDROMREADRAW = CDROMREADRAW;
633   unsigned IOCTL_CDROMREADTOCENTRY = CDROMREADTOCENTRY;
634   unsigned IOCTL_CDROMREADTOCHDR = CDROMREADTOCHDR;
635   unsigned IOCTL_CDROMRESET = CDROMRESET;
636   unsigned IOCTL_CDROMRESUME = CDROMRESUME;
637   unsigned IOCTL_CDROMSEEK = CDROMSEEK;
638   unsigned IOCTL_CDROMSTART = CDROMSTART;
639   unsigned IOCTL_CDROMSTOP = CDROMSTOP;
640   unsigned IOCTL_CDROMSUBCHNL = CDROMSUBCHNL;
641   unsigned IOCTL_CDROMVOLCTRL = CDROMVOLCTRL;
642   unsigned IOCTL_CDROMVOLREAD = CDROMVOLREAD;
643   unsigned IOCTL_CDROM_GET_UPC = CDROM_GET_UPC;
644   unsigned IOCTL_FDCLRPRM = FDCLRPRM;
645   unsigned IOCTL_FDDEFPRM = FDDEFPRM;
646   unsigned IOCTL_FDFLUSH = FDFLUSH;
647   unsigned IOCTL_FDFMTBEG = FDFMTBEG;
648   unsigned IOCTL_FDFMTEND = FDFMTEND;
649   unsigned IOCTL_FDFMTTRK = FDFMTTRK;
650   unsigned IOCTL_FDGETDRVPRM = FDGETDRVPRM;
651   unsigned IOCTL_FDGETDRVSTAT = FDGETDRVSTAT;
652   unsigned IOCTL_FDGETDRVTYP = FDGETDRVTYP;
653   unsigned IOCTL_FDGETFDCSTAT = FDGETFDCSTAT;
654   unsigned IOCTL_FDGETMAXERRS = FDGETMAXERRS;
655   unsigned IOCTL_FDGETPRM = FDGETPRM;
656   unsigned IOCTL_FDMSGOFF = FDMSGOFF;
657   unsigned IOCTL_FDMSGON = FDMSGON;
658   unsigned IOCTL_FDPOLLDRVSTAT = FDPOLLDRVSTAT;
659   unsigned IOCTL_FDRAWCMD = FDRAWCMD;
660   unsigned IOCTL_FDRESET = FDRESET;
661   unsigned IOCTL_FDSETDRVPRM = FDSETDRVPRM;
662   unsigned IOCTL_FDSETEMSGTRESH = FDSETEMSGTRESH;
663   unsigned IOCTL_FDSETMAXERRS = FDSETMAXERRS;
664   unsigned IOCTL_FDSETPRM = FDSETPRM;
665   unsigned IOCTL_FDTWADDLE = FDTWADDLE;
666   unsigned IOCTL_FDWERRORCLR = FDWERRORCLR;
667   unsigned IOCTL_FDWERRORGET = FDWERRORGET;
668   unsigned IOCTL_HDIO_DRIVE_CMD = HDIO_DRIVE_CMD;
669   unsigned IOCTL_HDIO_GETGEO = HDIO_GETGEO;
670   unsigned IOCTL_HDIO_GET_32BIT = HDIO_GET_32BIT;
671   unsigned IOCTL_HDIO_GET_DMA = HDIO_GET_DMA;
672   unsigned IOCTL_HDIO_GET_IDENTITY = HDIO_GET_IDENTITY;
673   unsigned IOCTL_HDIO_GET_KEEPSETTINGS = HDIO_GET_KEEPSETTINGS;
674   unsigned IOCTL_HDIO_GET_MULTCOUNT = HDIO_GET_MULTCOUNT;
675   unsigned IOCTL_HDIO_GET_NOWERR = HDIO_GET_NOWERR;
676   unsigned IOCTL_HDIO_GET_UNMASKINTR = HDIO_GET_UNMASKINTR;
677   unsigned IOCTL_HDIO_SET_32BIT = HDIO_SET_32BIT;
678   unsigned IOCTL_HDIO_SET_DMA = HDIO_SET_DMA;
679   unsigned IOCTL_HDIO_SET_KEEPSETTINGS = HDIO_SET_KEEPSETTINGS;
680   unsigned IOCTL_HDIO_SET_MULTCOUNT = HDIO_SET_MULTCOUNT;
681   unsigned IOCTL_HDIO_SET_NOWERR = HDIO_SET_NOWERR;
682   unsigned IOCTL_HDIO_SET_UNMASKINTR = HDIO_SET_UNMASKINTR;
683   unsigned IOCTL_MTIOCPOS = MTIOCPOS;
684   unsigned IOCTL_PPPIOCGASYNCMAP = PPPIOCGASYNCMAP;
685   unsigned IOCTL_PPPIOCGDEBUG = PPPIOCGDEBUG;
686   unsigned IOCTL_PPPIOCGFLAGS = PPPIOCGFLAGS;
687   unsigned IOCTL_PPPIOCGUNIT = PPPIOCGUNIT;
688   unsigned IOCTL_PPPIOCGXASYNCMAP = PPPIOCGXASYNCMAP;
689   unsigned IOCTL_PPPIOCSASYNCMAP = PPPIOCSASYNCMAP;
690   unsigned IOCTL_PPPIOCSDEBUG = PPPIOCSDEBUG;
691   unsigned IOCTL_PPPIOCSFLAGS = PPPIOCSFLAGS;
692   unsigned IOCTL_PPPIOCSMAXCID = PPPIOCSMAXCID;
693   unsigned IOCTL_PPPIOCSMRU = PPPIOCSMRU;
694   unsigned IOCTL_PPPIOCSXASYNCMAP = PPPIOCSXASYNCMAP;
695   unsigned IOCTL_SIOCADDRT = SIOCADDRT;
696   unsigned IOCTL_SIOCDARP = SIOCDARP;
697   unsigned IOCTL_SIOCDELRT = SIOCDELRT;
698   unsigned IOCTL_SIOCDRARP = SIOCDRARP;
699   unsigned IOCTL_SIOCGARP = SIOCGARP;
700   unsigned IOCTL_SIOCGIFENCAP = SIOCGIFENCAP;
701   unsigned IOCTL_SIOCGIFHWADDR = SIOCGIFHWADDR;
702   unsigned IOCTL_SIOCGIFMAP = SIOCGIFMAP;
703   unsigned IOCTL_SIOCGIFMEM = SIOCGIFMEM;
704   unsigned IOCTL_SIOCGIFNAME = SIOCGIFNAME;
705   unsigned IOCTL_SIOCGIFSLAVE = SIOCGIFSLAVE;
706   unsigned IOCTL_SIOCGRARP = SIOCGRARP;
707   unsigned IOCTL_SIOCGSTAMP = SIOCGSTAMP;
708   unsigned IOCTL_SIOCSARP = SIOCSARP;
709   unsigned IOCTL_SIOCSIFENCAP = SIOCSIFENCAP;
710   unsigned IOCTL_SIOCSIFHWADDR = SIOCSIFHWADDR;
711   unsigned IOCTL_SIOCSIFLINK = SIOCSIFLINK;
712   unsigned IOCTL_SIOCSIFMAP = SIOCSIFMAP;
713   unsigned IOCTL_SIOCSIFMEM = SIOCSIFMEM;
714   unsigned IOCTL_SIOCSIFSLAVE = SIOCSIFSLAVE;
715   unsigned IOCTL_SIOCSRARP = SIOCSRARP;
716 # if SOUND_VERSION >= 0x040000
717   unsigned IOCTL_SNDCTL_COPR_HALT = IOCTL_NOT_PRESENT;
718   unsigned IOCTL_SNDCTL_COPR_LOAD = IOCTL_NOT_PRESENT;
719   unsigned IOCTL_SNDCTL_COPR_RCODE = IOCTL_NOT_PRESENT;
720   unsigned IOCTL_SNDCTL_COPR_RCVMSG = IOCTL_NOT_PRESENT;
721   unsigned IOCTL_SNDCTL_COPR_RDATA = IOCTL_NOT_PRESENT;
722   unsigned IOCTL_SNDCTL_COPR_RESET = IOCTL_NOT_PRESENT;
723   unsigned IOCTL_SNDCTL_COPR_RUN = IOCTL_NOT_PRESENT;
724   unsigned IOCTL_SNDCTL_COPR_SENDMSG = IOCTL_NOT_PRESENT;
725   unsigned IOCTL_SNDCTL_COPR_WCODE = IOCTL_NOT_PRESENT;
726   unsigned IOCTL_SNDCTL_COPR_WDATA = IOCTL_NOT_PRESENT;
727   unsigned IOCTL_SOUND_PCM_READ_BITS = IOCTL_NOT_PRESENT;
728   unsigned IOCTL_SOUND_PCM_READ_CHANNELS = IOCTL_NOT_PRESENT;
729   unsigned IOCTL_SOUND_PCM_READ_FILTER = IOCTL_NOT_PRESENT;
730   unsigned IOCTL_SOUND_PCM_READ_RATE = IOCTL_NOT_PRESENT;
731   unsigned IOCTL_SOUND_PCM_WRITE_CHANNELS = IOCTL_NOT_PRESENT;
732   unsigned IOCTL_SOUND_PCM_WRITE_FILTER = IOCTL_NOT_PRESENT;
733 # else  // SOUND_VERSION
734   unsigned IOCTL_SNDCTL_COPR_HALT = SNDCTL_COPR_HALT;
735   unsigned IOCTL_SNDCTL_COPR_LOAD = SNDCTL_COPR_LOAD;
736   unsigned IOCTL_SNDCTL_COPR_RCODE = SNDCTL_COPR_RCODE;
737   unsigned IOCTL_SNDCTL_COPR_RCVMSG = SNDCTL_COPR_RCVMSG;
738   unsigned IOCTL_SNDCTL_COPR_RDATA = SNDCTL_COPR_RDATA;
739   unsigned IOCTL_SNDCTL_COPR_RESET = SNDCTL_COPR_RESET;
740   unsigned IOCTL_SNDCTL_COPR_RUN = SNDCTL_COPR_RUN;
741   unsigned IOCTL_SNDCTL_COPR_SENDMSG = SNDCTL_COPR_SENDMSG;
742   unsigned IOCTL_SNDCTL_COPR_WCODE = SNDCTL_COPR_WCODE;
743   unsigned IOCTL_SNDCTL_COPR_WDATA = SNDCTL_COPR_WDATA;
744   unsigned IOCTL_SOUND_PCM_READ_BITS = SOUND_PCM_READ_BITS;
745   unsigned IOCTL_SOUND_PCM_READ_CHANNELS = SOUND_PCM_READ_CHANNELS;
746   unsigned IOCTL_SOUND_PCM_READ_FILTER = SOUND_PCM_READ_FILTER;
747   unsigned IOCTL_SOUND_PCM_READ_RATE = SOUND_PCM_READ_RATE;
748   unsigned IOCTL_SOUND_PCM_WRITE_CHANNELS = SOUND_PCM_WRITE_CHANNELS;
749   unsigned IOCTL_SOUND_PCM_WRITE_FILTER = SOUND_PCM_WRITE_FILTER;
750 #endif // SOUND_VERSION
751   unsigned IOCTL_TCFLSH = TCFLSH;
752   unsigned IOCTL_TCGETA = TCGETA;
753   unsigned IOCTL_TCGETS = TCGETS;
754   unsigned IOCTL_TCSBRK = TCSBRK;
755   unsigned IOCTL_TCSBRKP = TCSBRKP;
756   unsigned IOCTL_TCSETA = TCSETA;
757   unsigned IOCTL_TCSETAF = TCSETAF;
758   unsigned IOCTL_TCSETAW = TCSETAW;
759   unsigned IOCTL_TCSETS = TCSETS;
760   unsigned IOCTL_TCSETSF = TCSETSF;
761   unsigned IOCTL_TCSETSW = TCSETSW;
762   unsigned IOCTL_TCXONC = TCXONC;
763   unsigned IOCTL_TIOCGLCKTRMIOS = TIOCGLCKTRMIOS;
764   unsigned IOCTL_TIOCGSOFTCAR = TIOCGSOFTCAR;
765   unsigned IOCTL_TIOCINQ = TIOCINQ;
766   unsigned IOCTL_TIOCLINUX = TIOCLINUX;
767   unsigned IOCTL_TIOCSERCONFIG = TIOCSERCONFIG;
768   unsigned IOCTL_TIOCSERGETLSR = TIOCSERGETLSR;
769   unsigned IOCTL_TIOCSERGWILD = TIOCSERGWILD;
770   unsigned IOCTL_TIOCSERSWILD = TIOCSERSWILD;
771   unsigned IOCTL_TIOCSLCKTRMIOS = TIOCSLCKTRMIOS;
772   unsigned IOCTL_TIOCSSOFTCAR = TIOCSSOFTCAR;
773   unsigned IOCTL_VT_DISALLOCATE = VT_DISALLOCATE;
774   unsigned IOCTL_VT_GETSTATE = VT_GETSTATE;
775   unsigned IOCTL_VT_RESIZE = VT_RESIZE;
776   unsigned IOCTL_VT_RESIZEX = VT_RESIZEX;
777   unsigned IOCTL_VT_SENDSIG = VT_SENDSIG;
778   unsigned IOCTL_MTIOCGET = MTIOCGET;
779   unsigned IOCTL_MTIOCTOP = MTIOCTOP;
780   unsigned IOCTL_SNDCTL_DSP_GETBLKSIZE = SNDCTL_DSP_GETBLKSIZE;
781   unsigned IOCTL_SNDCTL_DSP_GETFMTS = SNDCTL_DSP_GETFMTS;
782   unsigned IOCTL_SNDCTL_DSP_NONBLOCK = SNDCTL_DSP_NONBLOCK;
783   unsigned IOCTL_SNDCTL_DSP_POST = SNDCTL_DSP_POST;
784   unsigned IOCTL_SNDCTL_DSP_RESET = SNDCTL_DSP_RESET;
785   unsigned IOCTL_SNDCTL_DSP_SETFMT = SNDCTL_DSP_SETFMT;
786   unsigned IOCTL_SNDCTL_DSP_SETFRAGMENT = SNDCTL_DSP_SETFRAGMENT;
787   unsigned IOCTL_SNDCTL_DSP_SPEED = SNDCTL_DSP_SPEED;
788   unsigned IOCTL_SNDCTL_DSP_STEREO = SNDCTL_DSP_STEREO;
789   unsigned IOCTL_SNDCTL_DSP_SUBDIVIDE = SNDCTL_DSP_SUBDIVIDE;
790   unsigned IOCTL_SNDCTL_DSP_SYNC = SNDCTL_DSP_SYNC;
791   unsigned IOCTL_SNDCTL_FM_4OP_ENABLE = SNDCTL_FM_4OP_ENABLE;
792   unsigned IOCTL_SNDCTL_FM_LOAD_INSTR = SNDCTL_FM_LOAD_INSTR;
793   unsigned IOCTL_SNDCTL_MIDI_INFO = SNDCTL_MIDI_INFO;
794   unsigned IOCTL_SNDCTL_MIDI_PRETIME = SNDCTL_MIDI_PRETIME;
795   unsigned IOCTL_SNDCTL_SEQ_CTRLRATE = SNDCTL_SEQ_CTRLRATE;
796   unsigned IOCTL_SNDCTL_SEQ_GETINCOUNT = SNDCTL_SEQ_GETINCOUNT;
797   unsigned IOCTL_SNDCTL_SEQ_GETOUTCOUNT = SNDCTL_SEQ_GETOUTCOUNT;
798   unsigned IOCTL_SNDCTL_SEQ_NRMIDIS = SNDCTL_SEQ_NRMIDIS;
799   unsigned IOCTL_SNDCTL_SEQ_NRSYNTHS = SNDCTL_SEQ_NRSYNTHS;
800   unsigned IOCTL_SNDCTL_SEQ_OUTOFBAND = SNDCTL_SEQ_OUTOFBAND;
801   unsigned IOCTL_SNDCTL_SEQ_PANIC = SNDCTL_SEQ_PANIC;
802   unsigned IOCTL_SNDCTL_SEQ_PERCMODE = SNDCTL_SEQ_PERCMODE;
803   unsigned IOCTL_SNDCTL_SEQ_RESET = SNDCTL_SEQ_RESET;
804   unsigned IOCTL_SNDCTL_SEQ_RESETSAMPLES = SNDCTL_SEQ_RESETSAMPLES;
805   unsigned IOCTL_SNDCTL_SEQ_SYNC = SNDCTL_SEQ_SYNC;
806   unsigned IOCTL_SNDCTL_SEQ_TESTMIDI = SNDCTL_SEQ_TESTMIDI;
807   unsigned IOCTL_SNDCTL_SEQ_THRESHOLD = SNDCTL_SEQ_THRESHOLD;
808   unsigned IOCTL_SNDCTL_SYNTH_INFO = SNDCTL_SYNTH_INFO;
809   unsigned IOCTL_SNDCTL_SYNTH_MEMAVL = SNDCTL_SYNTH_MEMAVL;
810   unsigned IOCTL_SNDCTL_TMR_CONTINUE = SNDCTL_TMR_CONTINUE;
811   unsigned IOCTL_SNDCTL_TMR_METRONOME = SNDCTL_TMR_METRONOME;
812   unsigned IOCTL_SNDCTL_TMR_SELECT = SNDCTL_TMR_SELECT;
813   unsigned IOCTL_SNDCTL_TMR_SOURCE = SNDCTL_TMR_SOURCE;
814   unsigned IOCTL_SNDCTL_TMR_START = SNDCTL_TMR_START;
815   unsigned IOCTL_SNDCTL_TMR_STOP = SNDCTL_TMR_STOP;
816   unsigned IOCTL_SNDCTL_TMR_TEMPO = SNDCTL_TMR_TEMPO;
817   unsigned IOCTL_SNDCTL_TMR_TIMEBASE = SNDCTL_TMR_TIMEBASE;
818   unsigned IOCTL_SOUND_MIXER_READ_ALTPCM = SOUND_MIXER_READ_ALTPCM;
819   unsigned IOCTL_SOUND_MIXER_READ_BASS = SOUND_MIXER_READ_BASS;
820   unsigned IOCTL_SOUND_MIXER_READ_CAPS = SOUND_MIXER_READ_CAPS;
821   unsigned IOCTL_SOUND_MIXER_READ_CD = SOUND_MIXER_READ_CD;
822   unsigned IOCTL_SOUND_MIXER_READ_DEVMASK = SOUND_MIXER_READ_DEVMASK;
823   unsigned IOCTL_SOUND_MIXER_READ_ENHANCE = SOUND_MIXER_READ_ENHANCE;
824   unsigned IOCTL_SOUND_MIXER_READ_IGAIN = SOUND_MIXER_READ_IGAIN;
825   unsigned IOCTL_SOUND_MIXER_READ_IMIX = SOUND_MIXER_READ_IMIX;
826   unsigned IOCTL_SOUND_MIXER_READ_LINE = SOUND_MIXER_READ_LINE;
827   unsigned IOCTL_SOUND_MIXER_READ_LINE1 = SOUND_MIXER_READ_LINE1;
828   unsigned IOCTL_SOUND_MIXER_READ_LINE2 = SOUND_MIXER_READ_LINE2;
829   unsigned IOCTL_SOUND_MIXER_READ_LINE3 = SOUND_MIXER_READ_LINE3;
830   unsigned IOCTL_SOUND_MIXER_READ_LOUD = SOUND_MIXER_READ_LOUD;
831   unsigned IOCTL_SOUND_MIXER_READ_MIC = SOUND_MIXER_READ_MIC;
832   unsigned IOCTL_SOUND_MIXER_READ_MUTE = SOUND_MIXER_READ_MUTE;
833   unsigned IOCTL_SOUND_MIXER_READ_OGAIN = SOUND_MIXER_READ_OGAIN;
834   unsigned IOCTL_SOUND_MIXER_READ_PCM = SOUND_MIXER_READ_PCM;
835   unsigned IOCTL_SOUND_MIXER_READ_RECLEV = SOUND_MIXER_READ_RECLEV;
836   unsigned IOCTL_SOUND_MIXER_READ_RECMASK = SOUND_MIXER_READ_RECMASK;
837   unsigned IOCTL_SOUND_MIXER_READ_RECSRC = SOUND_MIXER_READ_RECSRC;
838   unsigned IOCTL_SOUND_MIXER_READ_SPEAKER = SOUND_MIXER_READ_SPEAKER;
839   unsigned IOCTL_SOUND_MIXER_READ_STEREODEVS = SOUND_MIXER_READ_STEREODEVS;
840   unsigned IOCTL_SOUND_MIXER_READ_SYNTH = SOUND_MIXER_READ_SYNTH;
841   unsigned IOCTL_SOUND_MIXER_READ_TREBLE = SOUND_MIXER_READ_TREBLE;
842   unsigned IOCTL_SOUND_MIXER_READ_VOLUME = SOUND_MIXER_READ_VOLUME;
843   unsigned IOCTL_SOUND_MIXER_WRITE_ALTPCM = SOUND_MIXER_WRITE_ALTPCM;
844   unsigned IOCTL_SOUND_MIXER_WRITE_BASS = SOUND_MIXER_WRITE_BASS;
845   unsigned IOCTL_SOUND_MIXER_WRITE_CD = SOUND_MIXER_WRITE_CD;
846   unsigned IOCTL_SOUND_MIXER_WRITE_ENHANCE = SOUND_MIXER_WRITE_ENHANCE;
847   unsigned IOCTL_SOUND_MIXER_WRITE_IGAIN = SOUND_MIXER_WRITE_IGAIN;
848   unsigned IOCTL_SOUND_MIXER_WRITE_IMIX = SOUND_MIXER_WRITE_IMIX;
849   unsigned IOCTL_SOUND_MIXER_WRITE_LINE = SOUND_MIXER_WRITE_LINE;
850   unsigned IOCTL_SOUND_MIXER_WRITE_LINE1 = SOUND_MIXER_WRITE_LINE1;
851   unsigned IOCTL_SOUND_MIXER_WRITE_LINE2 = SOUND_MIXER_WRITE_LINE2;
852   unsigned IOCTL_SOUND_MIXER_WRITE_LINE3 = SOUND_MIXER_WRITE_LINE3;
853   unsigned IOCTL_SOUND_MIXER_WRITE_LOUD = SOUND_MIXER_WRITE_LOUD;
854   unsigned IOCTL_SOUND_MIXER_WRITE_MIC = SOUND_MIXER_WRITE_MIC;
855   unsigned IOCTL_SOUND_MIXER_WRITE_MUTE = SOUND_MIXER_WRITE_MUTE;
856   unsigned IOCTL_SOUND_MIXER_WRITE_OGAIN = SOUND_MIXER_WRITE_OGAIN;
857   unsigned IOCTL_SOUND_MIXER_WRITE_PCM = SOUND_MIXER_WRITE_PCM;
858   unsigned IOCTL_SOUND_MIXER_WRITE_RECLEV = SOUND_MIXER_WRITE_RECLEV;
859   unsigned IOCTL_SOUND_MIXER_WRITE_RECSRC = SOUND_MIXER_WRITE_RECSRC;
860   unsigned IOCTL_SOUND_MIXER_WRITE_SPEAKER = SOUND_MIXER_WRITE_SPEAKER;
861   unsigned IOCTL_SOUND_MIXER_WRITE_SYNTH = SOUND_MIXER_WRITE_SYNTH;
862   unsigned IOCTL_SOUND_MIXER_WRITE_TREBLE = SOUND_MIXER_WRITE_TREBLE;
863   unsigned IOCTL_SOUND_MIXER_WRITE_VOLUME = SOUND_MIXER_WRITE_VOLUME;
864   unsigned IOCTL_VT_ACTIVATE = VT_ACTIVATE;
865   unsigned IOCTL_VT_GETMODE = VT_GETMODE;
866   unsigned IOCTL_VT_OPENQRY = VT_OPENQRY;
867   unsigned IOCTL_VT_RELDISP = VT_RELDISP;
868   unsigned IOCTL_VT_SETMODE = VT_SETMODE;
869   unsigned IOCTL_VT_WAITACTIVE = VT_WAITACTIVE;
870 #endif // SANITIZER_LINUX
871 
872 #if SANITIZER_LINUX && !SANITIZER_ANDROID
873   unsigned IOCTL_EQL_EMANCIPATE = EQL_EMANCIPATE;
874   unsigned IOCTL_EQL_ENSLAVE = EQL_ENSLAVE;
875   unsigned IOCTL_EQL_GETMASTRCFG = EQL_GETMASTRCFG;
876   unsigned IOCTL_EQL_GETSLAVECFG = EQL_GETSLAVECFG;
877   unsigned IOCTL_EQL_SETMASTRCFG = EQL_SETMASTRCFG;
878   unsigned IOCTL_EQL_SETSLAVECFG = EQL_SETSLAVECFG;
879 #if EV_VERSION > (0x010000)
880   unsigned IOCTL_EVIOCGKEYCODE_V2 = EVIOCGKEYCODE_V2;
881   unsigned IOCTL_EVIOCGPROP = EVIOCGPROP(0);
882   unsigned IOCTL_EVIOCSKEYCODE_V2 = EVIOCSKEYCODE_V2;
883 #else
884   unsigned IOCTL_EVIOCGKEYCODE_V2 = IOCTL_NOT_PRESENT;
885   unsigned IOCTL_EVIOCGPROP = IOCTL_NOT_PRESENT;
886   unsigned IOCTL_EVIOCSKEYCODE_V2 = IOCTL_NOT_PRESENT;
887 #endif
888   unsigned IOCTL_FS_IOC_GETFLAGS = _IOR('f', 1, long);
889   unsigned IOCTL_FS_IOC_GETVERSION = _IOR('v', 1, long);
890   unsigned IOCTL_FS_IOC_SETFLAGS = _IOW('f', 2, long);
891   unsigned IOCTL_FS_IOC_SETVERSION = _IOW('v', 2, long);
892   unsigned IOCTL_GIO_CMAP = GIO_CMAP;
893   unsigned IOCTL_GIO_FONT = GIO_FONT;
894   unsigned IOCTL_GIO_UNIMAP = GIO_UNIMAP;
895   unsigned IOCTL_GIO_UNISCRNMAP = GIO_UNISCRNMAP;
896   unsigned IOCTL_KDADDIO = KDADDIO;
897   unsigned IOCTL_KDDELIO = KDDELIO;
898   unsigned IOCTL_KDGETKEYCODE = KDGETKEYCODE;
899   unsigned IOCTL_KDGKBDIACR = KDGKBDIACR;
900   unsigned IOCTL_KDGKBENT = KDGKBENT;
901   unsigned IOCTL_KDGKBLED = KDGKBLED;
902   unsigned IOCTL_KDGKBMETA = KDGKBMETA;
903   unsigned IOCTL_KDGKBSENT = KDGKBSENT;
904   unsigned IOCTL_KDMAPDISP = KDMAPDISP;
905   unsigned IOCTL_KDSETKEYCODE = KDSETKEYCODE;
906   unsigned IOCTL_KDSIGACCEPT = KDSIGACCEPT;
907   unsigned IOCTL_KDSKBDIACR = KDSKBDIACR;
908   unsigned IOCTL_KDSKBENT = KDSKBENT;
909   unsigned IOCTL_KDSKBLED = KDSKBLED;
910   unsigned IOCTL_KDSKBMETA = KDSKBMETA;
911   unsigned IOCTL_KDSKBSENT = KDSKBSENT;
912   unsigned IOCTL_KDUNMAPDISP = KDUNMAPDISP;
913   unsigned IOCTL_LPABORT = LPABORT;
914   unsigned IOCTL_LPABORTOPEN = LPABORTOPEN;
915   unsigned IOCTL_LPCAREFUL = LPCAREFUL;
916   unsigned IOCTL_LPCHAR = LPCHAR;
917   unsigned IOCTL_LPGETIRQ = LPGETIRQ;
918   unsigned IOCTL_LPGETSTATUS = LPGETSTATUS;
919   unsigned IOCTL_LPRESET = LPRESET;
920   unsigned IOCTL_LPSETIRQ = LPSETIRQ;
921   unsigned IOCTL_LPTIME = LPTIME;
922   unsigned IOCTL_LPWAIT = LPWAIT;
923   unsigned IOCTL_MTIOCGETCONFIG = MTIOCGETCONFIG;
924   unsigned IOCTL_MTIOCSETCONFIG = MTIOCSETCONFIG;
925   unsigned IOCTL_PIO_CMAP = PIO_CMAP;
926   unsigned IOCTL_PIO_FONT = PIO_FONT;
927   unsigned IOCTL_PIO_UNIMAP = PIO_UNIMAP;
928   unsigned IOCTL_PIO_UNIMAPCLR = PIO_UNIMAPCLR;
929   unsigned IOCTL_PIO_UNISCRNMAP = PIO_UNISCRNMAP;
930 #if SANITIZER_GLIBC
931   unsigned IOCTL_SCSI_IOCTL_GET_IDLUN = SCSI_IOCTL_GET_IDLUN;
932   unsigned IOCTL_SCSI_IOCTL_PROBE_HOST = SCSI_IOCTL_PROBE_HOST;
933   unsigned IOCTL_SCSI_IOCTL_TAGGED_DISABLE = SCSI_IOCTL_TAGGED_DISABLE;
934   unsigned IOCTL_SCSI_IOCTL_TAGGED_ENABLE = SCSI_IOCTL_TAGGED_ENABLE;
935   unsigned IOCTL_SIOCAIPXITFCRT = SIOCAIPXITFCRT;
936   unsigned IOCTL_SIOCAIPXPRISLT = SIOCAIPXPRISLT;
937   unsigned IOCTL_SIOCAX25ADDUID = SIOCAX25ADDUID;
938   unsigned IOCTL_SIOCAX25DELUID = SIOCAX25DELUID;
939   unsigned IOCTL_SIOCAX25GETPARMS = SIOCAX25GETPARMS;
940   unsigned IOCTL_SIOCAX25GETUID = SIOCAX25GETUID;
941   unsigned IOCTL_SIOCAX25NOUID = SIOCAX25NOUID;
942   unsigned IOCTL_SIOCAX25SETPARMS = SIOCAX25SETPARMS;
943   unsigned IOCTL_SIOCDEVPLIP = SIOCDEVPLIP;
944   unsigned IOCTL_SIOCIPXCFGDATA = SIOCIPXCFGDATA;
945   unsigned IOCTL_SIOCNRDECOBS = SIOCNRDECOBS;
946   unsigned IOCTL_SIOCNRGETPARMS = SIOCNRGETPARMS;
947   unsigned IOCTL_SIOCNRRTCTL = SIOCNRRTCTL;
948   unsigned IOCTL_SIOCNRSETPARMS = SIOCNRSETPARMS;
949 #endif
950   unsigned IOCTL_TIOCGSERIAL = TIOCGSERIAL;
951   unsigned IOCTL_TIOCSERGETMULTI = TIOCSERGETMULTI;
952   unsigned IOCTL_TIOCSERSETMULTI = TIOCSERSETMULTI;
953   unsigned IOCTL_TIOCSSERIAL = TIOCSSERIAL;
954 #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
955 
956 #if SANITIZER_LINUX && !SANITIZER_ANDROID
957   unsigned IOCTL_GIO_SCRNMAP = GIO_SCRNMAP;
958   unsigned IOCTL_KDDISABIO = KDDISABIO;
959   unsigned IOCTL_KDENABIO = KDENABIO;
960   unsigned IOCTL_KDGETLED = KDGETLED;
961   unsigned IOCTL_KDGETMODE = KDGETMODE;
962   unsigned IOCTL_KDGKBMODE = KDGKBMODE;
963   unsigned IOCTL_KDGKBTYPE = KDGKBTYPE;
964   unsigned IOCTL_KDMKTONE = KDMKTONE;
965   unsigned IOCTL_KDSETLED = KDSETLED;
966   unsigned IOCTL_KDSETMODE = KDSETMODE;
967   unsigned IOCTL_KDSKBMODE = KDSKBMODE;
968   unsigned IOCTL_KIOCSOUND = KIOCSOUND;
969   unsigned IOCTL_PIO_SCRNMAP = PIO_SCRNMAP;
970   unsigned IOCTL_SNDCTL_DSP_GETISPACE = SNDCTL_DSP_GETISPACE;
971   unsigned IOCTL_SNDCTL_DSP_GETOSPACE = SNDCTL_DSP_GETOSPACE;
972 #endif // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
973 
974   const int si_SEGV_MAPERR = SEGV_MAPERR;
975   const int si_SEGV_ACCERR = SEGV_ACCERR;
976 } // namespace __sanitizer
977 
978 using namespace __sanitizer;
979 
980 COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
981 
982 COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
983 CHECK_TYPE_SIZE(pthread_key_t);
984 
985 #if SANITIZER_LINUX
986 // FIXME: We define those on Linux and Mac, but only check on Linux.
987 COMPILER_CHECK(IOC_NRBITS == _IOC_NRBITS);
988 COMPILER_CHECK(IOC_TYPEBITS == _IOC_TYPEBITS);
989 COMPILER_CHECK(IOC_SIZEBITS == _IOC_SIZEBITS);
990 COMPILER_CHECK(IOC_DIRBITS == _IOC_DIRBITS);
991 COMPILER_CHECK(IOC_NRMASK == _IOC_NRMASK);
992 COMPILER_CHECK(IOC_TYPEMASK == _IOC_TYPEMASK);
993 COMPILER_CHECK(IOC_SIZEMASK == _IOC_SIZEMASK);
994 COMPILER_CHECK(IOC_DIRMASK == _IOC_DIRMASK);
995 COMPILER_CHECK(IOC_NRSHIFT == _IOC_NRSHIFT);
996 COMPILER_CHECK(IOC_TYPESHIFT == _IOC_TYPESHIFT);
997 COMPILER_CHECK(IOC_SIZESHIFT == _IOC_SIZESHIFT);
998 COMPILER_CHECK(IOC_DIRSHIFT == _IOC_DIRSHIFT);
999 COMPILER_CHECK(IOC_NONE == _IOC_NONE);
1000 COMPILER_CHECK(IOC_WRITE == _IOC_WRITE);
1001 COMPILER_CHECK(IOC_READ == _IOC_READ);
1002 COMPILER_CHECK(EVIOC_ABS_MAX == ABS_MAX);
1003 COMPILER_CHECK(EVIOC_EV_MAX == EV_MAX);
1004 COMPILER_CHECK(IOC_SIZE(0x12345678) == _IOC_SIZE(0x12345678));
1005 COMPILER_CHECK(IOC_DIR(0x12345678) == _IOC_DIR(0x12345678));
1006 COMPILER_CHECK(IOC_NR(0x12345678) == _IOC_NR(0x12345678));
1007 COMPILER_CHECK(IOC_TYPE(0x12345678) == _IOC_TYPE(0x12345678));
1008 #endif // SANITIZER_LINUX
1009 
1010 #if SANITIZER_LINUX || SANITIZER_FREEBSD
1011 // There are more undocumented fields in dl_phdr_info that we are not interested
1012 // in.
1013 COMPILER_CHECK(sizeof(__sanitizer_dl_phdr_info) <= sizeof(dl_phdr_info));
1014 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr);
1015 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
1016 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
1017 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
1018 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD
1019 
1020 #if SANITIZER_GLIBC || SANITIZER_FREEBSD
1021 CHECK_TYPE_SIZE(glob_t);
1022 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
1023 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
1024 CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
1025 CHECK_SIZE_AND_OFFSET(glob_t, gl_flags);
1026 CHECK_SIZE_AND_OFFSET(glob_t, gl_closedir);
1027 CHECK_SIZE_AND_OFFSET(glob_t, gl_readdir);
1028 CHECK_SIZE_AND_OFFSET(glob_t, gl_opendir);
1029 CHECK_SIZE_AND_OFFSET(glob_t, gl_lstat);
1030 CHECK_SIZE_AND_OFFSET(glob_t, gl_stat);
1031 #endif  // SANITIZER_GLIBC || SANITIZER_FREEBSD
1032 
1033 CHECK_TYPE_SIZE(addrinfo);
1034 CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags);
1035 CHECK_SIZE_AND_OFFSET(addrinfo, ai_family);
1036 CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype);
1037 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
1038 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
1039 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen);
1040 CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname);
1041 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr);
1042 
1043 CHECK_TYPE_SIZE(hostent);
1044 CHECK_SIZE_AND_OFFSET(hostent, h_name);
1045 CHECK_SIZE_AND_OFFSET(hostent, h_aliases);
1046 CHECK_SIZE_AND_OFFSET(hostent, h_addrtype);
1047 CHECK_SIZE_AND_OFFSET(hostent, h_length);
1048 CHECK_SIZE_AND_OFFSET(hostent, h_addr_list);
1049 
1050 CHECK_TYPE_SIZE(iovec);
1051 CHECK_SIZE_AND_OFFSET(iovec, iov_base);
1052 CHECK_SIZE_AND_OFFSET(iovec, iov_len);
1053 
1054 // In POSIX, int msg_iovlen; socklen_t msg_controllen; socklen_t cmsg_len; but
1055 // many implementations don't conform to the standard. Since we pick the
1056 // non-conforming glibc definition, exclude the checks for musl (incompatible
1057 // sizes but compatible offsets).
1058 CHECK_TYPE_SIZE(msghdr);
1059 CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
1060 CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
1061 CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
1062 #if SANITIZER_GLIBC || SANITIZER_ANDROID
1063 CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
1064 #endif
1065 CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
1066 #if SANITIZER_GLIBC || SANITIZER_ANDROID
1067 CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
1068 #endif
1069 CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
1070 
1071 CHECK_TYPE_SIZE(cmsghdr);
1072 #if SANITIZER_GLIBC || SANITIZER_ANDROID
1073 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
1074 #endif
1075 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
1076 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
1077 
1078 #if SANITIZER_LINUX && (__ANDROID_API__ >= 21 || __GLIBC_PREREQ (2, 14))
1079 CHECK_TYPE_SIZE(mmsghdr);
1080 CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr);
1081 CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);
1082 #endif
1083 
1084 COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
1085 CHECK_SIZE_AND_OFFSET(dirent, d_ino);
1086 #if SANITIZER_APPLE
1087 CHECK_SIZE_AND_OFFSET(dirent, d_seekoff);
1088 #elif SANITIZER_FREEBSD
1089 // There is no 'd_off' field on FreeBSD.
1090 #else
1091 CHECK_SIZE_AND_OFFSET(dirent, d_off);
1092 #endif
1093 CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
1094 
1095 #if SANITIZER_GLIBC
1096 COMPILER_CHECK(sizeof(__sanitizer_dirent64) <= sizeof(dirent64));
1097 CHECK_SIZE_AND_OFFSET(dirent64, d_ino);
1098 CHECK_SIZE_AND_OFFSET(dirent64, d_off);
1099 CHECK_SIZE_AND_OFFSET(dirent64, d_reclen);
1100 #endif
1101 
1102 CHECK_TYPE_SIZE(ifconf);
1103 CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
1104 CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
1105 
1106 CHECK_TYPE_SIZE(pollfd);
1107 CHECK_SIZE_AND_OFFSET(pollfd, fd);
1108 CHECK_SIZE_AND_OFFSET(pollfd, events);
1109 CHECK_SIZE_AND_OFFSET(pollfd, revents);
1110 
1111 CHECK_TYPE_SIZE(nfds_t);
1112 
1113 CHECK_TYPE_SIZE(sigset_t);
1114 
1115 COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction));
1116 // Can't write checks for sa_handler and sa_sigaction due to them being
1117 // preprocessor macros.
1118 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
1119 #if !defined(__s390x__) || __GLIBC_PREREQ (2, 20)
1120 // On s390x glibc 2.19 and earlier sa_flags was unsigned long, and sa_resv
1121 // didn't exist.
1122 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_flags);
1123 #endif
1124 #if SANITIZER_LINUX && (!SANITIZER_ANDROID || !SANITIZER_MIPS32)
1125 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_restorer);
1126 #endif
1127 
1128 #if SANITIZER_HAS_SIGINFO
1129 COMPILER_CHECK(alignof(siginfo_t) == alignof(__sanitizer_siginfo));
1130 using __sanitizer_siginfo_t = __sanitizer_siginfo;
1131 CHECK_TYPE_SIZE(siginfo_t);
1132 CHECK_SIZE_AND_OFFSET(siginfo_t, si_signo);
1133 CHECK_SIZE_AND_OFFSET(siginfo_t, si_errno);
1134 CHECK_SIZE_AND_OFFSET(siginfo_t, si_code);
1135 #endif
1136 
1137 #if SANITIZER_LINUX
1138 CHECK_TYPE_SIZE(__sysctl_args);
1139 CHECK_SIZE_AND_OFFSET(__sysctl_args, name);
1140 CHECK_SIZE_AND_OFFSET(__sysctl_args, nlen);
1141 CHECK_SIZE_AND_OFFSET(__sysctl_args, oldval);
1142 CHECK_SIZE_AND_OFFSET(__sysctl_args, oldlenp);
1143 CHECK_SIZE_AND_OFFSET(__sysctl_args, newval);
1144 CHECK_SIZE_AND_OFFSET(__sysctl_args, newlen);
1145 
1146 CHECK_TYPE_SIZE(__kernel_uid_t);
1147 CHECK_TYPE_SIZE(__kernel_gid_t);
1148 
1149 #if SANITIZER_USES_UID16_SYSCALLS
1150 CHECK_TYPE_SIZE(__kernel_old_uid_t);
1151 CHECK_TYPE_SIZE(__kernel_old_gid_t);
1152 #endif
1153 
1154 CHECK_TYPE_SIZE(__kernel_off_t);
1155 CHECK_TYPE_SIZE(__kernel_loff_t);
1156 CHECK_TYPE_SIZE(__kernel_fd_set);
1157 #endif
1158 
1159 #if !SANITIZER_ANDROID
1160 CHECK_TYPE_SIZE(wordexp_t);
1161 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
1162 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
1163 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
1164 #endif
1165 
1166 CHECK_TYPE_SIZE(tm);
1167 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
1168 CHECK_SIZE_AND_OFFSET(tm, tm_min);
1169 CHECK_SIZE_AND_OFFSET(tm, tm_hour);
1170 CHECK_SIZE_AND_OFFSET(tm, tm_mday);
1171 CHECK_SIZE_AND_OFFSET(tm, tm_mon);
1172 CHECK_SIZE_AND_OFFSET(tm, tm_year);
1173 CHECK_SIZE_AND_OFFSET(tm, tm_wday);
1174 CHECK_SIZE_AND_OFFSET(tm, tm_yday);
1175 CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
1176 CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff);
1177 CHECK_SIZE_AND_OFFSET(tm, tm_zone);
1178 
1179 #if SANITIZER_LINUX
1180 CHECK_TYPE_SIZE(mntent);
1181 CHECK_SIZE_AND_OFFSET(mntent, mnt_fsname);
1182 CHECK_SIZE_AND_OFFSET(mntent, mnt_dir);
1183 CHECK_SIZE_AND_OFFSET(mntent, mnt_type);
1184 CHECK_SIZE_AND_OFFSET(mntent, mnt_opts);
1185 CHECK_SIZE_AND_OFFSET(mntent, mnt_freq);
1186 CHECK_SIZE_AND_OFFSET(mntent, mnt_passno);
1187 #endif
1188 
1189 CHECK_TYPE_SIZE(ether_addr);
1190 
1191 #if SANITIZER_GLIBC || SANITIZER_FREEBSD
1192 CHECK_TYPE_SIZE(ipc_perm);
1193 # if SANITIZER_FREEBSD
1194 CHECK_SIZE_AND_OFFSET(ipc_perm, key);
1195 CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
1196 # else
1197 CHECK_SIZE_AND_OFFSET(ipc_perm, __key);
1198 CHECK_SIZE_AND_OFFSET(ipc_perm, __seq);
1199 # endif
1200 CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
1201 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
1202 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
1203 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
1204 #if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
1205 /* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit
1206    on many architectures.  */
1207 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
1208 #endif
1209 
1210 CHECK_TYPE_SIZE(shmid_ds);
1211 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);
1212 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz);
1213 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime);
1214 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime);
1215 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime);
1216 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid);
1217 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
1218 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
1219 #endif
1220 
1221 CHECK_TYPE_SIZE(clock_t);
1222 
1223 #if SANITIZER_LINUX
1224 CHECK_TYPE_SIZE(clockid_t);
1225 #endif
1226 
1227 #if !SANITIZER_ANDROID
1228 CHECK_TYPE_SIZE(ifaddrs);
1229 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
1230 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
1231 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
1232 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask);
1233 #if SANITIZER_LINUX || SANITIZER_FREEBSD
1234 // Compare against the union, because we can't reach into the union in a
1235 // compliant way.
1236 #ifdef ifa_dstaddr
1237 #undef ifa_dstaddr
1238 #endif
1239 # if SANITIZER_FREEBSD
1240 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
1241 # else
1242 COMPILER_CHECK(sizeof(((__sanitizer_ifaddrs *)nullptr)->ifa_dstaddr) ==
1243                sizeof(((ifaddrs *)nullptr)->ifa_ifu));
1244 COMPILER_CHECK(offsetof(__sanitizer_ifaddrs, ifa_dstaddr) ==
1245                offsetof(ifaddrs, ifa_ifu));
1246 # endif // SANITIZER_FREEBSD
1247 #else
1248 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr);
1249 #endif // SANITIZER_LINUX
1250 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
1251 #endif
1252 
1253 #if SANITIZER_GLIBC || SANITIZER_ANDROID
1254 COMPILER_CHECK(sizeof(__sanitizer_struct_mallinfo) == sizeof(struct mallinfo));
1255 #endif
1256 
1257 #if !SANITIZER_ANDROID
1258 CHECK_TYPE_SIZE(timeb);
1259 CHECK_SIZE_AND_OFFSET(timeb, time);
1260 CHECK_SIZE_AND_OFFSET(timeb, millitm);
1261 CHECK_SIZE_AND_OFFSET(timeb, timezone);
1262 CHECK_SIZE_AND_OFFSET(timeb, dstflag);
1263 #endif
1264 
1265 CHECK_TYPE_SIZE(passwd);
1266 CHECK_SIZE_AND_OFFSET(passwd, pw_name);
1267 CHECK_SIZE_AND_OFFSET(passwd, pw_passwd);
1268 CHECK_SIZE_AND_OFFSET(passwd, pw_uid);
1269 CHECK_SIZE_AND_OFFSET(passwd, pw_gid);
1270 CHECK_SIZE_AND_OFFSET(passwd, pw_dir);
1271 CHECK_SIZE_AND_OFFSET(passwd, pw_shell);
1272 
1273 #if !SANITIZER_ANDROID
1274 CHECK_SIZE_AND_OFFSET(passwd, pw_gecos);
1275 #endif
1276 
1277 #if SANITIZER_APPLE
1278 CHECK_SIZE_AND_OFFSET(passwd, pw_change);
1279 CHECK_SIZE_AND_OFFSET(passwd, pw_expire);
1280 CHECK_SIZE_AND_OFFSET(passwd, pw_class);
1281 #endif
1282 
1283 
1284 CHECK_TYPE_SIZE(group);
1285 CHECK_SIZE_AND_OFFSET(group, gr_name);
1286 CHECK_SIZE_AND_OFFSET(group, gr_passwd);
1287 CHECK_SIZE_AND_OFFSET(group, gr_gid);
1288 CHECK_SIZE_AND_OFFSET(group, gr_mem);
1289 
1290 #if HAVE_RPC_XDR_H && !SANITIZER_APPLE
1291 CHECK_TYPE_SIZE(XDR);
1292 CHECK_SIZE_AND_OFFSET(XDR, x_op);
1293 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
1294 CHECK_SIZE_AND_OFFSET(XDR, x_public);
1295 CHECK_SIZE_AND_OFFSET(XDR, x_private);
1296 CHECK_SIZE_AND_OFFSET(XDR, x_base);
1297 CHECK_SIZE_AND_OFFSET(XDR, x_handy);
1298 COMPILER_CHECK(__sanitizer_XDR_ENCODE == XDR_ENCODE);
1299 COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE);
1300 COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
1301 #endif
1302 
1303 #if SANITIZER_GLIBC
1304 COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
1305 CHECK_SIZE_AND_OFFSET(FILE, _flags);
1306 CHECK_SIZE_AND_OFFSET(FILE, _IO_read_ptr);
1307 CHECK_SIZE_AND_OFFSET(FILE, _IO_read_end);
1308 CHECK_SIZE_AND_OFFSET(FILE, _IO_read_base);
1309 CHECK_SIZE_AND_OFFSET(FILE, _IO_write_ptr);
1310 CHECK_SIZE_AND_OFFSET(FILE, _IO_write_end);
1311 CHECK_SIZE_AND_OFFSET(FILE, _IO_write_base);
1312 CHECK_SIZE_AND_OFFSET(FILE, _IO_buf_base);
1313 CHECK_SIZE_AND_OFFSET(FILE, _IO_buf_end);
1314 CHECK_SIZE_AND_OFFSET(FILE, _IO_save_base);
1315 CHECK_SIZE_AND_OFFSET(FILE, _IO_backup_base);
1316 CHECK_SIZE_AND_OFFSET(FILE, _IO_save_end);
1317 CHECK_SIZE_AND_OFFSET(FILE, _markers);
1318 CHECK_SIZE_AND_OFFSET(FILE, _chain);
1319 CHECK_SIZE_AND_OFFSET(FILE, _fileno);
1320 
1321 COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk));
1322 CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit);
1323 CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev);
1324 CHECK_TYPE_SIZE(obstack);
1325 CHECK_SIZE_AND_OFFSET(obstack, chunk_size);
1326 CHECK_SIZE_AND_OFFSET(obstack, chunk);
1327 CHECK_SIZE_AND_OFFSET(obstack, object_base);
1328 CHECK_SIZE_AND_OFFSET(obstack, next_free);
1329 
1330 CHECK_TYPE_SIZE(cookie_io_functions_t);
1331 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, read);
1332 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, write);
1333 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, seek);
1334 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, close);
1335 #endif  // SANITIZER_GLIBC
1336 
1337 #if SANITIZER_LINUX || SANITIZER_FREEBSD
1338 CHECK_TYPE_SIZE(sem_t);
1339 #endif
1340 
1341 #if SANITIZER_LINUX && defined(__arm__)
1342 COMPILER_CHECK(ARM_VFPREGS_SIZE == ARM_VFPREGS_SIZE_ASAN);
1343 #endif
1344 
1345 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_APPLE
1346