[clang] Handle __declspec() attributes in using
[llvm-project.git] / compiler-rt / lib / sanitizer_common / sanitizer_platform_limits_solaris.cpp
blobdad7bde1498a7a969d6276903aa4428d425aaa75
1 //===-- sanitizer_platform_limits_solaris.cpp -----------------------------===//
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.
11 // Sizes and layouts of platform-specific Solaris data structures.
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_platform.h"
16 #if SANITIZER_SOLARIS
17 #include <arpa/inet.h>
18 #include <dirent.h>
19 #include <glob.h>
20 #include <grp.h>
21 #include <ifaddrs.h>
22 #include <limits.h>
23 #include <link.h>
24 #include <net/if.h>
25 #include <net/route.h>
26 #include <netdb.h>
27 #include <netinet/ip_mroute.h>
28 #include <poll.h>
29 #include <pthread.h>
30 #include <pwd.h>
31 #include <rpc/xdr.h>
32 #include <semaphore.h>
33 #include <signal.h>
34 #include <stddef.h>
35 #include <sys/ethernet.h>
36 #include <sys/filio.h>
37 #include <sys/ipc.h>
38 #include <sys/mman.h>
39 #include <sys/mount.h>
40 #include <sys/mtio.h>
41 #include <sys/ptyvar.h>
42 #include <sys/resource.h>
43 #include <sys/shm.h>
44 #include <sys/socket.h>
45 #include <sys/sockio.h>
46 #include <sys/stat.h>
47 #include <sys/statfs.h>
48 #include <sys/statvfs.h>
49 #include <sys/time.h>
50 #include <sys/timeb.h>
51 #include <sys/times.h>
52 #include <sys/types.h>
53 #include <sys/utsname.h>
54 #include <termios.h>
55 #include <time.h>
56 #include <utmp.h>
57 #include <utmpx.h>
58 #include <wchar.h>
59 #include <wordexp.h>
61 // Include these after system headers to avoid name clashes and ambiguities.
62 #include "sanitizer_internal_defs.h"
63 #include "sanitizer_platform_limits_solaris.h"
65 namespace __sanitizer {
66 unsigned struct_utsname_sz = sizeof(struct utsname);
67 unsigned struct_stat_sz = sizeof(struct stat);
68 unsigned struct_stat64_sz = sizeof(struct stat64);
69 unsigned struct_rusage_sz = sizeof(struct rusage);
70 unsigned struct_tm_sz = sizeof(struct tm);
71 unsigned struct_passwd_sz = sizeof(struct passwd);
72 unsigned struct_group_sz = sizeof(struct group);
73 unsigned siginfo_t_sz = sizeof(siginfo_t);
74 unsigned struct_sigaction_sz = sizeof(struct sigaction);
75 unsigned struct_stack_t_sz = sizeof(stack_t);
76 unsigned struct_itimerval_sz = sizeof(struct itimerval);
77 unsigned pthread_t_sz = sizeof(pthread_t);
78 unsigned pthread_mutex_t_sz = sizeof(pthread_mutex_t);
79 unsigned pthread_cond_t_sz = sizeof(pthread_cond_t);
80 unsigned pid_t_sz = sizeof(pid_t);
81 unsigned timeval_sz = sizeof(timeval);
82 unsigned uid_t_sz = sizeof(uid_t);
83 unsigned gid_t_sz = sizeof(gid_t);
84 unsigned mbstate_t_sz = sizeof(mbstate_t);
85 unsigned sigset_t_sz = sizeof(sigset_t);
86 unsigned struct_timezone_sz = sizeof(struct timezone);
87 unsigned struct_tms_sz = sizeof(struct tms);
88 unsigned struct_sigevent_sz = sizeof(struct sigevent);
89 unsigned struct_sched_param_sz = sizeof(struct sched_param);
90 unsigned struct_statfs_sz = sizeof(struct statfs);
91 unsigned struct_sockaddr_sz = sizeof(struct sockaddr);
92 unsigned ucontext_t_sz(void *ctx) { return sizeof(ucontext_t); }
93 unsigned struct_timespec_sz = sizeof(struct timespec);
94 #if SANITIZER_SOLARIS32
95 unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
96 #endif
97 unsigned struct_statvfs_sz = sizeof(struct statvfs);
99 const uptr sig_ign = (uptr)SIG_IGN;
100 const uptr sig_dfl = (uptr)SIG_DFL;
101 const uptr sig_err = (uptr)SIG_ERR;
102 const uptr sa_siginfo = (uptr)SA_SIGINFO;
104 int shmctl_ipc_stat = (int)IPC_STAT;
106 unsigned struct_utmp_sz = sizeof(struct utmp);
107 unsigned struct_utmpx_sz = sizeof(struct utmpx);
109 int map_fixed = MAP_FIXED;
111 int af_inet = (int)AF_INET;
112 int af_inet6 = (int)AF_INET6;
114 uptr __sanitizer_in_addr_sz(int af) {
115 if (af == AF_INET)
116 return sizeof(struct in_addr);
117 else if (af == AF_INET6)
118 return sizeof(struct in6_addr);
119 else
120 return 0;
123 unsigned struct_ElfW_Phdr_sz = sizeof(ElfW(Phdr));
125 int glob_nomatch = GLOB_NOMATCH;
126 const int wordexp_wrde_dooffs = WRDE_DOOFFS;
128 unsigned path_max = PATH_MAX;
130 // ioctl arguments
131 unsigned struct_ifreq_sz = sizeof(struct ifreq);
132 unsigned struct_termios_sz = sizeof(struct termios);
133 unsigned struct_winsize_sz = sizeof(struct winsize);
135 unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req);
136 unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
138 const unsigned IOCTL_NOT_PRESENT = 0;
140 unsigned IOCTL_FIOASYNC = FIOASYNC;
141 unsigned IOCTL_FIOCLEX = FIOCLEX;
142 unsigned IOCTL_FIOGETOWN = FIOGETOWN;
143 unsigned IOCTL_FIONBIO = FIONBIO;
144 unsigned IOCTL_FIONCLEX = FIONCLEX;
145 unsigned IOCTL_FIOSETOWN = FIOSETOWN;
146 unsigned IOCTL_SIOCADDMULTI = SIOCADDMULTI;
147 unsigned IOCTL_SIOCATMARK = SIOCATMARK;
148 unsigned IOCTL_SIOCDELMULTI = SIOCDELMULTI;
149 unsigned IOCTL_SIOCGIFADDR = SIOCGIFADDR;
150 unsigned IOCTL_SIOCGIFBRDADDR = SIOCGIFBRDADDR;
151 unsigned IOCTL_SIOCGIFCONF = SIOCGIFCONF;
152 unsigned IOCTL_SIOCGIFDSTADDR = SIOCGIFDSTADDR;
153 unsigned IOCTL_SIOCGIFFLAGS = SIOCGIFFLAGS;
154 unsigned IOCTL_SIOCGIFMETRIC = SIOCGIFMETRIC;
155 unsigned IOCTL_SIOCGIFMTU = SIOCGIFMTU;
156 unsigned IOCTL_SIOCGIFNETMASK = SIOCGIFNETMASK;
157 unsigned IOCTL_SIOCGPGRP = SIOCGPGRP;
158 unsigned IOCTL_SIOCSIFADDR = SIOCSIFADDR;
159 unsigned IOCTL_SIOCSIFBRDADDR = SIOCSIFBRDADDR;
160 unsigned IOCTL_SIOCSIFDSTADDR = SIOCSIFDSTADDR;
161 unsigned IOCTL_SIOCSIFFLAGS = SIOCSIFFLAGS;
162 unsigned IOCTL_SIOCSIFMETRIC = SIOCSIFMETRIC;
163 unsigned IOCTL_SIOCSIFMTU = SIOCSIFMTU;
164 unsigned IOCTL_SIOCSIFNETMASK = SIOCSIFNETMASK;
165 unsigned IOCTL_SIOCSPGRP = SIOCSPGRP;
166 unsigned IOCTL_TIOCEXCL = TIOCEXCL;
167 unsigned IOCTL_TIOCGETD = TIOCGETD;
168 unsigned IOCTL_TIOCGPGRP = TIOCGPGRP;
169 unsigned IOCTL_TIOCGWINSZ = TIOCGWINSZ;
170 unsigned IOCTL_TIOCMBIC = TIOCMBIC;
171 unsigned IOCTL_TIOCMBIS = TIOCMBIS;
172 unsigned IOCTL_TIOCMGET = TIOCMGET;
173 unsigned IOCTL_TIOCMSET = TIOCMSET;
174 unsigned IOCTL_TIOCNOTTY = TIOCNOTTY;
175 unsigned IOCTL_TIOCNXCL = TIOCNXCL;
176 unsigned IOCTL_TIOCOUTQ = TIOCOUTQ;
177 unsigned IOCTL_TIOCPKT = TIOCPKT;
178 unsigned IOCTL_TIOCSCTTY = TIOCSCTTY;
179 unsigned IOCTL_TIOCSETD = TIOCSETD;
180 unsigned IOCTL_TIOCSPGRP = TIOCSPGRP;
181 unsigned IOCTL_TIOCSTI = TIOCSTI;
182 unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ;
184 unsigned IOCTL_MTIOCGET = MTIOCGET;
185 unsigned IOCTL_MTIOCTOP = MTIOCTOP;
187 const int si_SEGV_MAPERR = SEGV_MAPERR;
188 const int si_SEGV_ACCERR = SEGV_ACCERR;
189 } // namespace __sanitizer
191 using namespace __sanitizer;
193 COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
195 COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
196 CHECK_TYPE_SIZE(pthread_key_t);
198 // There are more undocumented fields in dl_phdr_info that we are not interested
199 // in.
200 COMPILER_CHECK(sizeof(__sanitizer_dl_phdr_info) <= sizeof(dl_phdr_info));
201 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr);
202 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
203 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
204 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
206 // There are additional fields we are not interested in.
207 COMPILER_CHECK(sizeof(__sanitizer_glob_t) <= sizeof(glob_t));
208 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
209 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
210 CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
212 CHECK_TYPE_SIZE(addrinfo);
213 CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags);
214 CHECK_SIZE_AND_OFFSET(addrinfo, ai_family);
215 CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype);
216 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
217 CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
218 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen);
219 CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname);
220 CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr);
222 CHECK_TYPE_SIZE(hostent);
223 CHECK_SIZE_AND_OFFSET(hostent, h_name);
224 CHECK_SIZE_AND_OFFSET(hostent, h_aliases);
225 CHECK_SIZE_AND_OFFSET(hostent, h_addrtype);
226 CHECK_SIZE_AND_OFFSET(hostent, h_length);
227 CHECK_SIZE_AND_OFFSET(hostent, h_addr_list);
229 CHECK_TYPE_SIZE(iovec);
230 CHECK_SIZE_AND_OFFSET(iovec, iov_base);
231 CHECK_SIZE_AND_OFFSET(iovec, iov_len);
233 CHECK_TYPE_SIZE(msghdr);
234 CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
235 CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
236 CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
237 CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
238 CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
239 CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
240 CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
242 CHECK_TYPE_SIZE(cmsghdr);
243 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
244 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
245 CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
247 COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
248 CHECK_SIZE_AND_OFFSET(dirent, d_ino);
249 CHECK_SIZE_AND_OFFSET(dirent, d_off);
250 CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
252 #if SANITIZER_SOLARIS32
253 COMPILER_CHECK(sizeof(__sanitizer_dirent64) <= sizeof(dirent64));
254 CHECK_SIZE_AND_OFFSET(dirent64, d_ino);
255 CHECK_SIZE_AND_OFFSET(dirent64, d_off);
256 CHECK_SIZE_AND_OFFSET(dirent64, d_reclen);
257 #endif
259 CHECK_TYPE_SIZE(ifconf);
260 CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
261 CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
263 CHECK_TYPE_SIZE(pollfd);
264 CHECK_SIZE_AND_OFFSET(pollfd, fd);
265 CHECK_SIZE_AND_OFFSET(pollfd, events);
266 CHECK_SIZE_AND_OFFSET(pollfd, revents);
268 CHECK_TYPE_SIZE(nfds_t);
270 CHECK_TYPE_SIZE(sigset_t);
272 COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction));
273 // Can't write checks for sa_handler and sa_sigaction due to them being
274 // preprocessor macros.
275 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
276 CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_flags);
278 CHECK_TYPE_SIZE(wordexp_t);
279 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
280 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
281 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
283 CHECK_TYPE_SIZE(tm);
284 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
285 CHECK_SIZE_AND_OFFSET(tm, tm_min);
286 CHECK_SIZE_AND_OFFSET(tm, tm_hour);
287 CHECK_SIZE_AND_OFFSET(tm, tm_mday);
288 CHECK_SIZE_AND_OFFSET(tm, tm_mon);
289 CHECK_SIZE_AND_OFFSET(tm, tm_year);
290 CHECK_SIZE_AND_OFFSET(tm, tm_wday);
291 CHECK_SIZE_AND_OFFSET(tm, tm_yday);
292 CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
294 CHECK_TYPE_SIZE(ether_addr);
296 CHECK_TYPE_SIZE(ipc_perm);
297 CHECK_SIZE_AND_OFFSET(ipc_perm, key);
298 CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
299 CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
300 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
301 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
302 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
303 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
305 CHECK_TYPE_SIZE(shmid_ds);
306 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);
307 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz);
308 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime);
309 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime);
310 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime);
311 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid);
312 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
313 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
315 CHECK_TYPE_SIZE(clock_t);
317 CHECK_TYPE_SIZE(ifaddrs);
318 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
319 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
320 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
321 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask);
322 // Compare against the union, because we can't reach into the union in a
323 // compliant way.
324 #ifdef ifa_dstaddr
325 #undef ifa_dstaddr
326 #endif
327 COMPILER_CHECK(sizeof(((__sanitizer_ifaddrs *)nullptr)->ifa_dstaddr) ==
328 sizeof(((ifaddrs *)nullptr)->ifa_ifu));
329 COMPILER_CHECK(offsetof(__sanitizer_ifaddrs, ifa_dstaddr) ==
330 offsetof(ifaddrs, ifa_ifu));
331 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
333 CHECK_TYPE_SIZE(timeb);
334 CHECK_SIZE_AND_OFFSET(timeb, time);
335 CHECK_SIZE_AND_OFFSET(timeb, millitm);
336 CHECK_SIZE_AND_OFFSET(timeb, timezone);
337 CHECK_SIZE_AND_OFFSET(timeb, dstflag);
339 CHECK_TYPE_SIZE(passwd);
340 CHECK_SIZE_AND_OFFSET(passwd, pw_name);
341 CHECK_SIZE_AND_OFFSET(passwd, pw_passwd);
342 CHECK_SIZE_AND_OFFSET(passwd, pw_uid);
343 CHECK_SIZE_AND_OFFSET(passwd, pw_gid);
344 CHECK_SIZE_AND_OFFSET(passwd, pw_dir);
345 CHECK_SIZE_AND_OFFSET(passwd, pw_shell);
347 CHECK_SIZE_AND_OFFSET(passwd, pw_gecos);
349 CHECK_TYPE_SIZE(group);
350 CHECK_SIZE_AND_OFFSET(group, gr_name);
351 CHECK_SIZE_AND_OFFSET(group, gr_passwd);
352 CHECK_SIZE_AND_OFFSET(group, gr_gid);
353 CHECK_SIZE_AND_OFFSET(group, gr_mem);
355 CHECK_TYPE_SIZE(XDR);
356 CHECK_SIZE_AND_OFFSET(XDR, x_op);
357 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
358 CHECK_SIZE_AND_OFFSET(XDR, x_public);
359 CHECK_SIZE_AND_OFFSET(XDR, x_private);
360 CHECK_SIZE_AND_OFFSET(XDR, x_base);
361 CHECK_SIZE_AND_OFFSET(XDR, x_handy);
362 COMPILER_CHECK(__sanitizer_XDR_ENCODE == XDR_ENCODE);
363 COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE);
364 COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
366 CHECK_TYPE_SIZE(sem_t);
368 #endif // SANITIZER_SOLARIS