1//===-- sanitizer_platform_limits_openbsd.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 OpenBSD data structures.
12//===----------------------------------------------------------------------===//
13
14#ifndef SANITIZER_PLATFORM_LIMITS_OPENBSD_H
15#define SANITIZER_PLATFORM_LIMITS_OPENBSD_H
16
17#if SANITIZER_OPENBSD
18
19#include "sanitizer_internal_defs.h"
20#include "sanitizer_platform.h"
21
22#define _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, shift) \
23  ((link_map *)((handle) == nullptr ? nullptr : ((char *)(handle) + (shift))))
24
25#if defined(__x86_64__)
26#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
27  _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 312)
28#elif defined(__i386__)
29#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
30  _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 164)
31#endif
32
33#define RLIMIT_AS RLIMIT_DATA
34
35namespace __sanitizer {
36extern unsigned struct_utsname_sz;
37extern unsigned struct_stat_sz;
38extern unsigned struct_rusage_sz;
39extern unsigned siginfo_t_sz;
40extern unsigned struct_itimerval_sz;
41extern unsigned pthread_t_sz;
42extern unsigned pthread_mutex_t_sz;
43extern unsigned pthread_cond_t_sz;
44extern unsigned pid_t_sz;
45extern unsigned timeval_sz;
46extern unsigned uid_t_sz;
47extern unsigned gid_t_sz;
48extern unsigned mbstate_t_sz;
49extern unsigned struct_timezone_sz;
50extern unsigned struct_tms_sz;
51extern unsigned struct_itimerspec_sz;
52extern unsigned struct_sigevent_sz;
53extern unsigned struct_stack_t_sz;
54extern unsigned struct_statfs_sz;
55extern unsigned struct_sockaddr_sz;
56
57extern unsigned struct_rlimit_sz;
58extern unsigned struct_utimbuf_sz;
59extern unsigned struct_timespec_sz;
60
61struct __sanitizer_iocb {
62  u64 aio_offset;
63  uptr aio_buf;
64  long aio_nbytes;
65  u32 aio_fildes;
66  u32 aio_lio_opcode;
67  long aio_reqprio;
68#if SANITIZER_WORDSIZE == 64
69  u8 aio_sigevent[32];
70#else
71  u8 aio_sigevent[20];
72#endif
73  u32 _state;
74  u32 _errno;
75  long _retval;
76};
77
78struct __sanitizer___sysctl_args {
79  int *name;
80  int nlen;
81  void *oldval;
82  uptr *oldlenp;
83  void *newval;
84  uptr newlen;
85};
86
87struct __sanitizer_sem_t {
88  uptr data[5];
89};
90
91struct __sanitizer_ipc_perm {
92  u32 cuid;
93  u32 cgid;
94  u32 uid;
95  u32 gid;
96  u32 mode;
97  unsigned short seq;
98  long key;
99};
100
101struct __sanitizer_shmid_ds {
102  __sanitizer_ipc_perm shm_perm;
103  int shm_segsz;
104  u32 shm_lpid;
105  u32 shm_cpid;
106  short shm_nattch;
107  u64 shm_atime;
108  long __shm_atimensec;
109  u64 shm_dtime;
110  long __shm_dtimensec;
111  u64 shm_ctime;
112  long __shm_ctimensec;
113  void *_shm_internal;
114};
115
116extern unsigned struct_msqid_ds_sz;
117extern unsigned struct_mq_attr_sz;
118extern unsigned struct_timex_sz;
119extern unsigned struct_statvfs_sz;
120
121struct __sanitizer_iovec {
122  void *iov_base;
123  uptr iov_len;
124};
125
126struct __sanitizer_ifaddrs {
127  struct __sanitizer_ifaddrs *ifa_next;
128  char *ifa_name;
129  unsigned int ifa_flags;
130  struct __sanitizer_sockaddr *ifa_addr;     // (struct sockaddr *)
131  struct __sanitizer_sockaddr *ifa_netmask;  // (struct sockaddr *)
132  struct __sanitizer_sockaddr *ifa_dstaddr;  // (struct sockaddr *)
133  void *ifa_data;
134};
135
136typedef unsigned __sanitizer_pthread_key_t;
137
138typedef long long __sanitizer_time_t;
139typedef int __sanitizer_suseconds_t;
140
141struct __sanitizer_timeval {
142  __sanitizer_time_t tv_sec;
143  __sanitizer_suseconds_t tv_usec;
144};
145
146struct __sanitizer_itimerval {
147  struct __sanitizer_timeval it_interval;
148  struct __sanitizer_timeval it_value;
149};
150
151struct __sanitizer_passwd {
152  char *pw_name;
153  char *pw_passwd;
154  int pw_uid;
155  int pw_gid;
156  __sanitizer_time_t pw_change;
157  char *pw_class;
158  char *pw_gecos;
159  char *pw_dir;
160  char *pw_shell;
161  __sanitizer_time_t pw_expire;
162};
163
164struct __sanitizer_group {
165  char *gr_name;
166  char *gr_passwd;
167  int gr_gid;
168  char **gr_mem;
169};
170
171struct __sanitizer_ether_addr {
172  u8 octet[6];
173};
174
175struct __sanitizer_tm {
176  int tm_sec;
177  int tm_min;
178  int tm_hour;
179  int tm_mday;
180  int tm_mon;
181  int tm_year;
182  int tm_wday;
183  int tm_yday;
184  int tm_isdst;
185  long int tm_gmtoff;
186  const char *tm_zone;
187};
188
189struct __sanitizer_msghdr {
190  void *msg_name;
191  unsigned msg_namelen;
192  struct __sanitizer_iovec *msg_iov;
193  unsigned msg_iovlen;
194  void *msg_control;
195  unsigned msg_controllen;
196  int msg_flags;
197};
198struct __sanitizer_cmsghdr {
199  unsigned cmsg_len;
200  int cmsg_level;
201  int cmsg_type;
202};
203
204struct __sanitizer_dirent {
205  u64 d_fileno;
206  u64 d_off;
207  u16 d_reclen;
208};
209
210typedef u64 __sanitizer_clock_t;
211typedef u32 __sanitizer_clockid_t;
212
213typedef u32 __sanitizer___kernel_uid_t;
214typedef u32 __sanitizer___kernel_gid_t;
215typedef u64 __sanitizer___kernel_off_t;
216typedef struct {
217  u32 fds_bits[8];
218} __sanitizer___kernel_fd_set;
219
220typedef struct {
221  unsigned int pta_magic;
222  int pta_flags;
223  void *pta_private;
224} __sanitizer_pthread_attr_t;
225
226typedef unsigned int __sanitizer_sigset_t;
227
228struct __sanitizer_siginfo {
229  // The size is determined by looking at sizeof of real siginfo_t on linux.
230  u64 opaque[128 / sizeof(u64)];
231};
232
233using __sanitizer_sighandler_ptr = void (*)(int sig);
234using __sanitizer_sigactionhandler_ptr = void (*)(int sig,
235                                                  __sanitizer_siginfo *siginfo,
236                                                  void *uctx);
237
238struct __sanitizer_sigaction {
239  union {
240    __sanitizer_sighandler_ptr handler;
241    __sanitizer_sigactionhandler_ptr sigaction;
242  };
243  __sanitizer_sigset_t sa_mask;
244  int sa_flags;
245};
246
247typedef __sanitizer_sigset_t __sanitizer_kernel_sigset_t;
248
249struct __sanitizer_kernel_sigaction_t {
250  union {
251    void (*handler)(int signo);
252    void (*sigaction)(int signo, void *info, void *ctx);
253  };
254  unsigned long sa_flags;
255  void (*sa_restorer)(void);
256  __sanitizer_kernel_sigset_t sa_mask;
257};
258
259extern const uptr sig_ign;
260extern const uptr sig_dfl;
261extern const uptr sig_err;
262extern const uptr sa_siginfo;
263
264extern int af_inet;
265extern int af_inet6;
266uptr __sanitizer_in_addr_sz(int af);
267
268struct __sanitizer_dl_phdr_info {
269#if SANITIZER_WORDSIZE == 64
270  u64 dlpi_addr;
271#else
272  u32 dlpi_addr;
273#endif
274  const char *dlpi_name;
275  const void *dlpi_phdr;
276#if SANITIZER_WORDSIZE == 64
277  u32 dlpi_phnum;
278#else
279  u16 dlpi_phnum;
280#endif
281};
282
283extern unsigned struct_ElfW_Phdr_sz;
284
285struct __sanitizer_addrinfo {
286  int ai_flags;
287  int ai_family;
288  int ai_socktype;
289  int ai_protocol;
290  unsigned ai_addrlen;
291  struct __sanitizer_sockaddr *ai_addr;
292  char *ai_canonname;
293  struct __sanitizer_addrinfo *ai_next;
294};
295
296struct __sanitizer_hostent {
297  char *h_name;
298  char **h_aliases;
299  int h_addrtype;
300  int h_length;
301  char **h_addr_list;
302};
303
304struct __sanitizer_pollfd {
305  int fd;
306  short events;
307  short revents;
308};
309
310typedef unsigned __sanitizer_nfds_t;
311
312struct __sanitizer_glob_t {
313  int gl_pathc;
314  int gl_matchc;
315  int gl_offs;
316  int gl_flags;
317  char **gl_pathv;
318  void **gl_statv;
319  int (*gl_errfunc)(const char *, int);
320  void (*gl_closedir)(void *dirp);
321  struct dirent *(*gl_readdir)(void *dirp);
322  void *(*gl_opendir)(const char *);
323  int (*gl_lstat)(const char *, void * /* struct stat* */);
324  int (*gl_stat)(const char *, void * /* struct stat* */);
325};
326
327extern int glob_nomatch;
328extern int glob_altdirfunc;
329
330extern unsigned path_max;
331
332typedef char __sanitizer_FILE;
333#define SANITIZER_HAS_STRUCT_FILE 0
334
335extern int shmctl_ipc_stat;
336
337// This simplifies generic code
338#define struct_shminfo_sz -1
339#define struct_shm_info_sz -1
340#define shmctl_shm_stat -1
341#define shmctl_ipc_info -1
342#define shmctl_shm_info -1
343
344extern unsigned struct_utmp_sz;
345extern unsigned struct_utmpx_sz;
346
347extern int map_fixed;
348
349// ioctl arguments
350struct __sanitizer_ifconf {
351  int ifc_len;
352  union {
353    void *ifcu_req;
354  } ifc_ifcu;
355};
356
357extern const int si_SEGV_MAPERR;
358extern const int si_SEGV_ACCERR;
359}  // namespace __sanitizer
360
361#define CHECK_TYPE_SIZE(TYPE) \
362  COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
363
364#define CHECK_SIZE_AND_OFFSET(CLASS, MEMBER)                      \
365  COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *)NULL)->MEMBER) == \
366                 sizeof(((CLASS *)NULL)->MEMBER));                \
367  COMPILER_CHECK(offsetof(__sanitizer_##CLASS, MEMBER) ==         \
368                 offsetof(CLASS, MEMBER))
369
370// For sigaction, which is a function and struct at the same time,
371// and thus requires explicit "struct" in sizeof() expression.
372#define CHECK_STRUCT_SIZE_AND_OFFSET(CLASS, MEMBER)                      \
373  COMPILER_CHECK(sizeof(((struct __sanitizer_##CLASS *)NULL)->MEMBER) == \
374                 sizeof(((struct CLASS *)NULL)->MEMBER));                \
375  COMPILER_CHECK(offsetof(struct __sanitizer_##CLASS, MEMBER) ==         \
376                 offsetof(struct CLASS, MEMBER))
377
378#define SIGACTION_SYMNAME __sigaction14
379
380#endif  // SANITIZER_OPENBSD
381
382#endif
383