1 //===-- sanitizer_platform_limits_openbsd.h -------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file is a part of Sanitizer common code.
11 // Sizes and layouts of platform-specific OpenBSD data structures.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_PLATFORM_LIMITS_OPENBSD_H
15 #define SANITIZER_PLATFORM_LIMITS_OPENBSD_H
19 #include "sanitizer_internal_defs.h"
20 #include "sanitizer_platform.h"
22 #define _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, shift) \
23 ((link_map *)((handle) == nullptr ? nullptr : ((char *)(handle) + (shift))))
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)
33 #define RLIMIT_AS RLIMIT_DATA
35 namespace __sanitizer {
36 extern unsigned struct_utsname_sz;
37 extern unsigned struct_stat_sz;
38 extern unsigned struct_rusage_sz;
39 extern unsigned siginfo_t_sz;
40 extern unsigned struct_itimerval_sz;
41 extern unsigned pthread_t_sz;
42 extern unsigned pthread_mutex_t_sz;
43 extern unsigned pthread_cond_t_sz;
44 extern unsigned pid_t_sz;
45 extern unsigned timeval_sz;
46 extern unsigned uid_t_sz;
47 extern unsigned gid_t_sz;
48 extern unsigned mbstate_t_sz;
49 extern unsigned struct_timezone_sz;
50 extern unsigned struct_tms_sz;
51 extern unsigned struct_itimerspec_sz;
52 extern unsigned struct_sigevent_sz;
53 extern unsigned struct_stack_t_sz;
54 extern unsigned struct_statfs_sz;
55 extern unsigned struct_sockaddr_sz;
57 extern unsigned struct_rlimit_sz;
58 extern unsigned struct_utimbuf_sz;
59 extern unsigned struct_timespec_sz;
61 struct __sanitizer_iocb {
68 #if SANITIZER_WORDSIZE == 64
78 struct __sanitizer___sysctl_args {
87 struct __sanitizer_sem_t {
91 struct __sanitizer_ipc_perm {
101 struct __sanitizer_shmid_ds {
102 __sanitizer_ipc_perm shm_perm;
108 long __shm_atimensec;
110 long __shm_dtimensec;
112 long __shm_ctimensec;
116 extern unsigned struct_msqid_ds_sz;
117 extern unsigned struct_mq_attr_sz;
118 extern unsigned struct_timex_sz;
119 extern unsigned struct_statvfs_sz;
121 struct __sanitizer_iovec {
126 struct __sanitizer_ifaddrs {
127 struct __sanitizer_ifaddrs *ifa_next;
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 *)
136 typedef unsigned __sanitizer_pthread_key_t;
138 typedef long long __sanitizer_time_t;
139 typedef int __sanitizer_suseconds_t;
141 struct __sanitizer_timeval {
142 __sanitizer_time_t tv_sec;
143 __sanitizer_suseconds_t tv_usec;
146 struct __sanitizer_itimerval {
147 struct __sanitizer_timeval it_interval;
148 struct __sanitizer_timeval it_value;
151 struct __sanitizer_passwd {
156 __sanitizer_time_t pw_change;
161 __sanitizer_time_t pw_expire;
164 struct __sanitizer_group {
171 struct __sanitizer_ether_addr {
175 struct __sanitizer_tm {
189 struct __sanitizer_msghdr {
191 unsigned msg_namelen;
192 struct __sanitizer_iovec *msg_iov;
195 unsigned msg_controllen;
198 struct __sanitizer_cmsghdr {
204 struct __sanitizer_dirent {
210 typedef u64 __sanitizer_clock_t;
211 typedef u32 __sanitizer_clockid_t;
213 typedef u32 __sanitizer___kernel_uid_t;
214 typedef u32 __sanitizer___kernel_gid_t;
215 typedef u64 __sanitizer___kernel_off_t;
218 } __sanitizer___kernel_fd_set;
221 unsigned int pta_magic;
224 } __sanitizer_pthread_attr_t;
226 typedef unsigned int __sanitizer_sigset_t;
228 struct __sanitizer_siginfo {
229 // The size is determined by looking at sizeof of real siginfo_t on linux.
230 u64 opaque[128 / sizeof(u64)];
233 using __sanitizer_sighandler_ptr = void (*)(int sig);
234 using __sanitizer_sigactionhandler_ptr = void (*)(int sig,
235 __sanitizer_siginfo *siginfo,
238 struct __sanitizer_sigaction {
240 __sanitizer_sighandler_ptr handler;
241 __sanitizer_sigactionhandler_ptr sigaction;
243 __sanitizer_sigset_t sa_mask;
247 typedef __sanitizer_sigset_t __sanitizer_kernel_sigset_t;
249 struct __sanitizer_kernel_sigaction_t {
251 void (*handler)(int signo);
252 void (*sigaction)(int signo, void *info, void *ctx);
254 unsigned long sa_flags;
255 void (*sa_restorer)(void);
256 __sanitizer_kernel_sigset_t sa_mask;
259 extern const uptr sig_ign;
260 extern const uptr sig_dfl;
261 extern const uptr sig_err;
262 extern const uptr sa_siginfo;
266 uptr __sanitizer_in_addr_sz(int af);
268 struct __sanitizer_dl_phdr_info {
269 #if SANITIZER_WORDSIZE == 64
274 const char *dlpi_name;
275 const void *dlpi_phdr;
276 #if SANITIZER_WORDSIZE == 64
283 extern unsigned struct_ElfW_Phdr_sz;
285 struct __sanitizer_addrinfo {
291 struct __sanitizer_sockaddr *ai_addr;
293 struct __sanitizer_addrinfo *ai_next;
296 struct __sanitizer_hostent {
304 struct __sanitizer_pollfd {
310 typedef unsigned __sanitizer_nfds_t;
312 struct __sanitizer_glob_t {
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* */);
327 extern int glob_nomatch;
328 extern int glob_altdirfunc;
330 extern unsigned path_max;
332 typedef char __sanitizer_FILE;
333 #define SANITIZER_HAS_STRUCT_FILE 0
335 extern int shmctl_ipc_stat;
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
344 extern unsigned struct_utmp_sz;
345 extern unsigned struct_utmpx_sz;
347 extern int map_fixed;
350 struct __sanitizer_ifconf {
357 extern const int si_SEGV_MAPERR;
358 extern const int si_SEGV_ACCERR;
359 } // namespace __sanitizer
361 #define CHECK_TYPE_SIZE(TYPE) \
362 COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
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))
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))
378 #define SIGACTION_SYMNAME __sigaction14
380 #endif // SANITIZER_OPENBSD