1d874057dim//===-- sanitizer_platform_limits_solaris.h -------------------------------===//
2d874057dim//
3d874057dim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4d874057dim// See https://llvm.org/LICENSE.txt for license information.
5d874057dim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d874057dim//
7d874057dim//===----------------------------------------------------------------------===//
8d874057dim//
9d874057dim// This file is a part of Sanitizer common code.
10d874057dim//
11d874057dim// Sizes and layouts of platform-specific Solaris data structures.
12d874057dim//===----------------------------------------------------------------------===//
13d874057dim
14d874057dim#ifndef SANITIZER_PLATFORM_LIMITS_SOLARIS_H
15d874057dim#define SANITIZER_PLATFORM_LIMITS_SOLARIS_H
16d874057dim
17d874057dim#if SANITIZER_SOLARIS
18d874057dim
19d874057dim#include "sanitizer_internal_defs.h"
20d874057dim#include "sanitizer_platform.h"
21d874057dim
22d874057dimnamespace __sanitizer {
23d874057dimextern unsigned struct_utsname_sz;
24d874057dimextern unsigned struct_stat_sz;
25d874057dimextern unsigned struct_stat64_sz;
26d874057dimextern unsigned struct_rusage_sz;
27d874057dimextern unsigned siginfo_t_sz;
28d874057dimextern unsigned struct_itimerval_sz;
29d874057dimextern unsigned pthread_t_sz;
30d874057dimextern unsigned pthread_mutex_t_sz;
31d874057dimextern unsigned pthread_cond_t_sz;
32d874057dimextern unsigned pid_t_sz;
33d874057dimextern unsigned timeval_sz;
34d874057dimextern unsigned uid_t_sz;
35d874057dimextern unsigned gid_t_sz;
36d874057dimextern unsigned mbstate_t_sz;
37d874057dimextern unsigned struct_timezone_sz;
38d874057dimextern unsigned struct_tms_sz;
39d874057dimextern unsigned struct_itimerspec_sz;
40d874057dimextern unsigned struct_sigevent_sz;
41340097edimextern unsigned struct_stack_t_sz;
42d874057dimextern unsigned struct_sched_param_sz;
43d874057dimextern unsigned struct_statfs64_sz;
44d874057dimextern unsigned struct_statfs_sz;
45d874057dimextern unsigned struct_sockaddr_sz;
46d874057dimextern unsigned ucontext_t_sz;
47d874057dim
48d874057dimextern unsigned struct_timespec_sz;
49d874057dimextern unsigned struct_rlimit_sz;
50d874057dimextern unsigned struct_utimbuf_sz;
51d874057dim
52d874057dimstruct __sanitizer_sem_t {
53d874057dim  //u64 data[6];
54d874057dim  u32 sem_count;
55d874057dim  u16 sem_type;
56d874057dim  u16 sem_magic;
57d874057dim  u64 sem_pad1[3];
58d874057dim  u64 sem_pad2[2];
59d874057dim};
60d874057dim
61d874057dimstruct __sanitizer_ipc_perm {
62d874057dim  unsigned int uid;           // uid_t
63d874057dim  unsigned int gid;           // gid_t
64d874057dim  unsigned int cuid;          // uid_t
65d874057dim  unsigned int cgid;          // gid_t
66d874057dim  unsigned int mode;          // mode_t
67d874057dim  unsigned int seq;           // uint_t
68d874057dim  int key;                    // key_t
69d874057dim#if !defined(_LP64)
70d874057dim  int pad[4];
71d874057dim#endif
72d874057dim};
73d874057dim
74d874057dimstruct __sanitizer_shmid_ds {
75d874057dim  __sanitizer_ipc_perm shm_perm;
76d874057dim  unsigned long shm_segsz;    // size_t
77d874057dim  unsigned long shm_flags;    // uintptr_t
78d874057dim  unsigned short shm_lkcnt;   // ushort_t
79d874057dim  int shm_lpid;               // pid_t
80d874057dim  int shm_cpid;               // pid_t
81d874057dim  unsigned long shm_nattch;   // shmatt_t
82d874057dim  unsigned long shm_cnattch;  // ulong_t
83d874057dim#if defined(_LP64)
84d874057dim  long shm_atime;             // time_t
85d874057dim  long shm_dtime;
86d874057dim  long shm_ctime;
87d874057dim  void *shm_amp;
88d874057dim  u64 shm_gransize;           // uint64_t
89d874057dim  u64 shm_allocated;          // uint64_t
90d874057dim  u64 shm_pad4[1];            // int64_t
91d874057dim#else
92d874057dim  long shm_atime;             // time_t
93d874057dim  int shm_pad1;               // int32_t
94d874057dim  long shm_dtime;             // time_t
95d874057dim  int shm_pad2;               // int32_t
96d874057dim  long shm_ctime;             // time_t
97d874057dim  void *shm_amp;
98d874057dim  u64 shm_gransize;           // uint64_t
99d874057dim  u64 shm_allocated;          // uint64_t
100d874057dim#endif
101d874057dim};
102d874057dim
103d874057dimextern unsigned struct_statvfs_sz;
104d874057dim#if SANITIZER_SOLARIS32
105d874057dimextern unsigned struct_statvfs64_sz;
106d874057dim#endif
107d874057dim
108d874057dimstruct __sanitizer_iovec {
109d874057dim  void *iov_base;
110d874057dim  uptr iov_len;
111d874057dim};
112d874057dim
113d874057dimstruct __sanitizer_ifaddrs {
114d874057dim  struct __sanitizer_ifaddrs *ifa_next;
115d874057dim  char *ifa_name;
116d874057dim  u64 ifa_flags;     // uint64_t
117d874057dim  void *ifa_addr;    // (struct sockaddr *)
118d874057dim  void *ifa_netmask; // (struct sockaddr *)
119d874057dim  // This is a union on Linux.
120d874057dim# ifdef ifa_dstaddr
121d874057dim# undef ifa_dstaddr
122d874057dim# endif
123d874057dim  void *ifa_dstaddr; // (struct sockaddr *)
124d874057dim  void *ifa_data;
125d874057dim};
126d874057dim
127d874057dimtypedef unsigned __sanitizer_pthread_key_t;
128d874057dim
129d874057dimstruct __sanitizer_XDR {
130d874057dim  int x_op;
131d874057dim  void *x_ops;
132d874057dim  uptr x_public;
133d874057dim  uptr x_private;
134d874057dim  uptr x_base;
135d874057dim  unsigned x_handy;
136d874057dim};
137d874057dim
138d874057dimconst int __sanitizer_XDR_ENCODE = 0;
139d874057dimconst int __sanitizer_XDR_DECODE = 1;
140d874057dimconst int __sanitizer_XDR_FREE = 2;
141d874057dim
142d874057dimstruct __sanitizer_passwd {
143d874057dim  char *pw_name;
144d874057dim  char *pw_passwd;
145d874057dim  unsigned int pw_uid;    // uid_t
146d874057dim  unsigned int pw_gid;    // gid_t
147d874057dim  char *pw_age;
148d874057dim  char *pw_comment;
149d874057dim  char *pw_gecos;
150d874057dim  char *pw_dir;
151d874057dim  char *pw_shell;
152d874057dim};
153d874057dim
154d874057dimstruct __sanitizer_group {
155d874057dim  char *gr_name;
156d874057dim  char *gr_passwd;
157d874057dim  int gr_gid;
158d874057dim  char **gr_mem;
159d874057dim};
160d874057dim
161d874057dimtypedef long __sanitizer_time_t;
162d874057dim
163d874057dimtypedef long __sanitizer_suseconds_t;
164d874057dim
165d874057dimstruct __sanitizer_timeval {
166d874057dim  __sanitizer_time_t tv_sec;
167d874057dim  __sanitizer_suseconds_t tv_usec;
168d874057dim};
169d874057dim
170d874057dimstruct __sanitizer_itimerval {
171d874057dim  struct __sanitizer_timeval it_interval;
172d874057dim  struct __sanitizer_timeval it_value;
173d874057dim};
174d874057dim
175d874057dimstruct __sanitizer_timeb {
176d874057dim  __sanitizer_time_t time;
177d874057dim  unsigned short millitm;
178d874057dim  short timezone;
179d874057dim  short dstflag;
180d874057dim};
181d874057dim
182d874057dimstruct __sanitizer_ether_addr {
183d874057dim  u8 octet[6];
184d874057dim};
185d874057dim
186d874057dimstruct __sanitizer_tm {
187d874057dim  int tm_sec;
188d874057dim  int tm_min;
189d874057dim  int tm_hour;
190d874057dim  int tm_mday;
191d874057dim  int tm_mon;
192d874057dim  int tm_year;
193d874057dim  int tm_wday;
194d874057dim  int tm_yday;
195d874057dim  int tm_isdst;
196d874057dim};
197d874057dim
198d874057dimstruct __sanitizer_msghdr {
199d874057dim  void *msg_name;
200d874057dim  unsigned msg_namelen;
201d874057dim  struct __sanitizer_iovec *msg_iov;
202d874057dim  unsigned msg_iovlen;
203d874057dim  void *msg_control;
204d874057dim  unsigned msg_controllen;
205d874057dim  int msg_flags;
206d874057dim};
207d874057dimstruct __sanitizer_cmsghdr {
208d874057dim  unsigned cmsg_len;
209d874057dim  int cmsg_level;
210d874057dim  int cmsg_type;
211d874057dim};
212d874057dim
213d874057dim#if SANITIZER_SOLARIS && (defined(_LP64) || _FILE_OFFSET_BITS == 64)
214d874057dimstruct __sanitizer_dirent {
215d874057dim  unsigned long long d_ino;
216d874057dim  long long d_off;
217d874057dim  unsigned short d_reclen;
218d874057dim  // more fields that we don't care about
219d874057dim};
220d874057dim#else
221d874057dimstruct __sanitizer_dirent {
222d874057dim  unsigned long d_ino;
223d874057dim  long d_off;
224d874057dim  unsigned short d_reclen;
225d874057dim  // more fields that we don't care about
226d874057dim};
227d874057dim#endif
228d874057dim
229d874057dimstruct __sanitizer_dirent64 {
230d874057dim  unsigned long long d_ino;
231d874057dim  unsigned long long d_off;
232d874057dim  unsigned short d_reclen;
233d874057dim  // more fields that we don't care about
234d874057dim};
235d874057dim
236d874057dimtypedef long __sanitizer_clock_t;
237d874057dimtypedef int __sanitizer_clockid_t;
238d874057dim
239d874057dim// This thing depends on the platform. We are only interested in the upper
240d874057dim// limit. Verified with a compiler assert in .cpp.
241d874057dimunion __sanitizer_pthread_attr_t {
242d874057dim  char size[128];
243d874057dim  void *align;
244d874057dim};
245d874057dim
246d874057dimstruct __sanitizer_sigset_t {
247d874057dim  // uint32_t * 4
248d874057dim  unsigned int __bits[4];
249d874057dim};
250d874057dim
251d874057dimstruct __sanitizer_siginfo {
252d874057dim  // The size is determined by looking at sizeof of real siginfo_t on linux.
253d874057dim  u64 opaque[128 / sizeof(u64)];
254d874057dim};
255d874057dim
256d874057dimusing __sanitizer_sighandler_ptr = void (*)(int sig);
257d874057dimusing __sanitizer_sigactionhandler_ptr =
258d874057dim    void (*)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
259d874057dim
260d874057dimstruct __sanitizer_sigaction {
261d874057dim  int sa_flags;
262d874057dim  union {
263d874057dim    __sanitizer_sigactionhandler_ptr sigaction;
264d874057dim    __sanitizer_sighandler_ptr handler;
265d874057dim  };
266d874057dim  __sanitizer_sigset_t sa_mask;
267d874057dim#if !defined(_LP64)
268d874057dim  int sa_resv[2];
269d874057dim#endif
270d874057dim};
271d874057dim
272d874057dimstruct __sanitizer_kernel_sigset_t {
273d874057dim  u8 sig[8];
274d874057dim};
275d874057dim
276d874057dimstruct __sanitizer_kernel_sigaction_t {
277d874057dim  union {
278d874057dim    void (*handler)(int signo);
279d874057dim    void (*sigaction)(int signo, __sanitizer_siginfo *info, void *ctx);
280d874057dim  };
281d874057dim  unsigned long sa_flags;
282d874057dim  void (*sa_restorer)(void);
283d874057dim  __sanitizer_kernel_sigset_t sa_mask;
284d874057dim};
285d874057dim
286d874057dimextern const uptr sig_ign;
287d874057dimextern const uptr sig_dfl;
288d874057dimextern const uptr sig_err;
289d874057dimextern const uptr sa_siginfo;
290d874057dim
291d874057dimextern int af_inet;
292d874057dimextern int af_inet6;
293d874057dimuptr __sanitizer_in_addr_sz(int af);
294d874057dim
295d874057dimstruct __sanitizer_dl_phdr_info {
296d874057dim  uptr dlpi_addr;
297d874057dim  const char *dlpi_name;
298d874057dim  const void *dlpi_phdr;
299d874057dim  short dlpi_phnum;
300d874057dim};
301d874057dim
302d874057dimextern unsigned struct_ElfW_Phdr_sz;
303d874057dim
304d874057dimstruct __sanitizer_addrinfo {
305d874057dim  int ai_flags;
306d874057dim  int ai_family;
307d874057dim  int ai_socktype;
308d874057dim  int ai_protocol;
309d874057dim#if defined(__sparcv9)
310d874057dim  int _ai_pad;
311d874057dim#endif
312d874057dim  unsigned ai_addrlen;
313d874057dim  char *ai_canonname;
314d874057dim  void *ai_addr;
315d874057dim  struct __sanitizer_addrinfo *ai_next;
316d874057dim};
317d874057dim
318d874057dimstruct __sanitizer_hostent {
319d874057dim  char *h_name;
320d874057dim  char **h_aliases;
321d874057dim  int h_addrtype;
322d874057dim  int h_length;
323d874057dim  char **h_addr_list;
324d874057dim};
325d874057dim
326d874057dimstruct __sanitizer_pollfd {
327d874057dim  int fd;
328d874057dim  short events;
329d874057dim  short revents;
330d874057dim};
331d874057dim
332d874057dimtypedef unsigned long __sanitizer_nfds_t;
333d874057dim
334d874057dimstruct __sanitizer_glob_t {
335d874057dim  uptr gl_pathc;
336d874057dim  char **gl_pathv;
337d874057dim  uptr gl_offs;
338d874057dim  char **gl_pathp;
339d874057dim  int gl_pathn;
340d874057dim};
341d874057dim
342d874057dimextern int glob_nomatch;
343d874057dimextern int glob_altdirfunc;
344d874057dim
345d874057dimextern unsigned path_max;
346d874057dim
347d874057dimstruct __sanitizer_wordexp_t {
348d874057dim  uptr we_wordc;
349d874057dim  char **we_wordv;
350d874057dim  uptr we_offs;
351d874057dim  char **we_wordp;
352d874057dim  int we_wordn;
353d874057dim};
354d874057dim
355d874057dimtypedef void __sanitizer_FILE;
356d874057dim#define SANITIZER_HAS_STRUCT_FILE 0
357d874057dim
358d874057dim// This simplifies generic code
359d874057dim#define struct_shminfo_sz -1
360d874057dim#define struct_shm_info_sz -1
361d874057dim#define shmctl_shm_stat -1
362d874057dim#define shmctl_ipc_info -1
363d874057dim#define shmctl_shm_info -1
364d874057dim
365d874057dimextern int shmctl_ipc_stat;
366d874057dim
367d874057dimextern unsigned struct_utmp_sz;
368d874057dimextern unsigned struct_utmpx_sz;
369d874057dim
370d874057dimextern int map_fixed;
371d874057dim
372d874057dim// ioctl arguments
373d874057dimstruct __sanitizer_ifconf {
374d874057dim  int ifc_len;
375d874057dim  union {
376d874057dim    void *ifcu_req;
377d874057dim  } ifc_ifcu;
378d874057dim};
379d874057dim
380d874057dim// <sys/ioccom.h>
381d874057dim#define IOC_NRBITS 8
382d874057dim#define IOC_TYPEBITS 8
383d874057dim#define IOC_SIZEBITS 12
384d874057dim#define IOC_DIRBITS 4
385d874057dim#undef IOC_NONE
386d874057dim#define IOC_NONE 2U     // IOC_VOID
387d874057dim#define IOC_READ 4U     // IOC_OUT
388d874057dim#define IOC_WRITE 8U    // IOC_IN
389d874057dim
390d874057dim#define IOC_NRMASK ((1 << IOC_NRBITS) - 1)
391d874057dim#define IOC_TYPEMASK ((1 << IOC_TYPEBITS) - 1)
392d874057dim#define IOC_SIZEMASK ((1 << IOC_SIZEBITS) - 1)
393d874057dim#define IOC_DIRMASK ((1 << IOC_DIRBITS) - 1)
394d874057dim#define IOC_NRSHIFT 0
395d874057dim#define IOC_TYPESHIFT (IOC_NRSHIFT + IOC_NRBITS)
396d874057dim#define IOC_SIZESHIFT (IOC_TYPESHIFT + IOC_TYPEBITS)
397d874057dim#define IOC_DIRSHIFT (IOC_SIZESHIFT + IOC_SIZEBITS)
398d874057dim
399d874057dim#define IOC_DIR(nr) (((nr) >> IOC_DIRSHIFT) & IOC_DIRMASK)
400d874057dim#define IOC_TYPE(nr) (((nr) >> IOC_TYPESHIFT) & IOC_TYPEMASK)
401d874057dim#define IOC_NR(nr) (((nr) >> IOC_NRSHIFT) & IOC_NRMASK)
402d874057dim
403d874057dim#if defined(__sparc__)
404d874057dim// In sparc the 14 bits SIZE field overlaps with the
405d874057dim// least significant bit of DIR, so either IOC_READ or
406d874057dim// IOC_WRITE shall be 1 in order to get a non-zero SIZE.
407d874057dim#define IOC_SIZE(nr) \
408d874057dim  ((((((nr) >> 29) & 0x7) & (4U | 2U)) == 0) ? 0 : (((nr) >> 16) & 0x3fff))
409d874057dim#else
410d874057dim#define IOC_SIZE(nr) (((nr) >> IOC_SIZESHIFT) & IOC_SIZEMASK)
411d874057dim#endif
412d874057dim
413d874057dimextern unsigned struct_ifreq_sz;
414d874057dimextern unsigned struct_termios_sz;
415d874057dimextern unsigned struct_winsize_sz;
416d874057dim
417d874057dimextern unsigned struct_sioc_sg_req_sz;
418d874057dimextern unsigned struct_sioc_vif_req_sz;
419d874057dim
420d874057dim// ioctl request identifiers
421d874057dim
422d874057dim// A special value to mark ioctls that are not present on the target platform,
423d874057dim// when it can not be determined without including any system headers.
424d874057dimextern const unsigned IOCTL_NOT_PRESENT;
425d874057dim
426d874057dimextern unsigned IOCTL_FIOASYNC;
427d874057dimextern unsigned IOCTL_FIOCLEX;
428d874057dimextern unsigned IOCTL_FIOGETOWN;
429d874057dimextern unsigned IOCTL_FIONBIO;
430d874057dimextern unsigned IOCTL_FIONCLEX;
431d874057dimextern unsigned IOCTL_FIOSETOWN;
432d874057dimextern unsigned IOCTL_SIOCADDMULTI;
433d874057dimextern unsigned IOCTL_SIOCATMARK;
434d874057dimextern unsigned IOCTL_SIOCDELMULTI;
435d874057dimextern unsigned IOCTL_SIOCGIFADDR;
436d874057dimextern unsigned IOCTL_SIOCGIFBRDADDR;
437d874057dimextern unsigned IOCTL_SIOCGIFCONF;
438d874057dimextern unsigned IOCTL_SIOCGIFDSTADDR;
439d874057dimextern unsigned IOCTL_SIOCGIFFLAGS;
440d874057dimextern unsigned IOCTL_SIOCGIFMETRIC;
441d874057dimextern unsigned IOCTL_SIOCGIFMTU;
442d874057dimextern unsigned IOCTL_SIOCGIFNETMASK;
443d874057dimextern unsigned IOCTL_SIOCGPGRP;
444d874057dimextern unsigned IOCTL_SIOCSIFADDR;
445d874057dimextern unsigned IOCTL_SIOCSIFBRDADDR;
446d874057dimextern unsigned IOCTL_SIOCSIFDSTADDR;
447d874057dimextern unsigned IOCTL_SIOCSIFFLAGS;
448d874057dimextern unsigned IOCTL_SIOCSIFMETRIC;
449d874057dimextern unsigned IOCTL_SIOCSIFMTU;
450d874057dimextern unsigned IOCTL_SIOCSIFNETMASK;
451d874057dimextern unsigned IOCTL_SIOCSPGRP;
452d874057dimextern unsigned IOCTL_TIOCEXCL;
453d874057dimextern unsigned IOCTL_TIOCGETD;
454d874057dimextern unsigned IOCTL_TIOCGPGRP;
455d874057dimextern unsigned IOCTL_TIOCGWINSZ;
456d874057dimextern unsigned IOCTL_TIOCMBIC;
457d874057dimextern unsigned IOCTL_TIOCMBIS;
458d874057dimextern unsigned IOCTL_TIOCMGET;
459d874057dimextern unsigned IOCTL_TIOCMSET;
460d874057dimextern unsigned IOCTL_TIOCNOTTY;
461d874057dimextern unsigned IOCTL_TIOCNXCL;
462d874057dimextern unsigned IOCTL_TIOCOUTQ;
463d874057dimextern unsigned IOCTL_TIOCPKT;
464d874057dimextern unsigned IOCTL_TIOCSCTTY;
465d874057dimextern unsigned IOCTL_TIOCSETD;
466d874057dimextern unsigned IOCTL_TIOCSPGRP;
467d874057dimextern unsigned IOCTL_TIOCSTI;
468d874057dimextern unsigned IOCTL_TIOCSWINSZ;
469d874057dimextern unsigned IOCTL_MTIOCGET;
470d874057dimextern unsigned IOCTL_MTIOCTOP;
471d874057dim
472d874057dimextern const int si_SEGV_MAPERR;
473d874057dimextern const int si_SEGV_ACCERR;
474d874057dim}  // namespace __sanitizer
475d874057dim
476d874057dim#define CHECK_TYPE_SIZE(TYPE) \
477d874057dim  COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
478d874057dim
479d874057dim#define CHECK_SIZE_AND_OFFSET(CLASS, MEMBER)                       \
480d874057dim  COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *) NULL)->MEMBER) == \
481d874057dim                 sizeof(((CLASS *) NULL)->MEMBER));                \
482d874057dim  COMPILER_CHECK(offsetof(__sanitizer_##CLASS, MEMBER) ==          \
483d874057dim                 offsetof(CLASS, MEMBER))
484d874057dim
485d874057dim// For sigaction, which is a function and struct at the same time,
486d874057dim// and thus requires explicit "struct" in sizeof() expression.
487d874057dim#define CHECK_STRUCT_SIZE_AND_OFFSET(CLASS, MEMBER)                       \
488d874057dim  COMPILER_CHECK(sizeof(((struct __sanitizer_##CLASS *) NULL)->MEMBER) == \
489d874057dim                 sizeof(((struct CLASS *) NULL)->MEMBER));                \
490d874057dim  COMPILER_CHECK(offsetof(struct __sanitizer_##CLASS, MEMBER) ==          \
491d874057dim                 offsetof(struct CLASS, MEMBER))
492d874057dim
493d874057dim#endif  // SANITIZER_SOLARIS
494d874057dim
495d874057dim#endif
496