1 //===-- sanitizer_platform_limits_openbsd.cc ------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of Sanitizer common code.
10 // Sizes and layouts of platform-specific NetBSD data structures.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_platform.h"
16 #include <arpa/inet.h>
23 #include <sys/socket.h>
25 #include <net/ppp_defs.h>
26 #include <net/route.h>
28 #include <netinet/in.h>
29 #include <netinet/ip_mroute.h>
33 #include <semaphore.h>
35 #include <soundcard.h>
38 #include <sys/filio.h>
41 #include <sys/mount.h>
44 #include <sys/ptrace.h>
45 #include <sys/resource.h>
47 #include <sys/signal.h>
48 #include <sys/sockio.h>
50 #include <sys/statvfs.h>
52 #include <sys/times.h>
53 #include <sys/types.h>
54 #include <sys/utsname.h>
61 // Include these after system headers to avoid name clashes and ambiguities.
62 #include "sanitizer_internal_defs.h"
63 #include "sanitizer_platform_limits_openbsd.h"
65 namespace __sanitizer
{
66 unsigned struct_utsname_sz
= sizeof(struct utsname
);
67 unsigned struct_stat_sz
= sizeof(struct stat
);
68 unsigned struct_rusage_sz
= sizeof(struct rusage
);
69 unsigned struct_tm_sz
= sizeof(struct tm
);
70 unsigned struct_passwd_sz
= sizeof(struct passwd
);
71 unsigned struct_group_sz
= sizeof(struct group
);
72 unsigned siginfo_t_sz
= sizeof(siginfo_t
);
73 unsigned struct_sigaction_sz
= sizeof(struct sigaction
);
74 unsigned struct_itimerval_sz
= sizeof(struct itimerval
);
75 unsigned pthread_t_sz
= sizeof(pthread_t
);
76 unsigned pthread_mutex_t_sz
= sizeof(pthread_mutex_t
);
77 unsigned pthread_cond_t_sz
= sizeof(pthread_cond_t
);
78 unsigned pid_t_sz
= sizeof(pid_t
);
79 unsigned timeval_sz
= sizeof(timeval
);
80 unsigned uid_t_sz
= sizeof(uid_t
);
81 unsigned gid_t_sz
= sizeof(gid_t
);
82 unsigned mbstate_t_sz
= sizeof(mbstate_t);
83 unsigned sigset_t_sz
= sizeof(sigset_t
);
84 unsigned struct_timezone_sz
= sizeof(struct timezone
);
85 unsigned struct_tms_sz
= sizeof(struct tms
);
86 unsigned struct_sched_param_sz
= sizeof(struct sched_param
);
87 unsigned struct_sockaddr_sz
= sizeof(struct sockaddr
);
88 unsigned struct_rlimit_sz
= sizeof(struct rlimit
);
89 unsigned struct_timespec_sz
= sizeof(struct timespec
);
90 unsigned struct_utimbuf_sz
= sizeof(struct utimbuf
);
91 unsigned struct_itimerspec_sz
= sizeof(struct itimerspec
);
92 unsigned struct_msqid_ds_sz
= sizeof(struct msqid_ds
);
93 unsigned struct_statvfs_sz
= sizeof(struct statvfs
);
95 const uptr sig_ign
= (uptr
)SIG_IGN
;
96 const uptr sig_dfl
= (uptr
)SIG_DFL
;
97 const uptr sig_err
= (uptr
)SIG_ERR
;
98 const uptr sa_siginfo
= (uptr
)SA_SIGINFO
;
100 int shmctl_ipc_stat
= (int)IPC_STAT
;
102 unsigned struct_utmp_sz
= sizeof(struct utmp
);
104 int map_fixed
= MAP_FIXED
;
106 int af_inet
= (int)AF_INET
;
107 int af_inet6
= (int)AF_INET6
;
109 uptr
__sanitizer_in_addr_sz(int af
) {
111 return sizeof(struct in_addr
);
112 else if (af
== AF_INET6
)
113 return sizeof(struct in6_addr
);
118 unsigned struct_ElfW_Phdr_sz
= sizeof(Elf_Phdr
);
120 int glob_nomatch
= GLOB_NOMATCH
;
121 int glob_altdirfunc
= GLOB_ALTDIRFUNC
;
123 unsigned path_max
= PATH_MAX
;
125 const int si_SEGV_MAPERR
= SEGV_MAPERR
;
126 const int si_SEGV_ACCERR
= SEGV_ACCERR
;
127 } // namespace __sanitizer
129 using namespace __sanitizer
;
131 COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t
) >= sizeof(pthread_attr_t
));
133 COMPILER_CHECK(sizeof(socklen_t
) == sizeof(unsigned));
134 CHECK_TYPE_SIZE(pthread_key_t
);
136 CHECK_TYPE_SIZE(dl_phdr_info
);
137 CHECK_SIZE_AND_OFFSET(dl_phdr_info
, dlpi_addr
);
138 CHECK_SIZE_AND_OFFSET(dl_phdr_info
, dlpi_name
);
139 CHECK_SIZE_AND_OFFSET(dl_phdr_info
, dlpi_phdr
);
140 CHECK_SIZE_AND_OFFSET(dl_phdr_info
, dlpi_phnum
);
142 CHECK_TYPE_SIZE(glob_t
);
143 CHECK_SIZE_AND_OFFSET(glob_t
, gl_pathc
);
144 CHECK_SIZE_AND_OFFSET(glob_t
, gl_pathv
);
145 CHECK_SIZE_AND_OFFSET(glob_t
, gl_offs
);
146 CHECK_SIZE_AND_OFFSET(glob_t
, gl_flags
);
147 CHECK_SIZE_AND_OFFSET(glob_t
, gl_closedir
);
148 CHECK_SIZE_AND_OFFSET(glob_t
, gl_readdir
);
149 CHECK_SIZE_AND_OFFSET(glob_t
, gl_opendir
);
150 CHECK_SIZE_AND_OFFSET(glob_t
, gl_lstat
);
151 CHECK_SIZE_AND_OFFSET(glob_t
, gl_stat
);
153 CHECK_TYPE_SIZE(addrinfo
);
154 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_flags
);
155 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_family
);
156 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_socktype
);
157 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_protocol
);
158 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_addrlen
);
159 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_addr
);
160 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_canonname
);
161 CHECK_SIZE_AND_OFFSET(addrinfo
, ai_next
);
163 CHECK_TYPE_SIZE(hostent
);
164 CHECK_SIZE_AND_OFFSET(hostent
, h_name
);
165 CHECK_SIZE_AND_OFFSET(hostent
, h_aliases
);
166 CHECK_SIZE_AND_OFFSET(hostent
, h_addrtype
);
167 CHECK_SIZE_AND_OFFSET(hostent
, h_length
);
168 CHECK_SIZE_AND_OFFSET(hostent
, h_addr_list
);
170 CHECK_TYPE_SIZE(iovec
);
171 CHECK_SIZE_AND_OFFSET(iovec
, iov_base
);
172 CHECK_SIZE_AND_OFFSET(iovec
, iov_len
);
174 CHECK_TYPE_SIZE(msghdr
);
175 CHECK_SIZE_AND_OFFSET(msghdr
, msg_name
);
176 CHECK_SIZE_AND_OFFSET(msghdr
, msg_namelen
);
177 CHECK_SIZE_AND_OFFSET(msghdr
, msg_iov
);
178 CHECK_SIZE_AND_OFFSET(msghdr
, msg_iovlen
);
179 CHECK_SIZE_AND_OFFSET(msghdr
, msg_control
);
180 CHECK_SIZE_AND_OFFSET(msghdr
, msg_controllen
);
181 CHECK_SIZE_AND_OFFSET(msghdr
, msg_flags
);
183 CHECK_TYPE_SIZE(cmsghdr
);
184 CHECK_SIZE_AND_OFFSET(cmsghdr
, cmsg_len
);
185 CHECK_SIZE_AND_OFFSET(cmsghdr
, cmsg_level
);
186 CHECK_SIZE_AND_OFFSET(cmsghdr
, cmsg_type
);
188 COMPILER_CHECK(sizeof(__sanitizer_dirent
) <= sizeof(dirent
));
189 CHECK_SIZE_AND_OFFSET(dirent
, d_fileno
);
190 CHECK_SIZE_AND_OFFSET(dirent
, d_off
);
191 CHECK_SIZE_AND_OFFSET(dirent
, d_reclen
);
193 CHECK_TYPE_SIZE(ifconf
);
194 CHECK_SIZE_AND_OFFSET(ifconf
, ifc_len
);
195 CHECK_SIZE_AND_OFFSET(ifconf
, ifc_ifcu
);
197 CHECK_TYPE_SIZE(pollfd
);
198 CHECK_SIZE_AND_OFFSET(pollfd
, fd
);
199 CHECK_SIZE_AND_OFFSET(pollfd
, events
);
200 CHECK_SIZE_AND_OFFSET(pollfd
, revents
);
202 CHECK_TYPE_SIZE(nfds_t
);
204 CHECK_TYPE_SIZE(sigset_t
);
206 COMPILER_CHECK(sizeof(__sanitizer_sigaction
) == sizeof(struct sigaction
));
207 // Can't write checks for sa_handler and sa_sigaction due to them being
208 // preprocessor macros.
209 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction
, sa_mask
);
212 CHECK_SIZE_AND_OFFSET(tm
, tm_sec
);
213 CHECK_SIZE_AND_OFFSET(tm
, tm_min
);
214 CHECK_SIZE_AND_OFFSET(tm
, tm_hour
);
215 CHECK_SIZE_AND_OFFSET(tm
, tm_mday
);
216 CHECK_SIZE_AND_OFFSET(tm
, tm_mon
);
217 CHECK_SIZE_AND_OFFSET(tm
, tm_year
);
218 CHECK_SIZE_AND_OFFSET(tm
, tm_wday
);
219 CHECK_SIZE_AND_OFFSET(tm
, tm_yday
);
220 CHECK_SIZE_AND_OFFSET(tm
, tm_isdst
);
221 CHECK_SIZE_AND_OFFSET(tm
, tm_gmtoff
);
222 CHECK_SIZE_AND_OFFSET(tm
, tm_zone
);
224 CHECK_TYPE_SIZE(ipc_perm
);
225 CHECK_SIZE_AND_OFFSET(ipc_perm
, cuid
);
226 CHECK_SIZE_AND_OFFSET(ipc_perm
, cgid
);
227 CHECK_SIZE_AND_OFFSET(ipc_perm
, uid
);
228 CHECK_SIZE_AND_OFFSET(ipc_perm
, gid
);
229 CHECK_SIZE_AND_OFFSET(ipc_perm
, mode
);
230 CHECK_SIZE_AND_OFFSET(ipc_perm
, seq
);
231 CHECK_SIZE_AND_OFFSET(ipc_perm
, key
);
233 CHECK_TYPE_SIZE(shmid_ds
);
234 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_perm
);
235 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_segsz
);
236 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_atime
);
237 CHECK_SIZE_AND_OFFSET(shmid_ds
, __shm_atimensec
);
238 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_dtime
);
239 CHECK_SIZE_AND_OFFSET(shmid_ds
, __shm_dtimensec
);
240 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_ctime
);
241 CHECK_SIZE_AND_OFFSET(shmid_ds
, __shm_ctimensec
);
242 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_cpid
);
243 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_lpid
);
244 CHECK_SIZE_AND_OFFSET(shmid_ds
, shm_nattch
);
246 CHECK_TYPE_SIZE(clock_t);
248 CHECK_TYPE_SIZE(ifaddrs
);
249 CHECK_SIZE_AND_OFFSET(ifaddrs
, ifa_next
);
250 CHECK_SIZE_AND_OFFSET(ifaddrs
, ifa_name
);
251 CHECK_SIZE_AND_OFFSET(ifaddrs
, ifa_addr
);
252 CHECK_SIZE_AND_OFFSET(ifaddrs
, ifa_netmask
);
253 // Compare against the union, because we can't reach into the union in a
258 CHECK_SIZE_AND_OFFSET(ifaddrs
, ifa_dstaddr
);
259 CHECK_SIZE_AND_OFFSET(ifaddrs
, ifa_data
);
261 CHECK_TYPE_SIZE(passwd
);
262 CHECK_SIZE_AND_OFFSET(passwd
, pw_name
);
263 CHECK_SIZE_AND_OFFSET(passwd
, pw_passwd
);
264 CHECK_SIZE_AND_OFFSET(passwd
, pw_uid
);
265 CHECK_SIZE_AND_OFFSET(passwd
, pw_gid
);
266 CHECK_SIZE_AND_OFFSET(passwd
, pw_dir
);
267 CHECK_SIZE_AND_OFFSET(passwd
, pw_shell
);
269 CHECK_SIZE_AND_OFFSET(passwd
, pw_gecos
);
271 CHECK_TYPE_SIZE(group
);
272 CHECK_SIZE_AND_OFFSET(group
, gr_name
);
273 CHECK_SIZE_AND_OFFSET(group
, gr_passwd
);
274 CHECK_SIZE_AND_OFFSET(group
, gr_gid
);
275 CHECK_SIZE_AND_OFFSET(group
, gr_mem
);
277 #endif // SANITIZER_OPENBSD