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. */
15 #include <sys/types.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
24 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
25 <sys/ttold.h> does so unconditionally. */
27 #include <sys/bsd_types.h>
28 #include <sys/ttold.h>
30 #include <netinet/tcp.h>
31 #if defined(HAVE_NETINET_IN_SYSTM_H)
32 #include <netinet/in_systm.h>
34 #if defined(HAVE_NETINET_IP_H)
35 #include <netinet/ip.h>
37 #if defined(HAVE_NETINET_IP_MROUTE_H)
38 #include <netinet/ip_mroute.h>
40 #if defined(HAVE_NETINET_IF_ETHER_H)
41 #include <netinet/if_ether.h>
44 #include <sys/ioctl.h>
46 #if defined(HAVE_SYSCALL_H)
49 #if defined(HAVE_SYS_SYSCALL_H)
50 #include <sys/syscall.h>
52 #if defined(HAVE_SYS_SYSCTL_H)
53 #include <sys/sysctl.h>
55 #if defined(HAVE_SYS_EPOLL_H)
56 #include <sys/epoll.h>
58 #if defined(HAVE_SYS_EVENT_H)
59 #include <sys/event.h>
61 #if defined(HAVE_SYS_FILE_H)
64 #if defined(HAVE_SYS_MMAN_H)
67 #if defined(HAVE_SYS_PRCTL_H)
68 #include <sys/prctl.h>
70 #if defined(HAVE_SYS_PTRACE_H)
71 #include <sys/ptrace.h>
73 #include <sys/resource.h>
75 #include <sys/socket.h>
78 #include <sys/times.h>
81 #if defined(HAVE_SYS_USER_H)
84 #if defined(HAVE_SYS_UTSNAME_H)
85 #include <sys/utsname.h>
87 #if defined(HAVE_SYS_SELECT_H)
88 #include <sys/select.h>
95 #if defined(HAVE_LINUX_FILTER_H)
96 #include <linux/filter.h>
98 #if defined(HAVE_LINUX_IF_ADDR_H)
99 #include <linux/if_addr.h>
101 #if defined(HAVE_LINUX_IF_ETHER_H)
102 #include <linux/if_ether.h>
104 #if defined(HAVE_LINUX_IF_TUN_H)
105 #include <linux/if_tun.h>
107 #if defined(HAVE_LINUX_NETLINK_H)
108 #include <linux/netlink.h>
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>
119 #undef pt_all_user_regs
120 #undef ptrace_peeksiginfo_args
122 #if defined(HAVE_LINUX_RTNETLINK_H)
123 #include <linux/rtnetlink.h>
125 #if defined(HAVE_NET_BPF_H)
128 #if defined(HAVE_NET_IF_H)
131 #if defined(HAVE_NET_IF_ARP_H)
132 #include <net/if_arp.h>
134 #if defined(HAVE_NET_ROUTE_H)
135 #include <net/route.h>
137 #if defined (HAVE_NETPACKET_PACKET_H)
138 #include <netpacket/packet.h>
140 #if defined(HAVE_SYS_MOUNT_H)
141 #include <sys/mount.h>
143 #if defined(HAVE_SYS_VFS_H)
146 #if defined(HAVE_STATFS_H)
147 #include <sys/statfs.h>
149 #if defined(HAVE_SYS_TIMEX_H)
150 #include <sys/timex.h>
152 #if defined(HAVE_SYS_SYSINFO_H)
153 #include <sys/sysinfo.h>
155 #if defined(HAVE_UTIME_H)
158 #if defined(HAVE_LINUX_ETHER_H)
159 #include <linux/ether.h>
161 #if defined(HAVE_LINUX_FS_H)
162 #include <linux/fs.h>
164 #if defined(HAVE_LINUX_REBOOT_H)
165 #include <linux/reboot.h>
167 #if defined(HAVE_SYS_INOTIFY_H)
168 #include <sys/inotify.h>
170 #if defined(HAVE_NETINET_ICMP6_H)
171 #include <netinet/icmp6.h>
173 #if defined(HAVE_SCHED_H)
176 #if defined(HAVE_SEMAPHORE_H)
177 #include <semaphore.h>
179 #if defined(HAVE_PORT_H)
182 #if defined(HAVE_LWP_H)
190 /* Constants that may only be defined as expressions on some systems,
191 expressions too complex for -fdump-go-spec to handle. These are
192 handled specially below. */
195 TIOCGWINSZ_val
= TIOCGWINSZ
,
198 TIOCSWINSZ_val
= TIOCSWINSZ
,
201 TIOCNOTTY_val
= TIOCNOTTY
,
204 TIOCSCTTY_val
= TIOCSCTTY
,
207 TIOCGPGRP_val
= TIOCGPGRP
,
210 TIOCSPGRP_val
= TIOCSPGRP
,
213 TIOCGPTN_val
= TIOCGPTN
,
216 TIOCSPTLCK_val
= TIOCSPTLCK
,
219 TIOCGDEV_val
= TIOCGDEV
,
222 TIOCSIG_val
= TIOCSIG
,
231 TUNSETIFF_val
= TUNSETIFF
,
234 TUNSETNOCSUM_val
= TUNSETNOCSUM
,
237 TUNSETDEBUG_val
= TUNSETDEBUG
,
240 TUNSETPERSIST_val
= TUNSETPERSIST
,
243 TUNSETOWNER_val
= TUNSETOWNER
,
246 TUNSETLINK_val
= TUNSETLINK
,
249 TUNSETGROUP_val
= TUNSETGROUP
,
251 #ifdef TUNGETFEATURES
252 TUNGETFEATURES_val
= TUNGETFEATURES
,
255 TUNSETOFFLOAD_val
= TUNSETOFFLOAD
,
257 #ifdef TUNSETTXFILTER
258 TUNSETTXFILTER_val
= TUNSETTXFILTER
,
261 TUNGETIFF_val
= TUNGETIFF
,
264 TUNGETSNDBUF_val
= TUNGETSNDBUF
,
267 TUNSETSNDBUF_val
= TUNSETSNDBUF
,
269 #ifdef TUNATTACHFILTER
270 TUNATTACHFILTER_val
= TUNATTACHFILTER
,
272 #ifdef TUNDETACHFILTER
273 TUNDETACHFILTER_val
= TUNDETACHFILTER
,
275 #ifdef TUNGETVNETHDRSZ
276 TUNGETVNETHDRSZ_val
= TUNGETVNETHDRSZ
,
278 #ifdef TUNSETVNETHDRSZ
279 TUNSETVNETHDRSZ_val
= TUNSETVNETHDRSZ
,
282 TUNSETQUEUE_val
= TUNSETQUEUE
,
285 TUNSETIFINDEX_val
= TUNSETIFINDEX
,
288 TUNGETFILTER_val
= TUNGETFILTER
,
291 NLA_HDRLEN_val
= NLA_HDRLEN
,
294 BIOCFLUSH_val
= BIOCFLUSH
,
297 BIOCGBLEN_val
= BIOCGBLEN
,
300 BIOCGDLT_val
= BIOCGDLT
,
303 BIOCGETIF_val
= BIOCGETIF
,
306 BIOCGHDRCMPLT_val
= BIOCGHDRCMPLT
,
309 BIOCGRTIMEOUT_val
= BIOCGRTIMEOUT
,
312 BIOCGSTATS_val
= BIOCGSTATS
,
315 BIOCIMMEDIATE_val
= BIOCIMMEDIATE
,
318 BIOCPROMISC_val
= BIOCPROMISC
,
321 BIOCSBLEN_val
= BIOCSBLEN
,
324 BIOCSDLT_val
= BIOCSDLT
,
327 BIOCSETF_val
= BIOCSETF
,
330 BIOCSETIF_val
= BIOCSETIF
,
333 BIOCSHDRCMPLT_val
= BIOCSHDRCMPLT
,
336 BIOCSRTIMEOUT_val
= BIOCSRTIMEOUT
,
339 BIOCVERSION_val
= BIOCVERSION
,
342 SO_RCVTIMEO_val
= SO_RCVTIMEO
,
346 // SIOCGIFMTU can't be added in the above enum as it might
347 // be signed in some OSes.
350 SIOCGIFMTU_val
= SIOCGIFMTU
,
354 #if defined(HAVE_SYS_EPOLL_H)
356 epoll_data_offset
= offsetof(struct epoll_event
, data
)
360 // The following section introduces explicit references to types and
361 // constants of interest to support bootstrapping libgo using a
362 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
363 // DWARF-based tools. This process is made more difficult due to the
364 // fact that clang tries hard to omit types/constants from DWARF if it
365 // can't find explicit references to them, so here we make sure that
366 // key items are mentioned in ways that will force them into the
369 #if defined(__clang__)
371 // Make a reference to a type
372 #define TREF(typ) typ typ ## ref
374 // Make a reference to an opaque type
375 #define OTREF(typ) typ *typ ## ref
377 // Make a reference to a struct tag
378 #define SREF(stag) struct stag stag ## ref
380 // Make a reference to an enum literal
381 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
383 //......................................................................
405 #if defined(HAVE_LINUX_FILTER_H)
406 // From linux/filter.h
414 #if defined(HAVE_LINUX_IF_ADDR_H)
415 // From linux/if_addr.h
420 #if defined(HAVE_LINUX_RTNETLINK_H)
421 // From linux/if_link.h
425 // From in.h, in6.h, icmp6.h
434 #if defined(HAVE_LINUX_RTNETLINK_H)
435 // From linux/rtnetlink.h
452 // From pthread.h and related
453 TREF(pthread_attr_t
);
455 TREF(pthread_mutex_t
);
456 TREF(pthread_mutexattr_t
);
461 // From signal.h and related
483 // From <sys/epoll.h>
484 #if defined(HAVE_SYS_EPOLL_H)
487 EREF(epoll_data_offset
);
490 #if defined(HAVE_SYS_MOUNT_H)
496 #if defined(HAVE_SYS_PTRACE_H)
497 // From <sys/ptrace.h>
498 #if defined (__aarch64__)
503 EREF(PTRACE_PEEKTEXT
);
506 // From sys/resource.h
525 // From sys/time.h and sys/times.h
532 #if defined(HAVE_SYS_TIMEX_H)
547 // From sys/ucontext.h
550 #if defined(HAVE_SYS_USER_H)
552 SREF(user_regs_struct
);
555 #if defined(HAVE_SYS_UTSNAME_H)
556 // From sys/utsname.h
571 EREF(_SC_GETPW_R_SIZE_MAX
);