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