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