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