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. */
13 #include <sys/types.h>
18 #include <netinet/in.h>
19 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
20 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
22 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
23 <sys/ttold.h> does so unconditionally. */
25 #include <sys/bsd_types.h>
26 #include <sys/ttold.h>
28 #include <netinet/tcp.h>
29 #if defined(HAVE_NETINET_IN_SYSTM_H)
30 #include <netinet/in_systm.h>
32 #if defined(HAVE_NETINET_IP_H)
33 #include <netinet/ip.h>
35 #if defined(HAVE_NETINET_IP_MROUTE_H)
36 #include <netinet/ip_mroute.h>
38 #if defined(HAVE_NETINET_IF_ETHER_H)
39 #include <netinet/if_ether.h>
42 #include <sys/ioctl.h>
44 #if defined(HAVE_SYSCALL_H)
47 #if defined(HAVE_SYS_SYSCALL_H)
48 #include <sys/syscall.h>
50 #if defined(HAVE_SYS_SYSCTL_H)
51 #include <sys/sysctl.h>
53 #if defined(HAVE_SYS_EPOLL_H)
54 #include <sys/epoll.h>
56 #if defined(HAVE_SYS_EVENT_H)
57 #include <sys/event.h>
59 #if defined(HAVE_SYS_FILE_H)
62 #if defined(HAVE_SYS_MMAN_H)
65 #if defined(HAVE_SYS_PRCTL_H)
66 #include <sys/prctl.h>
68 #if defined(HAVE_SYS_PTRACE_H)
69 #include <sys/ptrace.h>
71 #include <sys/resource.h>
73 #include <sys/socket.h>
76 #include <sys/times.h>
79 #if defined(HAVE_SYS_USER_H)
82 #if defined(HAVE_SYS_UTSNAME_H)
83 #include <sys/utsname.h>
85 #if defined(HAVE_SYS_SELECT_H)
86 #include <sys/select.h>
93 #if defined(HAVE_LINUX_FILTER_H)
94 #include <linux/filter.h>
96 #if defined(HAVE_LINUX_IF_ADDR_H)
97 #include <linux/if_addr.h>
99 #if defined(HAVE_LINUX_IF_ETHER_H)
100 #include <linux/if_ether.h>
102 #if defined(HAVE_LINUX_IF_TUN_H)
103 #include <linux/if_tun.h>
105 #if defined(HAVE_LINUX_NETLINK_H)
106 #include <linux/netlink.h>
108 #if defined(HAVE_LINUX_PTRACE_H)
109 /* Avoid https://sourceware.org/bugzilla/show_bug.cgi?id=762 . */
110 #define ia64_fpreg pt_ia64_fpreg
111 #define pt_all_user_regs pt_ia64_all_user_regs
112 /* Avoid redefinition of ptrace_peeksiginfo from <sys/ptrace.h>.
113 https://gcc.gnu.org/PR81324 . */
114 #define ptrace_peeksiginfo_args ignore_ptrace_peeksiginfo_args
115 #include <linux/ptrace.h>
117 #undef pt_all_user_regs
118 #undef ptrace_peeksiginfo_args
120 #if defined(HAVE_LINUX_RTNETLINK_H)
121 #include <linux/rtnetlink.h>
123 #if defined(HAVE_NET_BPF_H)
126 #if defined(HAVE_NET_IF_H)
129 #if defined(HAVE_NET_IF_ARP_H)
130 #include <net/if_arp.h>
132 #if defined(HAVE_NET_ROUTE_H)
133 #include <net/route.h>
135 #if defined (HAVE_NETPACKET_PACKET_H)
136 #include <netpacket/packet.h>
138 #if defined(HAVE_SYS_MOUNT_H)
139 #include <sys/mount.h>
141 #if defined(HAVE_SYS_VFS_H)
144 #if defined(HAVE_STATFS_H)
145 #include <sys/statfs.h>
147 #if defined(HAVE_SYS_TIMEX_H)
148 #include <sys/timex.h>
150 #if defined(HAVE_SYS_SYSINFO_H)
151 #include <sys/sysinfo.h>
153 #if defined(HAVE_UTIME_H)
156 #if defined(HAVE_LINUX_ETHER_H)
157 #include <linux/ether.h>
159 #if defined(HAVE_LINUX_FS_H)
160 #include <linux/fs.h>
162 #if defined(HAVE_LINUX_REBOOT_H)
163 #include <linux/reboot.h>
165 #if defined(HAVE_SYS_INOTIFY_H)
166 #include <sys/inotify.h>
168 #if defined(HAVE_NETINET_ICMP6_H)
169 #include <netinet/icmp6.h>
171 #if defined(HAVE_SCHED_H)
174 #if defined(HAVE_SEMAPHORE_H)
175 #include <semaphore.h>
177 #if defined(HAVE_PORT_H)
185 /* Constants that may only be defined as expressions on some systems,
186 expressions too complex for -fdump-go-spec to handle. These are
187 handled specially below. */
190 TIOCGWINSZ_val
= TIOCGWINSZ
,
193 TIOCSWINSZ_val
= TIOCSWINSZ
,
196 TIOCNOTTY_val
= TIOCNOTTY
,
199 TIOCSCTTY_val
= TIOCSCTTY
,
202 TIOCGPGRP_val
= TIOCGPGRP
,
205 TIOCSPGRP_val
= TIOCSPGRP
,
208 TIOCGPTN_val
= TIOCGPTN
,
211 TIOCSPTLCK_val
= TIOCSPTLCK
,
214 TIOCGDEV_val
= TIOCGDEV
,
217 TIOCSIG_val
= TIOCSIG
,
226 TUNSETIFF_val
= TUNSETIFF
,
229 TUNSETNOCSUM_val
= TUNSETNOCSUM
,
232 TUNSETDEBUG_val
= TUNSETDEBUG
,
235 TUNSETPERSIST_val
= TUNSETPERSIST
,
238 TUNSETOWNER_val
= TUNSETOWNER
,
241 TUNSETLINK_val
= TUNSETLINK
,
244 TUNSETGROUP_val
= TUNSETGROUP
,
246 #ifdef TUNGETFEATURES
247 TUNGETFEATURES_val
= TUNGETFEATURES
,
250 TUNSETOFFLOAD_val
= TUNSETOFFLOAD
,
252 #ifdef TUNSETTXFILTER
253 TUNSETTXFILTER_val
= TUNSETTXFILTER
,
256 TUNGETIFF_val
= TUNGETIFF
,
259 TUNGETSNDBUF_val
= TUNGETSNDBUF
,
262 TUNSETSNDBUF_val
= TUNSETSNDBUF
,
264 #ifdef TUNATTACHFILTER
265 TUNATTACHFILTER_val
= TUNATTACHFILTER
,
267 #ifdef TUNDETACHFILTER
268 TUNDETACHFILTER_val
= TUNDETACHFILTER
,
270 #ifdef TUNGETVNETHDRSZ
271 TUNGETVNETHDRSZ_val
= TUNGETVNETHDRSZ
,
273 #ifdef TUNSETVNETHDRSZ
274 TUNSETVNETHDRSZ_val
= TUNSETVNETHDRSZ
,
277 TUNSETQUEUE_val
= TUNSETQUEUE
,
280 TUNSETIFINDEX_val
= TUNSETIFINDEX
,
283 TUNGETFILTER_val
= TUNGETFILTER
,
286 NLA_HDRLEN_val
= NLA_HDRLEN
,
289 BIOCFLUSH_val
= BIOCFLUSH
,
292 BIOCGBLEN_val
= BIOCGBLEN
,
295 BIOCGDLT_val
= BIOCGDLT
,
298 BIOCGETIF_val
= BIOCGETIF
,
301 BIOCGHDRCMPLT_val
= BIOCGHDRCMPLT
,
304 BIOCGRTIMEOUT_val
= BIOCGRTIMEOUT
,
307 BIOCGSTATS_val
= BIOCGSTATS
,
310 BIOCIMMEDIATE_val
= BIOCIMMEDIATE
,
313 BIOCPROMISC_val
= BIOCPROMISC
,
316 BIOCSBLEN_val
= BIOCSBLEN
,
319 BIOCSDLT_val
= BIOCSDLT
,
322 BIOCSETF_val
= BIOCSETF
,
325 BIOCSETIF_val
= BIOCSETIF
,
328 BIOCSHDRCMPLT_val
= BIOCSHDRCMPLT
,
331 BIOCSRTIMEOUT_val
= BIOCSRTIMEOUT
,
334 BIOCVERSION_val
= BIOCVERSION
,
338 // SIOCGIFMTU can't be added in the above enum as it might
339 // be signed in some OSes.
342 SIOCGIFMTU_val
= SIOCGIFMTU
,
346 #if defined(HAVE_SYS_EPOLL_H)
348 epoll_data_offset
= offsetof(struct epoll_event
, data
)
352 // The following section introduces explicit references to types and
353 // constants of interest to support bootstrapping libgo using a
354 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
355 // DWARF-based tools. This process is made more difficult due to the
356 // fact that clang tries hard to omit types/constants from DWARF if it
357 // can't find explicit references to them, so here we make sure that
358 // key items are mentioned in ways that will force them into the
361 #if defined(__clang__)
363 // Make a reference to a type
364 #define TREF(typ) typ typ ## ref
366 // Make a reference to an opaque type
367 #define OTREF(typ) typ *typ ## ref
369 // Make a reference to a struct tag
370 #define SREF(stag) struct stag stag ## ref
372 // Make a reference to an enum literal
373 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
375 //......................................................................
397 #if defined(HAVE_LINUX_FILTER_H)
398 // From linux/filter.h
406 #if defined(HAVE_LINUX_IF_ADDR_H)
407 // From linux/if_addr.h
412 #if defined(HAVE_LINUX_RTNETLINK_H)
413 // From linux/if_link.h
417 // From in.h, in6.h, icmp6.h
426 #if defined(HAVE_LINUX_RTNETLINK_H)
427 // From linux/rtnetlink.h
444 // From pthread.h and related
445 TREF(pthread_attr_t
);
447 TREF(pthread_mutex_t
);
448 TREF(pthread_mutexattr_t
);
453 // From signal.h and related
475 // From <sys/epoll.h>
476 #if defined(HAVE_SYS_EPOLL_H)
479 EREF(epoll_data_offset
);
482 #if defined(HAVE_SYS_MOUNT_H)
488 #if defined(HAVE_SYS_PTRACE_H)
489 // From <sys/ptrace.h>
490 #if defined (__aarch64__)
495 EREF(PTRACE_PEEKTEXT
);
498 // From sys/resource.h
517 // From sys/time.h and sys/times.h
524 #if defined(HAVE_SYS_TIMEX_H)
539 // From sys/ucontext.h
542 #if defined(HAVE_SYS_USER_H)
544 SREF(user_regs_struct
);
547 #if defined(HAVE_SYS_UTSNAME_H)
548 // From sys/utsname.h
563 EREF(_SC_GETPW_R_SIZE_MAX
);