1 //===-- sanitizer_platform_limits_posix.h ---------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of Sanitizer common code.
11 //
12 // Sizes and layouts of platform-specific POSIX data structures.
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef SANITIZER_PLATFORM_LIMITS_POSIX_H
16 #define SANITIZER_PLATFORM_LIMITS_POSIX_H
17 
18 #include "sanitizer_internal_defs.h"
19 #include "sanitizer_platform.h"
20 
21 #if SANITIZER_FREEBSD
22 // FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
23 // incroporates the map structure.
24 # define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
25     ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 544)))
26 #else
27 # define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) ((link_map*)(handle))
28 #endif  // !SANITIZER_FREEBSD
29 
30 namespace __sanitizer {
31   extern unsigned struct_utsname_sz;
32   extern unsigned struct_stat_sz;
33 #if !SANITIZER_FREEBSD && !SANITIZER_IOS
34   extern unsigned struct_stat64_sz;
35 #endif
36   extern unsigned struct_rusage_sz;
37   extern unsigned siginfo_t_sz;
38   extern unsigned struct_itimerval_sz;
39   extern unsigned pthread_t_sz;
40   extern unsigned pthread_cond_t_sz;
41   extern unsigned pid_t_sz;
42   extern unsigned timeval_sz;
43   extern unsigned uid_t_sz;
44   extern unsigned gid_t_sz;
45   extern unsigned mbstate_t_sz;
46   extern unsigned struct_timezone_sz;
47   extern unsigned struct_tms_sz;
48   extern unsigned struct_itimerspec_sz;
49   extern unsigned struct_sigevent_sz;
50   extern unsigned struct_sched_param_sz;
51   extern unsigned struct_statfs64_sz;
52 
53 #if !SANITIZER_ANDROID
54   extern unsigned struct_statfs_sz;
55   extern unsigned struct_sockaddr_sz;
56   extern unsigned ucontext_t_sz;
57 #endif // !SANITIZER_ANDROID
58 
59 #if SANITIZER_LINUX
60 
61 #if defined(__x86_64__)
62   const unsigned struct_kernel_stat_sz = 144;
63   const unsigned struct_kernel_stat64_sz = 0;
64 #elif defined(__i386__)
65   const unsigned struct_kernel_stat_sz = 64;
66   const unsigned struct_kernel_stat64_sz = 96;
67 #elif defined(__arm__)
68   const unsigned struct_kernel_stat_sz = 64;
69   const unsigned struct_kernel_stat64_sz = 104;
70 #elif defined(__aarch64__)
71   const unsigned struct_kernel_stat_sz = 128;
72   const unsigned struct_kernel_stat64_sz = 104;
73 #elif defined(__powerpc__) && !defined(__powerpc64__)
74   const unsigned struct_kernel_stat_sz = 72;
75   const unsigned struct_kernel_stat64_sz = 104;
76 #elif defined(__powerpc64__)
77   const unsigned struct_kernel_stat_sz = 144;
78   const unsigned struct_kernel_stat64_sz = 104;
79 #elif defined(__mips__)
80   #if SANITIZER_WORDSIZE == 64
81   const unsigned struct_kernel_stat_sz = 216;
82   #else
83   const unsigned struct_kernel_stat_sz = 144;
84   #endif
85   const unsigned struct_kernel_stat64_sz = 104;
86 #endif
87   struct __sanitizer_perf_event_attr {
88     unsigned type;
89     unsigned size;
90     // More fields that vary with the kernel version.
91   };
92 
93   extern unsigned struct_epoll_event_sz;
94   extern unsigned struct_sysinfo_sz;
95   extern unsigned __user_cap_header_struct_sz;
96   extern unsigned __user_cap_data_struct_sz;
97   extern unsigned struct_new_utsname_sz;
98   extern unsigned struct_old_utsname_sz;
99   extern unsigned struct_oldold_utsname_sz;
100 
101   const unsigned struct_kexec_segment_sz = 4 * sizeof(unsigned long);
102 #endif  // SANITIZER_LINUX
103 
104 #if SANITIZER_LINUX || SANITIZER_FREEBSD
105 
106 #if defined(__powerpc64__)
107   const unsigned struct___old_kernel_stat_sz = 0;
108 #else
109   const unsigned struct___old_kernel_stat_sz = 32;
110 #endif
111 
112   extern unsigned struct_rlimit_sz;
113   extern unsigned struct_utimbuf_sz;
114   extern unsigned struct_timespec_sz;
115 
116   struct __sanitizer_iocb {
117     u64   aio_data;
118     u32   aio_key_or_aio_reserved1; // Simply crazy.
119     u32   aio_reserved1_or_aio_key; // Luckily, we don't need these.
120     u16   aio_lio_opcode;
121     s16   aio_reqprio;
122     u32   aio_fildes;
123     u64   aio_buf;
124     u64   aio_nbytes;
125     s64   aio_offset;
126     u64   aio_reserved2;
127     u64   aio_reserved3;
128   };
129 
130   struct __sanitizer_io_event {
131     u64 data;
132     u64 obj;
133     u64 res;
134     u64 res2;
135   };
136 
137   const unsigned iocb_cmd_pread = 0;
138   const unsigned iocb_cmd_pwrite = 1;
139   const unsigned iocb_cmd_preadv = 7;
140   const unsigned iocb_cmd_pwritev = 8;
141 
142   struct __sanitizer___sysctl_args {
143     int *name;
144     int nlen;
145     void *oldval;
146     uptr *oldlenp;
147     void *newval;
148     uptr newlen;
149     unsigned long ___unused[4];
150   };
151 
152   const unsigned old_sigset_t_sz = sizeof(unsigned long);
153 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD
154 
155 #if SANITIZER_ANDROID
156   struct __sanitizer_mallinfo {
157     uptr v[10];
158   };
159 #endif
160 
161 #if SANITIZER_LINUX && !SANITIZER_ANDROID
162   struct __sanitizer_mallinfo {
163     int v[10];
164   };
165 
166   extern unsigned struct_ustat_sz;
167   extern unsigned struct_rlimit64_sz;
168   extern unsigned struct_statvfs64_sz;
169 
170   struct __sanitizer_ipc_perm {
171     int __key;
172     int uid;
173     int gid;
174     int cuid;
175     int cgid;
176 #ifdef __powerpc__
177     unsigned mode;
178     unsigned __seq;
179     u64 __unused1;
180     u64 __unused2;
181 #elif defined(__mips__) || defined(__aarch64__)
182     unsigned int mode;
183     unsigned short __seq;
184     unsigned short __pad1;
185     unsigned long __unused1;
186     unsigned long __unused2;
187 #else
188     unsigned short mode;
189     unsigned short __pad1;
190     unsigned short __seq;
191     unsigned short __pad2;
192 #if defined(__x86_64__) && !defined(_LP64)
193     u64 __unused1;
194     u64 __unused2;
195 #else
196     unsigned long __unused1;
197     unsigned long __unused2;
198 #endif
199 #endif
200   };
201 
202   struct __sanitizer_shmid_ds {
203     __sanitizer_ipc_perm shm_perm;
204   #ifndef __powerpc__
205     uptr shm_segsz;
206   #elif !defined(__powerpc64__)
207     uptr __unused0;
208   #endif
209   #if defined(__x86_64__) && !defined(_LP64)
210     u64 shm_atime;
211     u64 shm_dtime;
212     u64 shm_ctime;
213   #else
214     uptr shm_atime;
215   #if !defined(_LP64) && !defined(__mips__)
216     uptr __unused1;
217   #endif
218     uptr shm_dtime;
219   #if !defined(_LP64) && !defined(__mips__)
220     uptr __unused2;
221   #endif
222     uptr shm_ctime;
223   #if !defined(_LP64) && !defined(__mips__)
224     uptr __unused3;
225   #endif
226   #endif
227   #ifdef __powerpc__
228     uptr shm_segsz;
229   #endif
230     int shm_cpid;
231     int shm_lpid;
232   #if defined(__x86_64__) && !defined(_LP64)
233     u64 shm_nattch;
234     u64 __unused4;
235     u64 __unused5;
236   #else
237     uptr shm_nattch;
238     uptr __unused4;
239     uptr __unused5;
240   #endif
241   };
242 #elif SANITIZER_FREEBSD
243   struct __sanitizer_ipc_perm {
244     unsigned int cuid;
245     unsigned int cgid;
246     unsigned int uid;
247     unsigned int gid;
248     unsigned short mode;
249     unsigned short seq;
250     long key;
251   };
252 
253   struct __sanitizer_shmid_ds {
254     __sanitizer_ipc_perm shm_perm;
255     unsigned long shm_segsz;
256     unsigned int shm_lpid;
257     unsigned int shm_cpid;
258     int shm_nattch;
259     unsigned long shm_atime;
260     unsigned long shm_dtime;
261     unsigned long shm_ctime;
262   };
263 #endif
264 
265 #if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
266   extern unsigned struct_msqid_ds_sz;
267   extern unsigned struct_mq_attr_sz;
268   extern unsigned struct_timex_sz;
269   extern unsigned struct_statvfs_sz;
270 #endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
271 
272   struct __sanitizer_iovec {
273     void *iov_base;
274     uptr iov_len;
275   };
276 
277 #if !SANITIZER_ANDROID
278   struct __sanitizer_ifaddrs {
279     struct __sanitizer_ifaddrs *ifa_next;
280     char *ifa_name;
281     unsigned int ifa_flags;
282     void *ifa_addr;    // (struct sockaddr *)
283     void *ifa_netmask; // (struct sockaddr *)
284     // This is a union on Linux.
285 # ifdef ifa_dstaddr
286 # undef ifa_dstaddr
287 # endif
288     void *ifa_dstaddr; // (struct sockaddr *)
289     void *ifa_data;
290   };
291 #endif  // !SANITIZER_ANDROID
292 
293 #if SANITIZER_MAC
294   typedef unsigned long __sanitizer_pthread_key_t;
295 #else
296   typedef unsigned __sanitizer_pthread_key_t;
297 #endif
298 
299 #if SANITIZER_LINUX && !SANITIZER_ANDROID
300 
301   struct __sanitizer_XDR {
302     int x_op;
303     void *x_ops;
304     uptr x_public;
305     uptr x_private;
306     uptr x_base;
307     unsigned x_handy;
308   };
309 
310   const int __sanitizer_XDR_ENCODE = 0;
311   const int __sanitizer_XDR_DECODE = 1;
312   const int __sanitizer_XDR_FREE = 2;
313 #endif
314 
315   struct __sanitizer_passwd {
316     char *pw_name;
317     char *pw_passwd;
318     int pw_uid;
319     int pw_gid;
320 #if SANITIZER_MAC || SANITIZER_FREEBSD
321     long pw_change;
322     char *pw_class;
323 #endif
324 #if !SANITIZER_ANDROID
325     char *pw_gecos;
326 #endif
327     char *pw_dir;
328     char *pw_shell;
329 #if SANITIZER_MAC || SANITIZER_FREEBSD
330     long pw_expire;
331 #endif
332 #if SANITIZER_FREEBSD
333     int pw_fields;
334 #endif
335   };
336 
337   struct __sanitizer_group {
338     char *gr_name;
339     char *gr_passwd;
340     int gr_gid;
341     char **gr_mem;
342   };
343 
344 #if defined(__x86_64__) && !defined(_LP64)
345   typedef long long __sanitizer_time_t;
346 #else
347   typedef long __sanitizer_time_t;
348 #endif
349 
350   struct __sanitizer_timeb {
351     __sanitizer_time_t time;
352     unsigned short millitm;
353     short timezone;
354     short dstflag;
355   };
356 
357   struct __sanitizer_ether_addr {
358     u8 octet[6];
359   };
360 
361   struct __sanitizer_tm {
362     int tm_sec;
363     int tm_min;
364     int tm_hour;
365     int tm_mday;
366     int tm_mon;
367     int tm_year;
368     int tm_wday;
369     int tm_yday;
370     int tm_isdst;
371     long int tm_gmtoff;
372     const char *tm_zone;
373   };
374 
375 #if SANITIZER_LINUX
376   struct __sanitizer_mntent {
377     char *mnt_fsname;
378     char *mnt_dir;
379     char *mnt_type;
380     char *mnt_opts;
381     int mnt_freq;
382     int mnt_passno;
383   };
384 #endif
385 
386 #if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD
387   struct __sanitizer_msghdr {
388     void *msg_name;
389     unsigned msg_namelen;
390     struct __sanitizer_iovec *msg_iov;
391     unsigned msg_iovlen;
392     void *msg_control;
393     unsigned msg_controllen;
394     int msg_flags;
395   };
396   struct __sanitizer_cmsghdr {
397     unsigned cmsg_len;
398     int cmsg_level;
399     int cmsg_type;
400   };
401 #else
402   struct __sanitizer_msghdr {
403     void *msg_name;
404     unsigned msg_namelen;
405     struct __sanitizer_iovec *msg_iov;
406     uptr msg_iovlen;
407     void *msg_control;
408     uptr msg_controllen;
409     int msg_flags;
410   };
411   struct __sanitizer_cmsghdr {
412     uptr cmsg_len;
413     int cmsg_level;
414     int cmsg_type;
415   };
416 #endif
417 
418 #if SANITIZER_MAC
419   struct __sanitizer_dirent {
420     unsigned long long d_ino;
421     unsigned long long d_seekoff;
422     unsigned short d_reclen;
423     // more fields that we don't care about
424   };
425 #elif SANITIZER_FREEBSD
426   struct __sanitizer_dirent {
427     unsigned int d_fileno;
428     unsigned short d_reclen;
429     // more fields that we don't care about
430   };
431 #elif SANITIZER_ANDROID || defined(__x86_64__)
432   struct __sanitizer_dirent {
433     unsigned long long d_ino;
434     unsigned long long d_off;
435     unsigned short d_reclen;
436     // more fields that we don't care about
437   };
438 #else
439   struct __sanitizer_dirent {
440     uptr d_ino;
441     uptr d_off;
442     unsigned short d_reclen;
443     // more fields that we don't care about
444   };
445 #endif
446 
447 #if SANITIZER_LINUX && !SANITIZER_ANDROID
448   struct __sanitizer_dirent64 {
449     unsigned long long d_ino;
450     unsigned long long d_off;
451     unsigned short d_reclen;
452     // more fields that we don't care about
453   };
454 #endif
455 
456 // 'clock_t' is 32 bits wide on x64 FreeBSD
457 #if SANITIZER_FREEBSD
458   typedef int __sanitizer_clock_t;
459 #elif defined(__x86_64__) && !defined(_LP64)
460   typedef long long __sanitizer_clock_t;
461 #else
462   typedef long __sanitizer_clock_t;
463 #endif
464 
465 #if SANITIZER_LINUX
466   typedef int __sanitizer_clockid_t;
467 #endif
468 
469 #if SANITIZER_LINUX || SANITIZER_FREEBSD
470 #if defined(_LP64) || defined(__x86_64__) || defined(__powerpc__)\
471                    || defined(__mips__)
472   typedef unsigned __sanitizer___kernel_uid_t;
473   typedef unsigned __sanitizer___kernel_gid_t;
474 #else
475   typedef unsigned short __sanitizer___kernel_uid_t;
476   typedef unsigned short __sanitizer___kernel_gid_t;
477 #endif
478 #if defined(__x86_64__) && !defined(_LP64)
479   typedef long long __sanitizer___kernel_off_t;
480 #else
481   typedef long __sanitizer___kernel_off_t;
482 #endif
483 
484 #if defined(__powerpc__) || defined(__mips__)
485   typedef unsigned int __sanitizer___kernel_old_uid_t;
486   typedef unsigned int __sanitizer___kernel_old_gid_t;
487 #else
488   typedef unsigned short __sanitizer___kernel_old_uid_t;
489   typedef unsigned short __sanitizer___kernel_old_gid_t;
490 #endif
491 
492   typedef long long __sanitizer___kernel_loff_t;
493   typedef struct {
494     unsigned long fds_bits[1024 / (8 * sizeof(long))];
495   } __sanitizer___kernel_fd_set;
496 #endif
497 
498   // This thing depends on the platform. We are only interested in the upper
499   // limit. Verified with a compiler assert in .cc.
500   const int pthread_attr_t_max_sz = 128;
501   union __sanitizer_pthread_attr_t {
502     char size[pthread_attr_t_max_sz]; // NOLINT
503     void *align;
504   };
505 
506 #if SANITIZER_ANDROID
507   typedef unsigned long __sanitizer_sigset_t;
508 #elif SANITIZER_MAC
509   typedef unsigned __sanitizer_sigset_t;
510 #elif SANITIZER_LINUX
511   struct __sanitizer_sigset_t {
512     // The size is determined by looking at sizeof of real sigset_t on linux.
513     uptr val[128 / sizeof(uptr)];
514   };
515 #elif SANITIZER_FREEBSD
516   struct __sanitizer_sigset_t {
517      // uint32_t * 4
518      unsigned int __bits[4];
519   };
520 #endif
521 
522   // Linux system headers define the 'sa_handler' and 'sa_sigaction' macros.
523   struct __sanitizer_sigaction {
524 #if defined(__mips__) && !SANITIZER_FREEBSD
525     unsigned int sa_flags;
526 #endif
527     union {
528       void (*sigaction)(int sig, void *siginfo, void *uctx);
529       void (*handler)(int sig);
530     };
531 #if SANITIZER_FREEBSD
532     int sa_flags;
533     __sanitizer_sigset_t sa_mask;
534 #else
535     __sanitizer_sigset_t sa_mask;
536 #ifndef __mips__
537     int sa_flags;
538 #endif
539 #endif
540 #if SANITIZER_LINUX
541     void (*sa_restorer)();
542 #endif
543 #if defined(__mips__) && (SANITIZER_WORDSIZE == 32)
544     int sa_resv[1];
545 #endif
546   };
547 
548 #if SANITIZER_FREEBSD
549   typedef __sanitizer_sigset_t __sanitizer_kernel_sigset_t;
550 #elif defined(__mips__)
551   struct __sanitizer_kernel_sigset_t {
552     u8 sig[16];
553   };
554 #else
555   struct __sanitizer_kernel_sigset_t {
556     u8 sig[8];
557   };
558 #endif
559 
560   // Linux system headers define the 'sa_handler' and 'sa_sigaction' macros.
561   struct __sanitizer_kernel_sigaction_t {
562     union {
563       void (*handler)(int signo);
564       void (*sigaction)(int signo, void *info, void *ctx);
565     };
566     unsigned long sa_flags;
567     void (*sa_restorer)(void);
568     __sanitizer_kernel_sigset_t sa_mask;
569   };
570 
571   extern uptr sig_ign;
572   extern uptr sig_dfl;
573   extern uptr sa_siginfo;
574 
575 #if SANITIZER_LINUX
576   extern int e_tabsz;
577 #endif
578 
579   extern int af_inet;
580   extern int af_inet6;
581   uptr __sanitizer_in_addr_sz(int af);
582 
583 #if SANITIZER_LINUX || SANITIZER_FREEBSD
584   struct __sanitizer_dl_phdr_info {
585     uptr dlpi_addr;
586     const char *dlpi_name;
587     const void *dlpi_phdr;
588     short dlpi_phnum;
589   };
590 #endif
591 
592   struct __sanitizer_addrinfo {
593     int ai_flags;
594     int ai_family;
595     int ai_socktype;
596     int ai_protocol;
597 #if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD
598     unsigned ai_addrlen;
599     char *ai_canonname;
600     void *ai_addr;
601 #else // LINUX
602     unsigned ai_addrlen;
603     void *ai_addr;
604     char *ai_canonname;
605 #endif
606     struct __sanitizer_addrinfo *ai_next;
607   };
608 
609   struct __sanitizer_hostent {
610     char *h_name;
611     char **h_aliases;
612     int h_addrtype;
613     int h_length;
614     char **h_addr_list;
615   };
616 
617   struct __sanitizer_pollfd {
618     int fd;
619     short events;
620     short revents;
621   };
622 
623 #if SANITIZER_ANDROID || SANITIZER_MAC || SANITIZER_FREEBSD
624   typedef unsigned __sanitizer_nfds_t;
625 #else
626   typedef unsigned long __sanitizer_nfds_t;
627 #endif
628 
629 #if !SANITIZER_ANDROID
630 # if SANITIZER_LINUX
631   struct __sanitizer_glob_t {
632     uptr gl_pathc;
633     char **gl_pathv;
634     uptr gl_offs;
635     int gl_flags;
636 
637     void (*gl_closedir)(void *dirp);
638     void *(*gl_readdir)(void *dirp);
639     void *(*gl_opendir)(const char *);
640     int (*gl_lstat)(const char *, void *);
641     int (*gl_stat)(const char *, void *);
642   };
643 # elif SANITIZER_FREEBSD
644   struct __sanitizer_glob_t {
645     uptr gl_pathc;
646     uptr gl_matchc;
647     uptr gl_offs;
648     int gl_flags;
649     char **gl_pathv;
650     int (*gl_errfunc)(const char*, int);
651     void (*gl_closedir)(void *dirp);
652     struct dirent *(*gl_readdir)(void *dirp);
653     void *(*gl_opendir)(const char*);
654     int (*gl_lstat)(const char*, void* /* struct stat* */);
655     int (*gl_stat)(const char*, void* /* struct stat* */);
656   };
657 # endif  // SANITIZER_FREEBSD
658 
659 # if SANITIZER_LINUX || SANITIZER_FREEBSD
660   extern int glob_nomatch;
661   extern int glob_altdirfunc;
662 # endif
663 #endif  // !SANITIZER_ANDROID
664 
665   extern unsigned path_max;
666 
667   struct __sanitizer_wordexp_t {
668     uptr we_wordc;
669     char **we_wordv;
670     uptr we_offs;
671 #if SANITIZER_FREEBSD
672     char *we_strings;
673     uptr we_nbytes;
674 #endif
675   };
676 
677 #if SANITIZER_LINUX && !SANITIZER_ANDROID
678   struct __sanitizer_FILE {
679     int _flags;
680     char *_IO_read_ptr;
681     char *_IO_read_end;
682     char *_IO_read_base;
683     char *_IO_write_base;
684     char *_IO_write_ptr;
685     char *_IO_write_end;
686     char *_IO_buf_base;
687     char *_IO_buf_end;
688     char *_IO_save_base;
689     char *_IO_backup_base;
690     char *_IO_save_end;
691     void *_markers;
692     __sanitizer_FILE *_chain;
693     int _fileno;
694   };
695 # define SANITIZER_HAS_STRUCT_FILE 1
696 #else
697   typedef void __sanitizer_FILE;
698 # define SANITIZER_HAS_STRUCT_FILE 0
699 #endif
700 
701 #if SANITIZER_LINUX && !SANITIZER_ANDROID && \
702   (defined(__i386) || defined(__x86_64) || defined(__mips64))
703   extern unsigned struct_user_regs_struct_sz;
704   extern unsigned struct_user_fpregs_struct_sz;
705   extern unsigned struct_user_fpxregs_struct_sz;
706 
707   extern int ptrace_peektext;
708   extern int ptrace_peekdata;
709   extern int ptrace_peekuser;
710   extern int ptrace_getregs;
711   extern int ptrace_setregs;
712   extern int ptrace_getfpregs;
713   extern int ptrace_setfpregs;
714   extern int ptrace_getfpxregs;
715   extern int ptrace_setfpxregs;
716   extern int ptrace_getsiginfo;
717   extern int ptrace_setsiginfo;
718   extern int ptrace_getregset;
719   extern int ptrace_setregset;
720   extern int ptrace_geteventmsg;
721 #endif
722 
723 #if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
724   extern unsigned struct_shminfo_sz;
725   extern unsigned struct_shm_info_sz;
726   extern int shmctl_ipc_stat;
727   extern int shmctl_ipc_info;
728   extern int shmctl_shm_info;
729   extern int shmctl_shm_stat;
730 #endif
731 
732   extern int map_fixed;
733 
734   // ioctl arguments
735   struct __sanitizer_ifconf {
736     int ifc_len;
737     union {
738       void *ifcu_req;
739     } ifc_ifcu;
740 #if SANITIZER_MAC
741   } __attribute__((packed));
742 #else
743   };
744 #endif
745 
746 #if SANITIZER_LINUX && !SANITIZER_ANDROID
747 struct __sanitizer__obstack_chunk {
748   char *limit;
749   struct __sanitizer__obstack_chunk *prev;
750 };
751 
752 struct __sanitizer_obstack {
753   long chunk_size;
754   struct __sanitizer__obstack_chunk *chunk;
755   char *object_base;
756   char *next_free;
757   uptr more_fields[7];
758 };
759 #endif
760 
761 #define IOC_NRBITS 8
762 #define IOC_TYPEBITS 8
763 #if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__)
764 #define IOC_SIZEBITS 13
765 #define IOC_DIRBITS 3
766 #define IOC_NONE 1U
767 #define IOC_WRITE 4U
768 #define IOC_READ 2U
769 #else
770 #define IOC_SIZEBITS 14
771 #define IOC_DIRBITS 2
772 #define IOC_NONE 0U
773 #define IOC_WRITE 1U
774 #define IOC_READ 2U
775 #endif
776 #define IOC_NRMASK ((1 << IOC_NRBITS) - 1)
777 #define IOC_TYPEMASK ((1 << IOC_TYPEBITS) - 1)
778 #define IOC_SIZEMASK ((1 << IOC_SIZEBITS) - 1)
779 #if defined(IOC_DIRMASK)
780 #undef IOC_DIRMASK
781 #endif
782 #define IOC_DIRMASK ((1 << IOC_DIRBITS) - 1)
783 #define IOC_NRSHIFT 0
784 #define IOC_TYPESHIFT (IOC_NRSHIFT + IOC_NRBITS)
785 #define IOC_SIZESHIFT (IOC_TYPESHIFT + IOC_TYPEBITS)
786 #define IOC_DIRSHIFT (IOC_SIZESHIFT + IOC_SIZEBITS)
787 #define EVIOC_EV_MAX 0x1f
788 #define EVIOC_ABS_MAX 0x3f
789 
790 #define IOC_DIR(nr) (((nr) >> IOC_DIRSHIFT) & IOC_DIRMASK)
791 #define IOC_TYPE(nr) (((nr) >> IOC_TYPESHIFT) & IOC_TYPEMASK)
792 #define IOC_NR(nr) (((nr) >> IOC_NRSHIFT) & IOC_NRMASK)
793 #define IOC_SIZE(nr) (((nr) >> IOC_SIZESHIFT) & IOC_SIZEMASK)
794 
795   extern unsigned struct_arpreq_sz;
796   extern unsigned struct_ifreq_sz;
797   extern unsigned struct_termios_sz;
798   extern unsigned struct_winsize_sz;
799 
800 #if SANITIZER_LINUX
801   extern unsigned struct_cdrom_msf_sz;
802   extern unsigned struct_cdrom_multisession_sz;
803   extern unsigned struct_cdrom_read_audio_sz;
804   extern unsigned struct_cdrom_subchnl_sz;
805   extern unsigned struct_cdrom_ti_sz;
806   extern unsigned struct_cdrom_tocentry_sz;
807   extern unsigned struct_cdrom_tochdr_sz;
808   extern unsigned struct_cdrom_volctrl_sz;
809   extern unsigned struct_ff_effect_sz;
810   extern unsigned struct_floppy_drive_params_sz;
811   extern unsigned struct_floppy_drive_struct_sz;
812   extern unsigned struct_floppy_fdc_state_sz;
813   extern unsigned struct_floppy_max_errors_sz;
814   extern unsigned struct_floppy_raw_cmd_sz;
815   extern unsigned struct_floppy_struct_sz;
816   extern unsigned struct_floppy_write_errors_sz;
817   extern unsigned struct_format_descr_sz;
818   extern unsigned struct_hd_driveid_sz;
819   extern unsigned struct_hd_geometry_sz;
820   extern unsigned struct_input_absinfo_sz;
821   extern unsigned struct_input_id_sz;
822   extern unsigned struct_mtpos_sz;
823   extern unsigned struct_termio_sz;
824   extern unsigned struct_vt_consize_sz;
825   extern unsigned struct_vt_sizes_sz;
826   extern unsigned struct_vt_stat_sz;
827 #endif  // SANITIZER_LINUX
828 
829 #if SANITIZER_LINUX || SANITIZER_FREEBSD
830   extern unsigned struct_copr_buffer_sz;
831   extern unsigned struct_copr_debug_buf_sz;
832   extern unsigned struct_copr_msg_sz;
833   extern unsigned struct_midi_info_sz;
834   extern unsigned struct_mtget_sz;
835   extern unsigned struct_mtop_sz;
836   extern unsigned struct_rtentry_sz;
837   extern unsigned struct_sbi_instrument_sz;
838   extern unsigned struct_seq_event_rec_sz;
839   extern unsigned struct_synth_info_sz;
840   extern unsigned struct_vt_mode_sz;
841 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD
842 
843 #if SANITIZER_LINUX && !SANITIZER_ANDROID
844   extern unsigned struct_ax25_parms_struct_sz;
845   extern unsigned struct_cyclades_monitor_sz;
846   extern unsigned struct_input_keymap_entry_sz;
847   extern unsigned struct_ipx_config_data_sz;
848   extern unsigned struct_kbdiacrs_sz;
849   extern unsigned struct_kbentry_sz;
850   extern unsigned struct_kbkeycode_sz;
851   extern unsigned struct_kbsentry_sz;
852   extern unsigned struct_mtconfiginfo_sz;
853   extern unsigned struct_nr_parms_struct_sz;
854   extern unsigned struct_scc_modem_sz;
855   extern unsigned struct_scc_stat_sz;
856   extern unsigned struct_serial_multiport_struct_sz;
857   extern unsigned struct_serial_struct_sz;
858   extern unsigned struct_sockaddr_ax25_sz;
859   extern unsigned struct_unimapdesc_sz;
860   extern unsigned struct_unimapinit_sz;
861 #endif  // SANITIZER_LINUX && !SANITIZER_ANDROID
862 
863 #if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
864   extern unsigned struct_audio_buf_info_sz;
865   extern unsigned struct_ppp_stats_sz;
866 #endif  // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
867 
868 #if !SANITIZER_ANDROID && !SANITIZER_MAC
869   extern unsigned struct_sioc_sg_req_sz;
870   extern unsigned struct_sioc_vif_req_sz;
871 #endif
872 
873   // ioctl request identifiers
874 
875   // A special value to mark ioctls that are not present on the target platform,
876   // when it can not be determined without including any system headers.
877   extern const unsigned IOCTL_NOT_PRESENT;
878 
879   extern unsigned IOCTL_FIOASYNC;
880   extern unsigned IOCTL_FIOCLEX;
881   extern unsigned IOCTL_FIOGETOWN;
882   extern unsigned IOCTL_FIONBIO;
883   extern unsigned IOCTL_FIONCLEX;
884   extern unsigned IOCTL_FIOSETOWN;
885   extern unsigned IOCTL_SIOCADDMULTI;
886   extern unsigned IOCTL_SIOCATMARK;
887   extern unsigned IOCTL_SIOCDELMULTI;
888   extern unsigned IOCTL_SIOCGIFADDR;
889   extern unsigned IOCTL_SIOCGIFBRDADDR;
890   extern unsigned IOCTL_SIOCGIFCONF;
891   extern unsigned IOCTL_SIOCGIFDSTADDR;
892   extern unsigned IOCTL_SIOCGIFFLAGS;
893   extern unsigned IOCTL_SIOCGIFMETRIC;
894   extern unsigned IOCTL_SIOCGIFMTU;
895   extern unsigned IOCTL_SIOCGIFNETMASK;
896   extern unsigned IOCTL_SIOCGPGRP;
897   extern unsigned IOCTL_SIOCSIFADDR;
898   extern unsigned IOCTL_SIOCSIFBRDADDR;
899   extern unsigned IOCTL_SIOCSIFDSTADDR;
900   extern unsigned IOCTL_SIOCSIFFLAGS;
901   extern unsigned IOCTL_SIOCSIFMETRIC;
902   extern unsigned IOCTL_SIOCSIFMTU;
903   extern unsigned IOCTL_SIOCSIFNETMASK;
904   extern unsigned IOCTL_SIOCSPGRP;
905   extern unsigned IOCTL_TIOCCONS;
906   extern unsigned IOCTL_TIOCEXCL;
907   extern unsigned IOCTL_TIOCGETD;
908   extern unsigned IOCTL_TIOCGPGRP;
909   extern unsigned IOCTL_TIOCGWINSZ;
910   extern unsigned IOCTL_TIOCMBIC;
911   extern unsigned IOCTL_TIOCMBIS;
912   extern unsigned IOCTL_TIOCMGET;
913   extern unsigned IOCTL_TIOCMSET;
914   extern unsigned IOCTL_TIOCNOTTY;
915   extern unsigned IOCTL_TIOCNXCL;
916   extern unsigned IOCTL_TIOCOUTQ;
917   extern unsigned IOCTL_TIOCPKT;
918   extern unsigned IOCTL_TIOCSCTTY;
919   extern unsigned IOCTL_TIOCSETD;
920   extern unsigned IOCTL_TIOCSPGRP;
921   extern unsigned IOCTL_TIOCSTI;
922   extern unsigned IOCTL_TIOCSWINSZ;
923 #if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
924   extern unsigned IOCTL_SIOCGETSGCNT;
925   extern unsigned IOCTL_SIOCGETVIFCNT;
926 #endif
927 #if SANITIZER_LINUX
928   extern unsigned IOCTL_EVIOCGABS;
929   extern unsigned IOCTL_EVIOCGBIT;
930   extern unsigned IOCTL_EVIOCGEFFECTS;
931   extern unsigned IOCTL_EVIOCGID;
932   extern unsigned IOCTL_EVIOCGKEY;
933   extern unsigned IOCTL_EVIOCGKEYCODE;
934   extern unsigned IOCTL_EVIOCGLED;
935   extern unsigned IOCTL_EVIOCGNAME;
936   extern unsigned IOCTL_EVIOCGPHYS;
937   extern unsigned IOCTL_EVIOCGRAB;
938   extern unsigned IOCTL_EVIOCGREP;
939   extern unsigned IOCTL_EVIOCGSND;
940   extern unsigned IOCTL_EVIOCGSW;
941   extern unsigned IOCTL_EVIOCGUNIQ;
942   extern unsigned IOCTL_EVIOCGVERSION;
943   extern unsigned IOCTL_EVIOCRMFF;
944   extern unsigned IOCTL_EVIOCSABS;
945   extern unsigned IOCTL_EVIOCSFF;
946   extern unsigned IOCTL_EVIOCSKEYCODE;
947   extern unsigned IOCTL_EVIOCSREP;
948   extern unsigned IOCTL_BLKFLSBUF;
949   extern unsigned IOCTL_BLKGETSIZE;
950   extern unsigned IOCTL_BLKRAGET;
951   extern unsigned IOCTL_BLKRASET;
952   extern unsigned IOCTL_BLKROGET;
953   extern unsigned IOCTL_BLKROSET;
954   extern unsigned IOCTL_BLKRRPART;
955   extern unsigned IOCTL_CDROMAUDIOBUFSIZ;
956   extern unsigned IOCTL_CDROMEJECT;
957   extern unsigned IOCTL_CDROMEJECT_SW;
958   extern unsigned IOCTL_CDROMMULTISESSION;
959   extern unsigned IOCTL_CDROMPAUSE;
960   extern unsigned IOCTL_CDROMPLAYMSF;
961   extern unsigned IOCTL_CDROMPLAYTRKIND;
962   extern unsigned IOCTL_CDROMREADAUDIO;
963   extern unsigned IOCTL_CDROMREADCOOKED;
964   extern unsigned IOCTL_CDROMREADMODE1;
965   extern unsigned IOCTL_CDROMREADMODE2;
966   extern unsigned IOCTL_CDROMREADRAW;
967   extern unsigned IOCTL_CDROMREADTOCENTRY;
968   extern unsigned IOCTL_CDROMREADTOCHDR;
969   extern unsigned IOCTL_CDROMRESET;
970   extern unsigned IOCTL_CDROMRESUME;
971   extern unsigned IOCTL_CDROMSEEK;
972   extern unsigned IOCTL_CDROMSTART;
973   extern unsigned IOCTL_CDROMSTOP;
974   extern unsigned IOCTL_CDROMSUBCHNL;
975   extern unsigned IOCTL_CDROMVOLCTRL;
976   extern unsigned IOCTL_CDROMVOLREAD;
977   extern unsigned IOCTL_CDROM_GET_UPC;
978   extern unsigned IOCTL_FDCLRPRM;
979   extern unsigned IOCTL_FDDEFPRM;
980   extern unsigned IOCTL_FDFLUSH;
981   extern unsigned IOCTL_FDFMTBEG;
982   extern unsigned IOCTL_FDFMTEND;
983   extern unsigned IOCTL_FDFMTTRK;
984   extern unsigned IOCTL_FDGETDRVPRM;
985   extern unsigned IOCTL_FDGETDRVSTAT;
986   extern unsigned IOCTL_FDGETDRVTYP;
987   extern unsigned IOCTL_FDGETFDCSTAT;
988   extern unsigned IOCTL_FDGETMAXERRS;
989   extern unsigned IOCTL_FDGETPRM;
990   extern unsigned IOCTL_FDMSGOFF;
991   extern unsigned IOCTL_FDMSGON;
992   extern unsigned IOCTL_FDPOLLDRVSTAT;
993   extern unsigned IOCTL_FDRAWCMD;
994   extern unsigned IOCTL_FDRESET;
995   extern unsigned IOCTL_FDSETDRVPRM;
996   extern unsigned IOCTL_FDSETEMSGTRESH;
997   extern unsigned IOCTL_FDSETMAXERRS;
998   extern unsigned IOCTL_FDSETPRM;
999   extern unsigned IOCTL_FDTWADDLE;
1000   extern unsigned IOCTL_FDWERRORCLR;
1001   extern unsigned IOCTL_FDWERRORGET;
1002   extern unsigned IOCTL_HDIO_DRIVE_CMD;
1003   extern unsigned IOCTL_HDIO_GETGEO;
1004   extern unsigned IOCTL_HDIO_GET_32BIT;
1005   extern unsigned IOCTL_HDIO_GET_DMA;
1006   extern unsigned IOCTL_HDIO_GET_IDENTITY;
1007   extern unsigned IOCTL_HDIO_GET_KEEPSETTINGS;
1008   extern unsigned IOCTL_HDIO_GET_MULTCOUNT;
1009   extern unsigned IOCTL_HDIO_GET_NOWERR;
1010   extern unsigned IOCTL_HDIO_GET_UNMASKINTR;
1011   extern unsigned IOCTL_HDIO_SET_32BIT;
1012   extern unsigned IOCTL_HDIO_SET_DMA;
1013   extern unsigned IOCTL_HDIO_SET_KEEPSETTINGS;
1014   extern unsigned IOCTL_HDIO_SET_MULTCOUNT;
1015   extern unsigned IOCTL_HDIO_SET_NOWERR;
1016   extern unsigned IOCTL_HDIO_SET_UNMASKINTR;
1017   extern unsigned IOCTL_MTIOCPOS;
1018   extern unsigned IOCTL_PPPIOCGASYNCMAP;
1019   extern unsigned IOCTL_PPPIOCGDEBUG;
1020   extern unsigned IOCTL_PPPIOCGFLAGS;
1021   extern unsigned IOCTL_PPPIOCGUNIT;
1022   extern unsigned IOCTL_PPPIOCGXASYNCMAP;
1023   extern unsigned IOCTL_PPPIOCSASYNCMAP;
1024   extern unsigned IOCTL_PPPIOCSDEBUG;
1025   extern unsigned IOCTL_PPPIOCSFLAGS;
1026   extern unsigned IOCTL_PPPIOCSMAXCID;
1027   extern unsigned IOCTL_PPPIOCSMRU;
1028   extern unsigned IOCTL_PPPIOCSXASYNCMAP;
1029   extern unsigned IOCTL_SIOCDARP;
1030   extern unsigned IOCTL_SIOCDRARP;
1031   extern unsigned IOCTL_SIOCGARP;
1032   extern unsigned IOCTL_SIOCGIFENCAP;
1033   extern unsigned IOCTL_SIOCGIFHWADDR;
1034   extern unsigned IOCTL_SIOCGIFMAP;
1035   extern unsigned IOCTL_SIOCGIFMEM;
1036   extern unsigned IOCTL_SIOCGIFNAME;
1037   extern unsigned IOCTL_SIOCGIFSLAVE;
1038   extern unsigned IOCTL_SIOCGRARP;
1039   extern unsigned IOCTL_SIOCGSTAMP;
1040   extern unsigned IOCTL_SIOCSARP;
1041   extern unsigned IOCTL_SIOCSIFENCAP;
1042   extern unsigned IOCTL_SIOCSIFHWADDR;
1043   extern unsigned IOCTL_SIOCSIFLINK;
1044   extern unsigned IOCTL_SIOCSIFMAP;
1045   extern unsigned IOCTL_SIOCSIFMEM;
1046   extern unsigned IOCTL_SIOCSIFSLAVE;
1047   extern unsigned IOCTL_SIOCSRARP;
1048   extern unsigned IOCTL_SNDCTL_COPR_HALT;
1049   extern unsigned IOCTL_SNDCTL_COPR_LOAD;
1050   extern unsigned IOCTL_SNDCTL_COPR_RCODE;
1051   extern unsigned IOCTL_SNDCTL_COPR_RCVMSG;
1052   extern unsigned IOCTL_SNDCTL_COPR_RDATA;
1053   extern unsigned IOCTL_SNDCTL_COPR_RESET;
1054   extern unsigned IOCTL_SNDCTL_COPR_RUN;
1055   extern unsigned IOCTL_SNDCTL_COPR_SENDMSG;
1056   extern unsigned IOCTL_SNDCTL_COPR_WCODE;
1057   extern unsigned IOCTL_SNDCTL_COPR_WDATA;
1058   extern unsigned IOCTL_TCFLSH;
1059   extern unsigned IOCTL_TCGETA;
1060   extern unsigned IOCTL_TCGETS;
1061   extern unsigned IOCTL_TCSBRK;
1062   extern unsigned IOCTL_TCSBRKP;
1063   extern unsigned IOCTL_TCSETA;
1064   extern unsigned IOCTL_TCSETAF;
1065   extern unsigned IOCTL_TCSETAW;
1066   extern unsigned IOCTL_TCSETS;
1067   extern unsigned IOCTL_TCSETSF;
1068   extern unsigned IOCTL_TCSETSW;
1069   extern unsigned IOCTL_TCXONC;
1070   extern unsigned IOCTL_TIOCGLCKTRMIOS;
1071   extern unsigned IOCTL_TIOCGSOFTCAR;
1072   extern unsigned IOCTL_TIOCINQ;
1073   extern unsigned IOCTL_TIOCLINUX;
1074   extern unsigned IOCTL_TIOCSERCONFIG;
1075   extern unsigned IOCTL_TIOCSERGETLSR;
1076   extern unsigned IOCTL_TIOCSERGWILD;
1077   extern unsigned IOCTL_TIOCSERSWILD;
1078   extern unsigned IOCTL_TIOCSLCKTRMIOS;
1079   extern unsigned IOCTL_TIOCSSOFTCAR;
1080   extern unsigned IOCTL_VT_DISALLOCATE;
1081   extern unsigned IOCTL_VT_GETSTATE;
1082   extern unsigned IOCTL_VT_RESIZE;
1083   extern unsigned IOCTL_VT_RESIZEX;
1084   extern unsigned IOCTL_VT_SENDSIG;
1085 #endif  // SANITIZER_LINUX
1086 #if SANITIZER_LINUX || SANITIZER_FREEBSD
1087   extern unsigned IOCTL_MTIOCGET;
1088   extern unsigned IOCTL_MTIOCTOP;
1089   extern unsigned IOCTL_SIOCADDRT;
1090   extern unsigned IOCTL_SIOCDELRT;
1091   extern unsigned IOCTL_SNDCTL_DSP_GETBLKSIZE;
1092   extern unsigned IOCTL_SNDCTL_DSP_GETFMTS;
1093   extern unsigned IOCTL_SNDCTL_DSP_NONBLOCK;
1094   extern unsigned IOCTL_SNDCTL_DSP_POST;
1095   extern unsigned IOCTL_SNDCTL_DSP_RESET;
1096   extern unsigned IOCTL_SNDCTL_DSP_SETFMT;
1097   extern unsigned IOCTL_SNDCTL_DSP_SETFRAGMENT;
1098   extern unsigned IOCTL_SNDCTL_DSP_SPEED;
1099   extern unsigned IOCTL_SNDCTL_DSP_STEREO;
1100   extern unsigned IOCTL_SNDCTL_DSP_SUBDIVIDE;
1101   extern unsigned IOCTL_SNDCTL_DSP_SYNC;
1102   extern unsigned IOCTL_SNDCTL_FM_4OP_ENABLE;
1103   extern unsigned IOCTL_SNDCTL_FM_LOAD_INSTR;
1104   extern unsigned IOCTL_SNDCTL_MIDI_INFO;
1105   extern unsigned IOCTL_SNDCTL_MIDI_PRETIME;
1106   extern unsigned IOCTL_SNDCTL_SEQ_CTRLRATE;
1107   extern unsigned IOCTL_SNDCTL_SEQ_GETINCOUNT;
1108   extern unsigned IOCTL_SNDCTL_SEQ_GETOUTCOUNT;
1109   extern unsigned IOCTL_SNDCTL_SEQ_NRMIDIS;
1110   extern unsigned IOCTL_SNDCTL_SEQ_NRSYNTHS;
1111   extern unsigned IOCTL_SNDCTL_SEQ_OUTOFBAND;
1112   extern unsigned IOCTL_SNDCTL_SEQ_PANIC;
1113   extern unsigned IOCTL_SNDCTL_SEQ_PERCMODE;
1114   extern unsigned IOCTL_SNDCTL_SEQ_RESET;
1115   extern unsigned IOCTL_SNDCTL_SEQ_RESETSAMPLES;
1116   extern unsigned IOCTL_SNDCTL_SEQ_SYNC;
1117   extern unsigned IOCTL_SNDCTL_SEQ_TESTMIDI;
1118   extern unsigned IOCTL_SNDCTL_SEQ_THRESHOLD;
1119   extern unsigned IOCTL_SNDCTL_SYNTH_INFO;
1120   extern unsigned IOCTL_SNDCTL_SYNTH_MEMAVL;
1121   extern unsigned IOCTL_SNDCTL_TMR_CONTINUE;
1122   extern unsigned IOCTL_SNDCTL_TMR_METRONOME;
1123   extern unsigned IOCTL_SNDCTL_TMR_SELECT;
1124   extern unsigned IOCTL_SNDCTL_TMR_SOURCE;
1125   extern unsigned IOCTL_SNDCTL_TMR_START;
1126   extern unsigned IOCTL_SNDCTL_TMR_STOP;
1127   extern unsigned IOCTL_SNDCTL_TMR_TEMPO;
1128   extern unsigned IOCTL_SNDCTL_TMR_TIMEBASE;
1129   extern unsigned IOCTL_SOUND_MIXER_READ_ALTPCM;
1130   extern unsigned IOCTL_SOUND_MIXER_READ_BASS;
1131   extern unsigned IOCTL_SOUND_MIXER_READ_CAPS;
1132   extern unsigned IOCTL_SOUND_MIXER_READ_CD;
1133   extern unsigned IOCTL_SOUND_MIXER_READ_DEVMASK;
1134   extern unsigned IOCTL_SOUND_MIXER_READ_ENHANCE;
1135   extern unsigned IOCTL_SOUND_MIXER_READ_IGAIN;
1136   extern unsigned IOCTL_SOUND_MIXER_READ_IMIX;
1137   extern unsigned IOCTL_SOUND_MIXER_READ_LINE1;
1138   extern unsigned IOCTL_SOUND_MIXER_READ_LINE2;
1139   extern unsigned IOCTL_SOUND_MIXER_READ_LINE3;
1140   extern unsigned IOCTL_SOUND_MIXER_READ_LINE;
1141   extern unsigned IOCTL_SOUND_MIXER_READ_LOUD;
1142   extern unsigned IOCTL_SOUND_MIXER_READ_MIC;
1143   extern unsigned IOCTL_SOUND_MIXER_READ_MUTE;
1144   extern unsigned IOCTL_SOUND_MIXER_READ_OGAIN;
1145   extern unsigned IOCTL_SOUND_MIXER_READ_PCM;
1146   extern unsigned IOCTL_SOUND_MIXER_READ_RECLEV;
1147   extern unsigned IOCTL_SOUND_MIXER_READ_RECMASK;
1148   extern unsigned IOCTL_SOUND_MIXER_READ_RECSRC;
1149   extern unsigned IOCTL_SOUND_MIXER_READ_SPEAKER;
1150   extern unsigned IOCTL_SOUND_MIXER_READ_STEREODEVS;
1151   extern unsigned IOCTL_SOUND_MIXER_READ_SYNTH;
1152   extern unsigned IOCTL_SOUND_MIXER_READ_TREBLE;
1153   extern unsigned IOCTL_SOUND_MIXER_READ_VOLUME;
1154   extern unsigned IOCTL_SOUND_MIXER_WRITE_ALTPCM;
1155   extern unsigned IOCTL_SOUND_MIXER_WRITE_BASS;
1156   extern unsigned IOCTL_SOUND_MIXER_WRITE_CD;
1157   extern unsigned IOCTL_SOUND_MIXER_WRITE_ENHANCE;
1158   extern unsigned IOCTL_SOUND_MIXER_WRITE_IGAIN;
1159   extern unsigned IOCTL_SOUND_MIXER_WRITE_IMIX;
1160   extern unsigned IOCTL_SOUND_MIXER_WRITE_LINE1;
1161   extern unsigned IOCTL_SOUND_MIXER_WRITE_LINE2;
1162   extern unsigned IOCTL_SOUND_MIXER_WRITE_LINE3;
1163   extern unsigned IOCTL_SOUND_MIXER_WRITE_LINE;
1164   extern unsigned IOCTL_SOUND_MIXER_WRITE_LOUD;
1165   extern unsigned IOCTL_SOUND_MIXER_WRITE_MIC;
1166   extern unsigned IOCTL_SOUND_MIXER_WRITE_MUTE;
1167   extern unsigned IOCTL_SOUND_MIXER_WRITE_OGAIN;
1168   extern unsigned IOCTL_SOUND_MIXER_WRITE_PCM;
1169   extern unsigned IOCTL_SOUND_MIXER_WRITE_RECLEV;
1170   extern unsigned IOCTL_SOUND_MIXER_WRITE_RECSRC;
1171   extern unsigned IOCTL_SOUND_MIXER_WRITE_SPEAKER;
1172   extern unsigned IOCTL_SOUND_MIXER_WRITE_SYNTH;
1173   extern unsigned IOCTL_SOUND_MIXER_WRITE_TREBLE;
1174   extern unsigned IOCTL_SOUND_MIXER_WRITE_VOLUME;
1175   extern unsigned IOCTL_SOUND_PCM_READ_BITS;
1176   extern unsigned IOCTL_SOUND_PCM_READ_CHANNELS;
1177   extern unsigned IOCTL_SOUND_PCM_READ_FILTER;
1178   extern unsigned IOCTL_SOUND_PCM_READ_RATE;
1179   extern unsigned IOCTL_SOUND_PCM_WRITE_CHANNELS;
1180   extern unsigned IOCTL_SOUND_PCM_WRITE_FILTER;
1181   extern unsigned IOCTL_VT_ACTIVATE;
1182   extern unsigned IOCTL_VT_GETMODE;
1183   extern unsigned IOCTL_VT_OPENQRY;
1184   extern unsigned IOCTL_VT_RELDISP;
1185   extern unsigned IOCTL_VT_SETMODE;
1186   extern unsigned IOCTL_VT_WAITACTIVE;
1187 #endif  // SANITIZER_LINUX || SANITIZER_FREEBSD
1188 
1189 #if SANITIZER_LINUX && !SANITIZER_ANDROID
1190   extern unsigned IOCTL_CYGETDEFTHRESH;
1191   extern unsigned IOCTL_CYGETDEFTIMEOUT;
1192   extern unsigned IOCTL_CYGETMON;
1193   extern unsigned IOCTL_CYGETTHRESH;
1194   extern unsigned IOCTL_CYGETTIMEOUT;
1195   extern unsigned IOCTL_CYSETDEFTHRESH;
1196   extern unsigned IOCTL_CYSETDEFTIMEOUT;
1197   extern unsigned IOCTL_CYSETTHRESH;
1198   extern unsigned IOCTL_CYSETTIMEOUT;
1199   extern unsigned IOCTL_EQL_EMANCIPATE;
1200   extern unsigned IOCTL_EQL_ENSLAVE;
1201   extern unsigned IOCTL_EQL_GETMASTRCFG;
1202   extern unsigned IOCTL_EQL_GETSLAVECFG;
1203   extern unsigned IOCTL_EQL_SETMASTRCFG;
1204   extern unsigned IOCTL_EQL_SETSLAVECFG;
1205   extern unsigned IOCTL_EVIOCGKEYCODE_V2;
1206   extern unsigned IOCTL_EVIOCGPROP;
1207   extern unsigned IOCTL_EVIOCSKEYCODE_V2;
1208   extern unsigned IOCTL_FS_IOC_GETFLAGS;
1209   extern unsigned IOCTL_FS_IOC_GETVERSION;
1210   extern unsigned IOCTL_FS_IOC_SETFLAGS;
1211   extern unsigned IOCTL_FS_IOC_SETVERSION;
1212   extern unsigned IOCTL_GIO_CMAP;
1213   extern unsigned IOCTL_GIO_FONT;
1214   extern unsigned IOCTL_GIO_UNIMAP;
1215   extern unsigned IOCTL_GIO_UNISCRNMAP;
1216   extern unsigned IOCTL_KDADDIO;
1217   extern unsigned IOCTL_KDDELIO;
1218   extern unsigned IOCTL_KDGETKEYCODE;
1219   extern unsigned IOCTL_KDGKBDIACR;
1220   extern unsigned IOCTL_KDGKBENT;
1221   extern unsigned IOCTL_KDGKBLED;
1222   extern unsigned IOCTL_KDGKBMETA;
1223   extern unsigned IOCTL_KDGKBSENT;
1224   extern unsigned IOCTL_KDMAPDISP;
1225   extern unsigned IOCTL_KDSETKEYCODE;
1226   extern unsigned IOCTL_KDSIGACCEPT;
1227   extern unsigned IOCTL_KDSKBDIACR;
1228   extern unsigned IOCTL_KDSKBENT;
1229   extern unsigned IOCTL_KDSKBLED;
1230   extern unsigned IOCTL_KDSKBMETA;
1231   extern unsigned IOCTL_KDSKBSENT;
1232   extern unsigned IOCTL_KDUNMAPDISP;
1233   extern unsigned IOCTL_LPABORT;
1234   extern unsigned IOCTL_LPABORTOPEN;
1235   extern unsigned IOCTL_LPCAREFUL;
1236   extern unsigned IOCTL_LPCHAR;
1237   extern unsigned IOCTL_LPGETIRQ;
1238   extern unsigned IOCTL_LPGETSTATUS;
1239   extern unsigned IOCTL_LPRESET;
1240   extern unsigned IOCTL_LPSETIRQ;
1241   extern unsigned IOCTL_LPTIME;
1242   extern unsigned IOCTL_LPWAIT;
1243   extern unsigned IOCTL_MTIOCGETCONFIG;
1244   extern unsigned IOCTL_MTIOCSETCONFIG;
1245   extern unsigned IOCTL_PIO_CMAP;
1246   extern unsigned IOCTL_PIO_FONT;
1247   extern unsigned IOCTL_PIO_UNIMAP;
1248   extern unsigned IOCTL_PIO_UNIMAPCLR;
1249   extern unsigned IOCTL_PIO_UNISCRNMAP;
1250   extern unsigned IOCTL_SCSI_IOCTL_GET_IDLUN;
1251   extern unsigned IOCTL_SCSI_IOCTL_PROBE_HOST;
1252   extern unsigned IOCTL_SCSI_IOCTL_TAGGED_DISABLE;
1253   extern unsigned IOCTL_SCSI_IOCTL_TAGGED_ENABLE;
1254   extern unsigned IOCTL_SIOCAIPXITFCRT;
1255   extern unsigned IOCTL_SIOCAIPXPRISLT;
1256   extern unsigned IOCTL_SIOCAX25ADDUID;
1257   extern unsigned IOCTL_SIOCAX25DELUID;
1258   extern unsigned IOCTL_SIOCAX25GETPARMS;
1259   extern unsigned IOCTL_SIOCAX25GETUID;
1260   extern unsigned IOCTL_SIOCAX25NOUID;
1261   extern unsigned IOCTL_SIOCAX25SETPARMS;
1262   extern unsigned IOCTL_SIOCDEVPLIP;
1263   extern unsigned IOCTL_SIOCIPXCFGDATA;
1264   extern unsigned IOCTL_SIOCNRDECOBS;
1265   extern unsigned IOCTL_SIOCNRGETPARMS;
1266   extern unsigned IOCTL_SIOCNRRTCTL;
1267   extern unsigned IOCTL_SIOCNRSETPARMS;
1268   extern unsigned IOCTL_SNDCTL_DSP_GETISPACE;
1269   extern unsigned IOCTL_SNDCTL_DSP_GETOSPACE;
1270   extern unsigned IOCTL_TIOCGSERIAL;
1271   extern unsigned IOCTL_TIOCSERGETMULTI;
1272   extern unsigned IOCTL_TIOCSERSETMULTI;
1273   extern unsigned IOCTL_TIOCSSERIAL;
1274 #endif  // SANITIZER_LINUX && !SANITIZER_ANDROID
1275 
1276 #if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
1277   extern unsigned IOCTL_GIO_SCRNMAP;
1278   extern unsigned IOCTL_KDDISABIO;
1279   extern unsigned IOCTL_KDENABIO;
1280   extern unsigned IOCTL_KDGETLED;
1281   extern unsigned IOCTL_KDGETMODE;
1282   extern unsigned IOCTL_KDGKBMODE;
1283   extern unsigned IOCTL_KDGKBTYPE;
1284   extern unsigned IOCTL_KDMKTONE;
1285   extern unsigned IOCTL_KDSETLED;
1286   extern unsigned IOCTL_KDSETMODE;
1287   extern unsigned IOCTL_KDSKBMODE;
1288   extern unsigned IOCTL_KIOCSOUND;
1289   extern unsigned IOCTL_PIO_SCRNMAP;
1290 #endif
1291 
1292   extern const int errno_EINVAL;
1293   extern const int errno_EOWNERDEAD;
1294 
1295   extern const int si_SEGV_MAPERR;
1296   extern const int si_SEGV_ACCERR;
1297 }  // namespace __sanitizer
1298 
1299 #define CHECK_TYPE_SIZE(TYPE) \
1300   COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
1301 
1302 #define CHECK_SIZE_AND_OFFSET(CLASS, MEMBER)                       \
1303   COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *) NULL)->MEMBER) == \
1304                  sizeof(((CLASS *) NULL)->MEMBER));                \
1305   COMPILER_CHECK(offsetof(__sanitizer_##CLASS, MEMBER) ==          \
1306                  offsetof(CLASS, MEMBER))
1307 
1308 // For sigaction, which is a function and struct at the same time,
1309 // and thus requires explicit "struct" in sizeof() expression.
1310 #define CHECK_STRUCT_SIZE_AND_OFFSET(CLASS, MEMBER)                       \
1311   COMPILER_CHECK(sizeof(((struct __sanitizer_##CLASS *) NULL)->MEMBER) == \
1312                  sizeof(((struct CLASS *) NULL)->MEMBER));                \
1313   COMPILER_CHECK(offsetof(struct __sanitizer_##CLASS, MEMBER) ==          \
1314                  offsetof(struct CLASS, MEMBER))
1315 
1316 #endif
1317