testsuite: Add test for r11-4123
[official-gcc.git] / libgo / sysinfo.c
blob180f5c31d742752719130aa85f3bebcdc411c92e
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 #if !defined(SYS_timer_settime) && defined(SYS_timer_settime32)
358 // musl defines SYS_timer_settim32 on 32-bit systems.
359 #define SYS_timer_settime SYS_timer_settime32
360 #endif
362 #if defined(HAVE_LOFF_T)
363 // loff_t can be defined as a macro; for -fgo-dump-spec make sure we
364 // see a typedef.
365 typedef loff_t libgo_loff_t_type;
366 #endif
368 #if defined(HAVE_OFF64_T)
369 typedef off64_t libgo_off_t_type;
370 #else
371 typedef off_t libgo_off_t_type;
372 #endif
374 // The following section introduces explicit references to types and
375 // constants of interest to support bootstrapping libgo using a
376 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
377 // DWARF-based tools. This process is made more difficult due to the
378 // fact that clang tries hard to omit types/constants from DWARF if it
379 // can't find explicit references to them, so here we make sure that
380 // key items are mentioned in ways that will force them into the
381 // generated DWARF.
383 #if defined(__clang__)
385 // Make a reference to a type
386 #define TREF(typ) typ typ ## ref
388 // Make a reference to an opaque type
389 #define OTREF(typ) typ *typ ## ref
391 // Make a reference to a struct tag
392 #define SREF(stag) struct stag stag ## ref
394 // Make a reference to an enum literal
395 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
397 //......................................................................
399 // From dirent.h
400 SREF(dirent);
401 SREF(dirent64);
402 OTREF(DIR);
403 EREF(DT_UNKNOWN);
405 // From fcntl.h
406 SREF(flock);
407 SREF(flock64);
409 // From ffi headers
410 SREF(_ffi_type);
411 TREF(ffi_cif);
412 TREF(ffi_abi);
413 TREF(ffi_status);
414 EREF(FFI_OK);
416 // From grp.h
417 SREF(group);
419 #if defined(HAVE_LINUX_FILTER_H)
420 // From linux/filter.h
421 SREF(sock_filter);
422 SREF(sock_fprog);
423 #endif
425 // From linux/if.h
426 EREF(IFF_UP);
428 #if defined(HAVE_LINUX_IF_ADDR_H)
429 // From linux/if_addr.h
430 SREF(ifaddrmsg);
431 EREF(IFA_ADDRESS);
432 #endif
434 #if defined(HAVE_LINUX_RTNETLINK_H)
435 // From linux/if_link.h
436 EREF(IFLA_ADDRESS);
437 #endif
439 // From in.h, in6.h, icmp6.h
440 SREF(ip_mreq);
441 SREF(ip_mreqn);
442 SREF(ipv6_mreq);
443 SREF(ip6_mtuinfo);
444 SREF(icmp6_filter);
445 SREF(in_pktinfo);
446 EREF(IPPROTO_TCP);
448 #if defined(HAVE_LINUX_RTNETLINK_H)
449 // From linux/rtnetlink.h
450 SREF(rtgenmsg);
451 SREF(rtmsg);
452 SREF(ifinfomsg);
453 SREF(rtattr);
454 SREF(rtnexthop);
455 EREF(RTM_BASE);
456 EREF(RTN_UNSPEC);
457 #endif
459 // From netdb.h
460 SREF(addrinfo);
462 // From netlink.h
463 SREF(nlattr);
464 SREF(nlmsgerr);
466 // From pthread.h and related
467 TREF(pthread_attr_t);
468 TREF(pthread_t);
469 TREF(pthread_mutex_t);
470 TREF(pthread_mutexattr_t);
472 // From pwd.h
473 SREF(passwd);
475 // From signal.h and related
476 TREF(sigset_t);
477 TREF(siginfo_t);
478 TREF(stack_t);
479 SREF(sigaction);
480 SREF(sigstack);
481 EREF(SI_USER);
482 EREF(FPE_INTOVF);
483 EREF(BUS_ADRALN);
484 EREF(SS_ONSTACK);
485 EREF(SEGV_MAPERR);
487 // From stat.h
488 SREF(stat64);
490 // From statfs.h
491 SREF(statfs);
492 SREF(statfs64);
494 // From sysinfo.h
495 SREF(sysinfo);
497 // From <sys/epoll.h>
498 #if defined(HAVE_SYS_EPOLL_H)
499 SREF(epoll_event);
500 EREF(EPOLLIN);
501 EREF(epoll_data_offset);
502 #endif
504 #if defined(HAVE_SYS_MOUNT_H)
505 // From sys/mount.h
506 EREF(MS_PRIVATE);
507 EREF(MNT_FORCE);
508 #endif
510 #if defined(HAVE_SYS_PTRACE_H)
511 // From <sys/ptrace.h>
512 #if defined (__aarch64__)
513 SREF(user_pt_regs);
514 #else
515 SREF(pt_regs);
516 #endif
517 EREF(PTRACE_PEEKTEXT);
518 #endif
520 // From sys/resource.h
521 SREF(rusage);
522 SREF(rlimit64);
523 EREF(RLIMIT_NOFILE);
524 EREF(PRIO_USER);
525 EREF(RUSAGE_SELF);
527 // From sys/select.h
528 TREF(fd_set);
530 // From sys/socket.h
531 SREF(msghdr);
532 SREF(cmsghdr);
533 SREF(ucred);
534 EREF(MSG_OOB);
535 EREF(SCM_RIGHTS);
536 EREF(SOCK_RAW);
537 EREF(SHUT_RD);
539 // From sys/time.h and sys/times.h
540 SREF(timespec);
541 SREF(timeval);
542 SREF(itimerval);
543 SREF(tms);
544 EREF(ITIMER_PROF);
546 #if defined(HAVE_SYS_TIMEX_H)
547 // From sys/timex.h
548 SREF(timex);
549 #endif
551 // From sys/types.h
552 TREF(pid_t);
553 TREF(off_t);
554 TREF(libgo_loff_t_type);
555 TREF(libgo_off_t_type);
556 TREF(size_t);
557 TREF(ssize_t);
558 TREF(mode_t);
559 TREF(dev_t);
560 TREF(time_t);
562 // From sys/ucontext.h
563 TREF(ucontext_t);
565 #if defined(HAVE_SYS_USER_H)
566 // From sys/user.h
567 SREF(user_regs_struct);
568 #endif
570 #if defined(HAVE_SYS_UTSNAME_H)
571 // From sys/utsname.h
572 SREF(utsname);
573 #endif
575 // From termios.h
576 SREF(termios);
578 // From uio.h
579 SREF(iovec);
581 // From utime.h
582 SREF(utimbuf);
584 // From unistd.h
585 EREF(_PC_NAME_MAX);
586 EREF(_SC_GETPW_R_SIZE_MAX);
588 #endif // clang