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