d: Fix ICE on explicit immutable struct import [PR108877]
[official-gcc.git] / libgo / sysinfo.c
blob336a5983750a43d2151b6d4907c78537bf36abfa
1 /* sysinfo.c -- input for mksysinfo.sh
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 /* This file is passed to GCC with the -fdump-go-spec option to
8 generate a Go version of the system information. */
10 #include "config.h"
12 #include <stddef.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include <dirent.h>
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <ucontext.h>
20 #include <netinet/in.h>
21 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
22 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
23 && !_XOPEN_SOURCE.
24 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
25 <sys/ttold.h> does so unconditionally. */
26 #ifdef __sgi__
27 #include <sys/bsd_types.h>
28 #include <sys/ttold.h>
29 #endif
30 #include <netinet/tcp.h>
31 #if defined(HAVE_NETINET_IN_SYSTM_H)
32 #include <netinet/in_systm.h>
33 #endif
34 #if defined(HAVE_NETINET_IP_H)
35 #include <netinet/ip.h>
36 #endif
37 #if defined(HAVE_NETINET_IP_MROUTE_H)
38 #include <netinet/ip_mroute.h>
39 #endif
40 #if defined(HAVE_NETINET_IF_ETHER_H)
41 #include <netinet/if_ether.h>
42 #endif
43 #include <signal.h>
44 #include <sys/ioctl.h>
45 #include <termios.h>
46 #if defined(HAVE_SYSCALL_H)
47 #include <syscall.h>
48 #endif
49 #if defined(HAVE_SYS_SYSCALL_H)
50 #include <sys/syscall.h>
51 #endif
52 #if defined(HAVE_SYS_SYSCTL_H)
53 #include <sys/sysctl.h>
54 #endif
55 #if defined(HAVE_SYS_EPOLL_H)
56 #include <sys/epoll.h>
57 #endif
58 #if defined(HAVE_SYS_EVENT_H)
59 #include <sys/event.h>
60 #endif
61 #if defined(HAVE_SYS_FILE_H)
62 #include <sys/file.h>
63 #endif
64 #if defined(HAVE_SYS_MMAN_H)
65 #include <sys/mman.h>
66 #endif
67 #if defined(HAVE_SYS_PRCTL_H)
68 #include <sys/prctl.h>
69 #endif
70 #if defined(HAVE_SYS_PTRACE_H)
71 #include <sys/ptrace.h>
72 #endif
73 #include <sys/resource.h>
74 #include <sys/uio.h>
75 #include <sys/socket.h>
76 #include <sys/stat.h>
77 #include <sys/time.h>
78 #include <sys/times.h>
79 #include <sys/wait.h>
80 #include <sys/un.h>
81 #if defined(HAVE_SYS_USER_H)
82 #include <sys/user.h>
83 #endif
84 #if defined(HAVE_SYS_UTSNAME_H)
85 #include <sys/utsname.h>
86 #endif
87 #if defined(HAVE_SYS_SELECT_H)
88 #include <sys/select.h>
89 #endif
90 #include <time.h>
91 #include <unistd.h>
92 #include <netdb.h>
93 #include <pwd.h>
94 #include <grp.h>
95 #if defined(HAVE_LINUX_FILTER_H)
96 #include <linux/filter.h>
97 #endif
98 #if defined(HAVE_LINUX_IF_ADDR_H)
99 #include <linux/if_addr.h>
100 #endif
101 #if defined(HAVE_LINUX_IF_ETHER_H)
102 #include <linux/if_ether.h>
103 #endif
104 #if defined(HAVE_LINUX_IF_TUN_H)
105 #include <linux/if_tun.h>
106 #endif
107 #if defined(HAVE_LINUX_NETLINK_H)
108 #include <linux/netlink.h>
109 #endif
110 #if defined(HAVE_LINUX_PTRACE_H)
111 /* Avoid https://sourceware.org/bugzilla/show_bug.cgi?id=762 . */
112 #define ia64_fpreg pt_ia64_fpreg
113 #define pt_all_user_regs pt_ia64_all_user_regs
114 /* Avoid redefinition of ptrace_peeksiginfo from <sys/ptrace.h>.
115 https://gcc.gnu.org/PR81324 . */
116 #define ptrace_peeksiginfo_args ignore_ptrace_peeksiginfo_args
117 #include <linux/ptrace.h>
118 #undef ia64_fpreg
119 #undef pt_all_user_regs
120 #undef ptrace_peeksiginfo_args
121 #endif
122 #if defined(HAVE_LINUX_RTNETLINK_H)
123 #include <linux/rtnetlink.h>
124 #endif
125 #if defined(HAVE_NET_BPF_H)
126 #include <net/bpf.h>
127 #endif
128 #if defined(HAVE_NET_IF_H)
129 #include <net/if.h>
130 #endif
131 #if defined(HAVE_NET_IF_ARP_H)
132 #include <net/if_arp.h>
133 #endif
134 #if defined(HAVE_NET_ROUTE_H)
135 #include <net/route.h>
136 #endif
137 #if defined (HAVE_NETPACKET_PACKET_H)
138 #include <netpacket/packet.h>
139 #endif
140 #if defined(HAVE_SYS_MOUNT_H)
141 #include <sys/mount.h>
142 #endif
143 #if defined(HAVE_SYS_VFS_H)
144 #include <sys/vfs.h>
145 #endif
146 #if defined(HAVE_STATFS_H)
147 #include <sys/statfs.h>
148 #endif
149 #if defined(HAVE_SYS_TIMEX_H)
150 #include <sys/timex.h>
151 #endif
152 #if defined(HAVE_SYS_SYSINFO_H)
153 #include <sys/sysinfo.h>
154 #endif
155 #if defined(HAVE_UTIME_H)
156 #include <utime.h>
157 #endif
158 #if defined(HAVE_LINUX_ETHER_H)
159 #include <linux/ether.h>
160 #endif
161 #if defined(HAVE_LINUX_REBOOT_H)
162 #include <linux/reboot.h>
163 #endif
164 #if defined(HAVE_SYS_INOTIFY_H)
165 #include <sys/inotify.h>
166 #endif
167 #if defined(HAVE_NETINET_ICMP6_H)
168 #include <netinet/icmp6.h>
169 #endif
170 #if defined(HAVE_SCHED_H)
171 #include <sched.h>
172 #endif
173 #if defined(HAVE_SEMAPHORE_H)
174 #include <semaphore.h>
175 #endif
176 #if defined(HAVE_PORT_H)
177 #include <port.h>
178 #endif
179 #if defined(HAVE_LWP_H)
180 #include <lwp.h>
181 #endif
183 #ifdef USE_LIBFFI
184 #include "ffi.h"
185 #endif
187 /* Constants that may only be defined as expressions on some systems,
188 expressions too complex for -fdump-go-spec to handle. These are
189 handled specially below. */
190 enum {
191 #ifdef TIOCGWINSZ
192 TIOCGWINSZ_val = TIOCGWINSZ,
193 #endif
194 #ifdef TIOCSWINSZ
195 TIOCSWINSZ_val = TIOCSWINSZ,
196 #endif
197 #ifdef TIOCNOTTY
198 TIOCNOTTY_val = TIOCNOTTY,
199 #endif
200 #ifdef TIOCSCTTY
201 TIOCSCTTY_val = TIOCSCTTY,
202 #endif
203 #ifdef TIOCGPGRP
204 TIOCGPGRP_val = TIOCGPGRP,
205 #endif
206 #ifdef TIOCSPGRP
207 TIOCSPGRP_val = TIOCSPGRP,
208 #endif
209 #ifdef TIOCGPTN
210 TIOCGPTN_val = TIOCGPTN,
211 #endif
212 #ifdef TIOCSPTLCK
213 TIOCSPTLCK_val = TIOCSPTLCK,
214 #endif
215 #ifdef TIOCGDEV
216 TIOCGDEV_val = TIOCGDEV,
217 #endif
218 #ifdef TIOCSIG
219 TIOCSIG_val = TIOCSIG,
220 #endif
221 #ifdef TCGETS
222 TCGETS_val = TCGETS,
223 #endif
224 #ifdef TCSETS
225 TCSETS_val = TCSETS,
226 #endif
227 #ifdef TUNSETIFF
228 TUNSETIFF_val = TUNSETIFF,
229 #endif
230 #ifdef TUNSETNOCSUM
231 TUNSETNOCSUM_val = TUNSETNOCSUM,
232 #endif
233 #ifdef TUNSETDEBUG
234 TUNSETDEBUG_val = TUNSETDEBUG,
235 #endif
236 #ifdef TUNSETPERSIST
237 TUNSETPERSIST_val = TUNSETPERSIST,
238 #endif
239 #ifdef TUNSETOWNER
240 TUNSETOWNER_val = TUNSETOWNER,
241 #endif
242 #ifdef TUNSETLINK
243 TUNSETLINK_val = TUNSETLINK,
244 #endif
245 #ifdef TUNSETGROUP
246 TUNSETGROUP_val = TUNSETGROUP,
247 #endif
248 #ifdef TUNGETFEATURES
249 TUNGETFEATURES_val = TUNGETFEATURES,
250 #endif
251 #ifdef TUNSETOFFLOAD
252 TUNSETOFFLOAD_val = TUNSETOFFLOAD,
253 #endif
254 #ifdef TUNSETTXFILTER
255 TUNSETTXFILTER_val = TUNSETTXFILTER,
256 #endif
257 #ifdef TUNGETIFF
258 TUNGETIFF_val = TUNGETIFF,
259 #endif
260 #ifdef TUNGETSNDBUF
261 TUNGETSNDBUF_val = TUNGETSNDBUF,
262 #endif
263 #ifdef TUNSETSNDBUF
264 TUNSETSNDBUF_val = TUNSETSNDBUF,
265 #endif
266 #ifdef TUNATTACHFILTER
267 TUNATTACHFILTER_val = TUNATTACHFILTER,
268 #endif
269 #ifdef TUNDETACHFILTER
270 TUNDETACHFILTER_val = TUNDETACHFILTER,
271 #endif
272 #ifdef TUNGETVNETHDRSZ
273 TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ,
274 #endif
275 #ifdef TUNSETVNETHDRSZ
276 TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ,
277 #endif
278 #ifdef TUNSETQUEUE
279 TUNSETQUEUE_val = TUNSETQUEUE,
280 #endif
281 #ifdef TUNSETIFINDEX
282 TUNSETIFINDEX_val = TUNSETIFINDEX,
283 #endif
284 #ifdef TUNGETFILTER
285 TUNGETFILTER_val = TUNGETFILTER,
286 #endif
287 #ifdef NLA_HDRLEN
288 NLA_HDRLEN_val = NLA_HDRLEN,
289 #endif
290 #ifdef BIOCFLUSH
291 BIOCFLUSH_val = BIOCFLUSH,
292 #endif
293 #ifdef BIOCGBLEN
294 BIOCGBLEN_val = BIOCGBLEN,
295 #endif
296 #ifdef BIOCGDLT
297 BIOCGDLT_val = BIOCGDLT,
298 #endif
299 #ifdef BIOCGETIF
300 BIOCGETIF_val = BIOCGETIF,
301 #endif
302 #ifdef BIOCGHDRCMPLT
303 BIOCGHDRCMPLT_val = BIOCGHDRCMPLT,
304 #endif
305 #ifdef BIOCGRTIMEOUT
306 BIOCGRTIMEOUT_val = BIOCGRTIMEOUT,
307 #endif
308 #ifdef BIOCGSTATS
309 BIOCGSTATS_val = BIOCGSTATS,
310 #endif
311 #ifdef BIOCIMMEDIATE
312 BIOCIMMEDIATE_val = BIOCIMMEDIATE,
313 #endif
314 #ifdef BIOCPROMISC
315 BIOCPROMISC_val = BIOCPROMISC,
316 #endif
317 #ifdef BIOCSBLEN
318 BIOCSBLEN_val = BIOCSBLEN,
319 #endif
320 #ifdef BIOCSDLT
321 BIOCSDLT_val = BIOCSDLT,
322 #endif
323 #ifdef BIOCSETF
324 BIOCSETF_val = BIOCSETF,
325 #endif
326 #ifdef BIOCSETIF
327 BIOCSETIF_val = BIOCSETIF,
328 #endif
329 #ifdef BIOCSHDRCMPLT
330 BIOCSHDRCMPLT_val = BIOCSHDRCMPLT,
331 #endif
332 #ifdef BIOCSRTIMEOUT
333 BIOCSRTIMEOUT_val = BIOCSRTIMEOUT,
334 #endif
335 #ifdef BIOCVERSION
336 BIOCVERSION_val = BIOCVERSION,
337 #endif
338 #ifdef SO_RCVTIMEO
339 SO_RCVTIMEO_val = SO_RCVTIMEO,
340 #endif
343 // SIOCGIFMTU can't be added in the above enum as it might
344 // be signed in some OSes.
345 #ifdef SIOCGIFMTU
346 enum {
347 SIOCGIFMTU_val = SIOCGIFMTU,
349 #endif
351 #if defined(HAVE_SYS_EPOLL_H)
352 enum {
353 epoll_data_offset = offsetof(struct epoll_event, data)
355 #endif
357 // The following section introduces explicit references to types and
358 // constants of interest to support bootstrapping libgo using a
359 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
360 // DWARF-based tools. This process is made more difficult due to the
361 // fact that clang tries hard to omit types/constants from DWARF if it
362 // can't find explicit references to them, so here we make sure that
363 // key items are mentioned in ways that will force them into the
364 // generated DWARF.
366 #if defined(__clang__)
368 // Make a reference to a type
369 #define TREF(typ) typ typ ## ref
371 // Make a reference to an opaque type
372 #define OTREF(typ) typ *typ ## ref
374 // Make a reference to a struct tag
375 #define SREF(stag) struct stag stag ## ref
377 // Make a reference to an enum literal
378 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
380 //......................................................................
382 // From dirent.h
383 SREF(dirent);
384 SREF(dirent64);
385 OTREF(DIR);
386 EREF(DT_UNKNOWN);
388 // From fcntl.h
389 SREF(flock);
390 SREF(flock64);
392 // From ffi headers
393 SREF(_ffi_type);
394 TREF(ffi_cif);
395 TREF(ffi_abi);
396 TREF(ffi_status);
397 EREF(FFI_OK);
399 // From grp.h
400 SREF(group);
402 #if defined(HAVE_LINUX_FILTER_H)
403 // From linux/filter.h
404 SREF(sock_filter);
405 SREF(sock_fprog);
406 #endif
408 // From linux/if.h
409 EREF(IFF_UP);
411 #if defined(HAVE_LINUX_IF_ADDR_H)
412 // From linux/if_addr.h
413 SREF(ifaddrmsg);
414 EREF(IFA_ADDRESS);
415 #endif
417 #if defined(HAVE_LINUX_RTNETLINK_H)
418 // From linux/if_link.h
419 EREF(IFLA_ADDRESS);
420 #endif
422 // From in.h, in6.h, icmp6.h
423 SREF(ip_mreq);
424 SREF(ip_mreqn);
425 SREF(ipv6_mreq);
426 SREF(ip6_mtuinfo);
427 SREF(icmp6_filter);
428 SREF(in_pktinfo);
429 EREF(IPPROTO_TCP);
431 #if defined(HAVE_LINUX_RTNETLINK_H)
432 // From linux/rtnetlink.h
433 SREF(rtgenmsg);
434 SREF(rtmsg);
435 SREF(ifinfomsg);
436 SREF(rtattr);
437 SREF(rtnexthop);
438 EREF(RTM_BASE);
439 EREF(RTN_UNSPEC);
440 #endif
442 // From netdb.h
443 SREF(addrinfo);
445 // From netlink.h
446 SREF(nlattr);
447 SREF(nlmsgerr);
449 // From pthread.h and related
450 TREF(pthread_attr_t);
451 TREF(pthread_t);
452 TREF(pthread_mutex_t);
453 TREF(pthread_mutexattr_t);
455 // From pwd.h
456 SREF(passwd);
458 // From signal.h and related
459 TREF(sigset_t);
460 TREF(siginfo_t);
461 TREF(stack_t);
462 SREF(sigaction);
463 SREF(sigstack);
464 EREF(SI_USER);
465 EREF(FPE_INTOVF);
466 EREF(BUS_ADRALN);
467 EREF(SS_ONSTACK);
468 EREF(SEGV_MAPERR);
470 // From stat.h
471 SREF(stat64);
473 // From statfs.h
474 SREF(statfs);
475 SREF(statfs64);
477 // From sysinfo.h
478 SREF(sysinfo);
480 // From <sys/epoll.h>
481 #if defined(HAVE_SYS_EPOLL_H)
482 SREF(epoll_event);
483 EREF(EPOLLIN);
484 EREF(epoll_data_offset);
485 #endif
487 #if defined(HAVE_SYS_MOUNT_H)
488 // From sys/mount.h
489 EREF(MS_PRIVATE);
490 EREF(MNT_FORCE);
491 #endif
493 #if defined(HAVE_SYS_PTRACE_H)
494 // From <sys/ptrace.h>
495 #if defined (__aarch64__)
496 SREF(user_pt_regs);
497 #else
498 SREF(pt_regs);
499 #endif
500 EREF(PTRACE_PEEKTEXT);
501 #endif
503 // From sys/resource.h
504 SREF(rusage);
505 SREF(rlimit64);
506 EREF(RLIMIT_NOFILE);
507 EREF(PRIO_USER);
508 EREF(RUSAGE_SELF);
510 // From sys/select.h
511 TREF(fd_set);
513 // From sys/socket.h
514 SREF(msghdr);
515 SREF(cmsghdr);
516 SREF(ucred);
517 EREF(MSG_OOB);
518 EREF(SCM_RIGHTS);
519 EREF(SOCK_RAW);
520 EREF(SHUT_RD);
522 // From sys/time.h and sys/times.h
523 SREF(timespec);
524 SREF(timeval);
525 SREF(itimerval);
526 SREF(tms);
527 EREF(ITIMER_PROF);
529 #if defined(HAVE_SYS_TIMEX_H)
530 // From sys/timex.h
531 SREF(timex);
532 #endif
534 // From sys/types.h
535 TREF(pid_t);
536 TREF(off_t);
537 TREF(loff_t);
538 TREF(size_t);
539 TREF(ssize_t);
540 TREF(mode_t);
541 TREF(dev_t);
542 TREF(time_t);
544 // From sys/ucontext.h
545 TREF(ucontext_t);
547 #if defined(HAVE_SYS_USER_H)
548 // From sys/user.h
549 SREF(user_regs_struct);
550 #endif
552 #if defined(HAVE_SYS_UTSNAME_H)
553 // From sys/utsname.h
554 SREF(utsname);
555 #endif
557 // From termios.h
558 SREF(termios);
560 // From uio.h
561 SREF(iovec);
563 // From utime.h
564 SREF(utimbuf);
566 // From unistd.h
567 EREF(_PC_NAME_MAX);
568 EREF(_SC_GETPW_R_SIZE_MAX);
570 #endif // clang