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. */
14 #include <sys/types.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
23 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
24 <sys/ttold.h> does so unconditionally. */
26 #include <sys/bsd_types.h>
27 #include <sys/ttold.h>
29 #include <netinet/tcp.h>
30 #if defined(HAVE_NETINET_IN_SYSTM_H)
31 #include <netinet/in_systm.h>
33 #if defined(HAVE_NETINET_IP_H)
34 #include <netinet/ip.h>
36 #if defined(HAVE_NETINET_IP_MROUTE_H)
37 #include <netinet/ip_mroute.h>
39 #if defined(HAVE_NETINET_IF_ETHER_H)
40 #include <netinet/if_ether.h>
43 #include <sys/ioctl.h>
45 #if defined(HAVE_SYSCALL_H)
48 #if defined(HAVE_SYS_SYSCALL_H)
49 #include <sys/syscall.h>
51 #if defined(HAVE_SYS_SYSCTL_H)
52 #include <sys/sysctl.h>
54 #if defined(HAVE_SYS_EPOLL_H)
55 #include <sys/epoll.h>
57 #if defined(HAVE_SYS_EVENT_H)
58 #include <sys/event.h>
60 #if defined(HAVE_SYS_FILE_H)
63 #if defined(HAVE_SYS_MMAN_H)
66 #if defined(HAVE_SYS_PRCTL_H)
67 #include <sys/prctl.h>
69 #if defined(HAVE_SYS_PTRACE_H)
70 #include <sys/ptrace.h>
72 #include <sys/resource.h>
74 #include <sys/socket.h>
77 #include <sys/times.h>
80 #if defined(HAVE_SYS_USER_H)
83 #if defined(HAVE_SYS_UTSNAME_H)
84 #include <sys/utsname.h>
86 #if defined(HAVE_SYS_SELECT_H)
87 #include <sys/select.h>
94 #if defined(HAVE_LINUX_FILTER_H)
95 #include <linux/filter.h>
97 #if defined(HAVE_LINUX_IF_ADDR_H)
98 #include <linux/if_addr.h>
100 #if defined(HAVE_LINUX_IF_ETHER_H)
101 #include <linux/if_ether.h>
103 #if defined(HAVE_LINUX_IF_TUN_H)
104 #include <linux/if_tun.h>
106 #if defined(HAVE_LINUX_NETLINK_H)
107 #include <linux/netlink.h>
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>
118 #undef pt_all_user_regs
119 #undef ptrace_peeksiginfo_args
121 #if defined(HAVE_LINUX_RTNETLINK_H)
122 #include <linux/rtnetlink.h>
124 #if defined(HAVE_NET_BPF_H)
127 #if defined(HAVE_NET_IF_H)
130 #if defined(HAVE_NET_IF_ARP_H)
131 #include <net/if_arp.h>
133 #if defined(HAVE_NET_ROUTE_H)
134 #include <net/route.h>
136 #if defined (HAVE_NETPACKET_PACKET_H)
137 #include <netpacket/packet.h>
139 #if defined(HAVE_SYS_MOUNT_H)
140 #include <sys/mount.h>
142 #if defined(HAVE_SYS_VFS_H)
145 #if defined(HAVE_STATFS_H)
146 #include <sys/statfs.h>
148 #if defined(HAVE_SYS_TIMEX_H)
149 #include <sys/timex.h>
151 #if defined(HAVE_SYS_SYSINFO_H)
152 #include <sys/sysinfo.h>
154 #if defined(HAVE_UTIME_H)
157 #if defined(HAVE_LINUX_ETHER_H)
158 #include <linux/ether.h>
160 #if defined(HAVE_LINUX_FS_H)
161 #include <linux/fs.h>
163 #if defined(HAVE_LINUX_REBOOT_H)
164 #include <linux/reboot.h>
166 #if defined(HAVE_SYS_INOTIFY_H)
167 #include <sys/inotify.h>
169 #if defined(HAVE_NETINET_ICMP6_H)
170 #include <netinet/icmp6.h>
172 #if defined(HAVE_SCHED_H)
175 #if defined(HAVE_SEMAPHORE_H)
176 #include <semaphore.h>
178 #if defined(HAVE_PORT_H)
181 #if defined(HAVE_LWP_H)
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. */
194 TIOCGWINSZ_val
= TIOCGWINSZ
,
197 TIOCSWINSZ_val
= TIOCSWINSZ
,
200 TIOCNOTTY_val
= TIOCNOTTY
,
203 TIOCSCTTY_val
= TIOCSCTTY
,
206 TIOCGPGRP_val
= TIOCGPGRP
,
209 TIOCSPGRP_val
= TIOCSPGRP
,
212 TIOCGPTN_val
= TIOCGPTN
,
215 TIOCSPTLCK_val
= TIOCSPTLCK
,
218 TIOCGDEV_val
= TIOCGDEV
,
221 TIOCSIG_val
= TIOCSIG
,
230 TUNSETIFF_val
= TUNSETIFF
,
233 TUNSETNOCSUM_val
= TUNSETNOCSUM
,
236 TUNSETDEBUG_val
= TUNSETDEBUG
,
239 TUNSETPERSIST_val
= TUNSETPERSIST
,
242 TUNSETOWNER_val
= TUNSETOWNER
,
245 TUNSETLINK_val
= TUNSETLINK
,
248 TUNSETGROUP_val
= TUNSETGROUP
,
250 #ifdef TUNGETFEATURES
251 TUNGETFEATURES_val
= TUNGETFEATURES
,
254 TUNSETOFFLOAD_val
= TUNSETOFFLOAD
,
256 #ifdef TUNSETTXFILTER
257 TUNSETTXFILTER_val
= TUNSETTXFILTER
,
260 TUNGETIFF_val
= TUNGETIFF
,
263 TUNGETSNDBUF_val
= TUNGETSNDBUF
,
266 TUNSETSNDBUF_val
= TUNSETSNDBUF
,
268 #ifdef TUNATTACHFILTER
269 TUNATTACHFILTER_val
= TUNATTACHFILTER
,
271 #ifdef TUNDETACHFILTER
272 TUNDETACHFILTER_val
= TUNDETACHFILTER
,
274 #ifdef TUNGETVNETHDRSZ
275 TUNGETVNETHDRSZ_val
= TUNGETVNETHDRSZ
,
277 #ifdef TUNSETVNETHDRSZ
278 TUNSETVNETHDRSZ_val
= TUNSETVNETHDRSZ
,
281 TUNSETQUEUE_val
= TUNSETQUEUE
,
284 TUNSETIFINDEX_val
= TUNSETIFINDEX
,
287 TUNGETFILTER_val
= TUNGETFILTER
,
290 NLA_HDRLEN_val
= NLA_HDRLEN
,
293 BIOCFLUSH_val
= BIOCFLUSH
,
296 BIOCGBLEN_val
= BIOCGBLEN
,
299 BIOCGDLT_val
= BIOCGDLT
,
302 BIOCGETIF_val
= BIOCGETIF
,
305 BIOCGHDRCMPLT_val
= BIOCGHDRCMPLT
,
308 BIOCGRTIMEOUT_val
= BIOCGRTIMEOUT
,
311 BIOCGSTATS_val
= BIOCGSTATS
,
314 BIOCIMMEDIATE_val
= BIOCIMMEDIATE
,
317 BIOCPROMISC_val
= BIOCPROMISC
,
320 BIOCSBLEN_val
= BIOCSBLEN
,
323 BIOCSDLT_val
= BIOCSDLT
,
326 BIOCSETF_val
= BIOCSETF
,
329 BIOCSETIF_val
= BIOCSETIF
,
332 BIOCSHDRCMPLT_val
= BIOCSHDRCMPLT
,
335 BIOCSRTIMEOUT_val
= BIOCSRTIMEOUT
,
338 BIOCVERSION_val
= BIOCVERSION
,
342 // SIOCGIFMTU can't be added in the above enum as it might
343 // be signed in some OSes.
346 SIOCGIFMTU_val
= SIOCGIFMTU
,
350 #if defined(HAVE_SYS_EPOLL_H)
352 epoll_data_offset
= offsetof(struct epoll_event
, data
)
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
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 //......................................................................
401 #if defined(HAVE_LINUX_FILTER_H)
402 // From linux/filter.h
410 #if defined(HAVE_LINUX_IF_ADDR_H)
411 // From linux/if_addr.h
416 #if defined(HAVE_LINUX_RTNETLINK_H)
417 // From linux/if_link.h
421 // From in.h, in6.h, icmp6.h
430 #if defined(HAVE_LINUX_RTNETLINK_H)
431 // From linux/rtnetlink.h
448 // From pthread.h and related
449 TREF(pthread_attr_t
);
451 TREF(pthread_mutex_t
);
452 TREF(pthread_mutexattr_t
);
457 // From signal.h and related
479 // From <sys/epoll.h>
480 #if defined(HAVE_SYS_EPOLL_H)
483 EREF(epoll_data_offset
);
486 #if defined(HAVE_SYS_MOUNT_H)
492 #if defined(HAVE_SYS_PTRACE_H)
493 // From <sys/ptrace.h>
494 #if defined (__aarch64__)
499 EREF(PTRACE_PEEKTEXT
);
502 // From sys/resource.h
521 // From sys/time.h and sys/times.h
528 #if defined(HAVE_SYS_TIMEX_H)
543 // From sys/ucontext.h
546 #if defined(HAVE_SYS_USER_H)
548 SREF(user_regs_struct
);
551 #if defined(HAVE_SYS_UTSNAME_H)
552 // From sys/utsname.h
567 EREF(_SC_GETPW_R_SIZE_MAX
);