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.
10//
11// Sizes and layouts of platform-specific Solaris data structures.
12//===----------------------------------------------------------------------===//
13
14#include "sanitizer_platform.h"
15
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>
60
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"
64
65namespace __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);
98
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;
103
104 int shmctl_ipc_stat = (int)IPC_STAT;
105
106 unsigned struct_utmp_sz = sizeof(struct utmp);
107 unsigned struct_utmpx_sz = sizeof(struct utmpx);
108
109 int map_fixed = MAP_FIXED;
110
111 int af_inet = (int)AF_INET;
112 int af_inet6 = (int)AF_INET6;
113
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;
121 }
122
123 unsigned struct_ElfW_Phdr_sz = sizeof(ElfW(Phdr));
124
125 int glob_nomatch = GLOB_NOMATCH;
126 const int wordexp_wrde_dooffs = WRDE_DOOFFS;
127
128 unsigned path_max = PATH_MAX;
129
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);
134
135 unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req);
136 unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
137
138 const unsigned IOCTL_NOT_PRESENT = 0;
139
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;
183
184 unsigned IOCTL_MTIOCGET = MTIOCGET;
185 unsigned IOCTL_MTIOCTOP = MTIOCTOP;
186
187 const int si_SEGV_MAPERR = SEGV_MAPERR;
188 const int si_SEGV_ACCERR = SEGV_ACCERR;
189} // namespace __sanitizer
190
191using namespace __sanitizer;
192
193COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
194
195COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
196CHECK_TYPE_SIZE(pthread_key_t);
197
198// There are more undocumented fields in dl_phdr_info that we are not interested
199// in.
200COMPILER_CHECK(sizeof(__sanitizer_dl_phdr_info) <= sizeof(dl_phdr_info));
201CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr);
202CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name);
203CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
204CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
205
206// There are additional fields we are not interested in.
207COMPILER_CHECK(sizeof(__sanitizer_glob_t) <= sizeof(glob_t));
208CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
209CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
210CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
211
212CHECK_TYPE_SIZE(addrinfo);
213CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags);
214CHECK_SIZE_AND_OFFSET(addrinfo, ai_family);
215CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype);
216CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
217CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol);
218CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen);
219CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname);
220CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr);
221
222CHECK_TYPE_SIZE(hostent);
223CHECK_SIZE_AND_OFFSET(hostent, h_name);
224CHECK_SIZE_AND_OFFSET(hostent, h_aliases);
225CHECK_SIZE_AND_OFFSET(hostent, h_addrtype);
226CHECK_SIZE_AND_OFFSET(hostent, h_length);
227CHECK_SIZE_AND_OFFSET(hostent, h_addr_list);
228
229CHECK_TYPE_SIZE(iovec);
230CHECK_SIZE_AND_OFFSET(iovec, iov_base);
231CHECK_SIZE_AND_OFFSET(iovec, iov_len);
232
233CHECK_TYPE_SIZE(msghdr);
234CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
235CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
236CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
237CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
238CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
239CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
240CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
241
242CHECK_TYPE_SIZE(cmsghdr);
243CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
244CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
245CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
246
247COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
248CHECK_SIZE_AND_OFFSET(dirent, d_ino);
249CHECK_SIZE_AND_OFFSET(dirent, d_off);
250CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
251
252#if SANITIZER_SOLARIS32
253COMPILER_CHECK(sizeof(__sanitizer_dirent64) <= sizeof(dirent64));
254CHECK_SIZE_AND_OFFSET(dirent64, d_ino);
255CHECK_SIZE_AND_OFFSET(dirent64, d_off);
256CHECK_SIZE_AND_OFFSET(dirent64, d_reclen);
257#endif
258
259CHECK_TYPE_SIZE(ifconf);
260CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
261CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
262
263CHECK_TYPE_SIZE(pollfd);
264CHECK_SIZE_AND_OFFSET(pollfd, fd);
265CHECK_SIZE_AND_OFFSET(pollfd, events);
266CHECK_SIZE_AND_OFFSET(pollfd, revents);
267
268CHECK_TYPE_SIZE(nfds_t);
269
270CHECK_TYPE_SIZE(sigset_t);
271
272COMPILER_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.
275CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
276CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_flags);
277
278CHECK_TYPE_SIZE(wordexp_t);
279CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
280CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
281CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
282
283CHECK_TYPE_SIZE(tm);
284CHECK_SIZE_AND_OFFSET(tm, tm_sec);
285CHECK_SIZE_AND_OFFSET(tm, tm_min);
286CHECK_SIZE_AND_OFFSET(tm, tm_hour);
287CHECK_SIZE_AND_OFFSET(tm, tm_mday);
288CHECK_SIZE_AND_OFFSET(tm, tm_mon);
289CHECK_SIZE_AND_OFFSET(tm, tm_year);
290CHECK_SIZE_AND_OFFSET(tm, tm_wday);
291CHECK_SIZE_AND_OFFSET(tm, tm_yday);
292CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
293
294CHECK_TYPE_SIZE(ether_addr);
295
296CHECK_TYPE_SIZE(ipc_perm);
297CHECK_SIZE_AND_OFFSET(ipc_perm, key);
298CHECK_SIZE_AND_OFFSET(ipc_perm, seq);
299CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
300CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
301CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
302CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
303CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
304
305CHECK_TYPE_SIZE(shmid_ds);
306CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);
307CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz);
308CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime);
309CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime);
310CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime);
311CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid);
312CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
313CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
314
315CHECK_TYPE_SIZE(clock_t);
316
317CHECK_TYPE_SIZE(ifaddrs);
318CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
319CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
320CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr);
321CHECK_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
327COMPILER_CHECK(sizeof(((__sanitizer_ifaddrs *)nullptr)->ifa_dstaddr) ==
328 sizeof(((ifaddrs *)nullptr)->ifa_ifu));
329COMPILER_CHECK(offsetof(__sanitizer_ifaddrs, ifa_dstaddr) ==
330 offsetof(ifaddrs, ifa_ifu));
331CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
332
333CHECK_TYPE_SIZE(timeb);
334CHECK_SIZE_AND_OFFSET(timeb, time);
335CHECK_SIZE_AND_OFFSET(timeb, millitm);
336CHECK_SIZE_AND_OFFSET(timeb, timezone);
337CHECK_SIZE_AND_OFFSET(timeb, dstflag);
338
339CHECK_TYPE_SIZE(passwd);
340CHECK_SIZE_AND_OFFSET(passwd, pw_name);
341CHECK_SIZE_AND_OFFSET(passwd, pw_passwd);
342CHECK_SIZE_AND_OFFSET(passwd, pw_uid);
343CHECK_SIZE_AND_OFFSET(passwd, pw_gid);
344CHECK_SIZE_AND_OFFSET(passwd, pw_dir);
345CHECK_SIZE_AND_OFFSET(passwd, pw_shell);
346
347CHECK_SIZE_AND_OFFSET(passwd, pw_gecos);
348
349CHECK_TYPE_SIZE(group);
350CHECK_SIZE_AND_OFFSET(group, gr_name);
351CHECK_SIZE_AND_OFFSET(group, gr_passwd);
352CHECK_SIZE_AND_OFFSET(group, gr_gid);
353CHECK_SIZE_AND_OFFSET(group, gr_mem);
354
355CHECK_TYPE_SIZE(XDR);
356CHECK_SIZE_AND_OFFSET(XDR, x_op);
357CHECK_SIZE_AND_OFFSET(XDR, x_ops);
358CHECK_SIZE_AND_OFFSET(XDR, x_public);
359CHECK_SIZE_AND_OFFSET(XDR, x_private);
360CHECK_SIZE_AND_OFFSET(XDR, x_base);
361CHECK_SIZE_AND_OFFSET(XDR, x_handy);
362COMPILER_CHECK(__sanitizer_XDR_ENCODE == XDR_ENCODE);
363COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE);
364COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
365
366CHECK_TYPE_SIZE(sem_t);
367
368#endif // SANITIZER_SOLARIS
369

source code of compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.cpp