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_EPOLL_H)
51 #include <sys/epoll.h>
53 #if defined(HAVE_SYS_EVENT_H)
54 #include <sys/event.h>
56 #if defined(HAVE_SYS_FILE_H)
59 #if defined(HAVE_SYS_MMAN_H)
62 #if defined(HAVE_SYS_PRCTL_H)
63 #include <sys/prctl.h>
65 #if defined(HAVE_SYS_PTRACE_H)
66 #include <sys/ptrace.h>
68 #include <sys/resource.h>
70 #include <sys/socket.h>
73 #include <sys/times.h>
76 #if defined(HAVE_SYS_USER_H)
79 #if defined(HAVE_SYS_UTSNAME_H)
80 #include <sys/utsname.h>
82 #if defined(HAVE_SYS_SELECT_H)
83 #include <sys/select.h>
90 #if defined(HAVE_LINUX_FILTER_H)
91 #include <linux/filter.h>
93 #if defined(HAVE_LINUX_IF_ADDR_H)
94 #include <linux/if_addr.h>
96 #if defined(HAVE_LINUX_IF_ETHER_H)
97 #include <linux/if_ether.h>
99 #if defined(HAVE_LINUX_IF_TUN_H)
100 #include <linux/if_tun.h>
102 #if defined(HAVE_LINUX_NETLINK_H)
103 #include <linux/netlink.h>
105 #if defined(HAVE_LINUX_PTRACE_H)
106 /* Avoid https://sourceware.org/bugzilla/show_bug.cgi?id=762 . */
107 #define ia64_fpreg pt_ia64_fpreg
108 #define pt_all_user_regs pt_ia64_all_user_regs
109 /* Avoid redefinition of ptrace_peeksiginfo from <sys/ptrace.h>.
110 https://gcc.gnu.org/PR81324 . */
111 #define ptrace_peeksiginfo_args ignore_ptrace_peeksiginfo_args
112 #include <linux/ptrace.h>
114 #undef pt_all_user_regs
115 #undef ptrace_peeksiginfo_args
117 #if defined(HAVE_LINUX_RTNETLINK_H)
118 #include <linux/rtnetlink.h>
120 #if defined(HAVE_NET_IF_H)
123 #if defined(HAVE_NET_IF_ARP_H)
124 #include <net/if_arp.h>
126 #if defined(HAVE_NET_ROUTE_H)
127 #include <net/route.h>
129 #if defined (HAVE_NETPACKET_PACKET_H)
130 #include <netpacket/packet.h>
132 #if defined(HAVE_SYS_MOUNT_H)
133 #include <sys/mount.h>
135 #if defined(HAVE_SYS_VFS_H)
138 #if defined(HAVE_STATFS_H)
139 #include <sys/statfs.h>
141 #if defined(HAVE_SYS_TIMEX_H)
142 #include <sys/timex.h>
144 #if defined(HAVE_SYS_SYSINFO_H)
145 #include <sys/sysinfo.h>
147 #if defined(HAVE_UTIME_H)
150 #if defined(HAVE_LINUX_ETHER_H)
151 #include <linux/ether.h>
153 #if defined(HAVE_LINUX_FS_H)
154 #include <linux/fs.h>
156 #if defined(HAVE_LINUX_REBOOT_H)
157 #include <linux/reboot.h>
159 #if defined(HAVE_SYS_INOTIFY_H)
160 #include <sys/inotify.h>
162 #if defined(HAVE_NETINET_ICMP6_H)
163 #include <netinet/icmp6.h>
165 #if defined(HAVE_SCHED_H)
168 #if defined(HAVE_SEMAPHORE_H)
169 #include <semaphore.h>
171 #if defined(HAVE_PORT_H)
179 /* Constants that may only be defined as expressions on some systems,
180 expressions too complex for -fdump-go-spec to handle. These are
181 handled specially below. */
184 TIOCGWINSZ_val
= TIOCGWINSZ
,
187 TIOCSWINSZ_val
= TIOCSWINSZ
,
190 TIOCNOTTY_val
= TIOCNOTTY
,
193 TIOCSCTTY_val
= TIOCSCTTY
,
196 TIOCGPGRP_val
= TIOCGPGRP
,
199 TIOCSPGRP_val
= TIOCSPGRP
,
202 TIOCGPTN_val
= TIOCGPTN
,
205 TIOCSPTLCK_val
= TIOCSPTLCK
,
208 TIOCGDEV_val
= TIOCGDEV
,
211 TIOCSIG_val
= TIOCSIG
,
220 TUNSETIFF_val
= TUNSETIFF
,
223 TUNSETNOCSUM_val
= TUNSETNOCSUM
,
226 TUNSETDEBUG_val
= TUNSETDEBUG
,
229 TUNSETPERSIST_val
= TUNSETPERSIST
,
232 TUNSETOWNER_val
= TUNSETOWNER
,
235 TUNSETLINK_val
= TUNSETLINK
,
238 TUNSETGROUP_val
= TUNSETGROUP
,
240 #ifdef TUNGETFEATURES
241 TUNGETFEATURES_val
= TUNGETFEATURES
,
244 TUNSETOFFLOAD_val
= TUNSETOFFLOAD
,
246 #ifdef TUNSETTXFILTER
247 TUNSETTXFILTER_val
= TUNSETTXFILTER
,
250 TUNGETIFF_val
= TUNGETIFF
,
253 TUNGETSNDBUF_val
= TUNGETSNDBUF
,
256 TUNSETSNDBUF_val
= TUNSETSNDBUF
,
258 #ifdef TUNATTACHFILTER
259 TUNATTACHFILTER_val
= TUNATTACHFILTER
,
261 #ifdef TUNDETACHFILTER
262 TUNDETACHFILTER_val
= TUNDETACHFILTER
,
264 #ifdef TUNGETVNETHDRSZ
265 TUNGETVNETHDRSZ_val
= TUNGETVNETHDRSZ
,
267 #ifdef TUNSETVNETHDRSZ
268 TUNSETVNETHDRSZ_val
= TUNSETVNETHDRSZ
,
271 TUNSETQUEUE_val
= TUNSETQUEUE
,
274 TUNSETIFINDEX_val
= TUNSETIFINDEX
,
277 TUNGETFILTER_val
= TUNGETFILTER
,
280 NLA_HDRLEN_val
= NLA_HDRLEN
,
284 #if defined(HAVE_SYS_EPOLL_H)
286 epoll_data_offset
= offsetof(struct epoll_event
, data
)
290 // The following section introduces explicit references to types and
291 // constants of interest to support bootstrapping libgo using a
292 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
293 // DWARF-based tools. This process is made more difficult due to the
294 // fact that clang tries hard to omit types/constants from DWARF if it
295 // can't find explicit references to them, so here we make sure that
296 // key items are mentioned in ways that will force them into the
299 #if defined(__clang__)
301 // Make a reference to a type
302 #define TREF(typ) typ typ ## ref
304 // Make a reference to an opaque type
305 #define OTREF(typ) typ *typ ## ref
307 // Make a reference to a struct tag
308 #define SREF(stag) struct stag stag ## ref
310 // Make a reference to an enum literal
311 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
313 //......................................................................
334 #if defined(HAVE_LINUX_FILTER_H)
335 // From linux/filter.h
343 #if defined(HAVE_LINUX_IF_ADDR_H)
344 // From linux/if_addr.h
349 #if defined(HAVE_LINUX_RTNETLINK_H)
350 // From linux/if_link.h
354 // From in.h, in6.h, icmp6.h
363 #if defined(HAVE_LINUX_RTNETLINK_H)
364 // From linux/rtnetlink.h
381 // From pthread.h and related
382 TREF(pthread_attr_t
);
384 TREF(pthread_mutex_t
);
385 TREF(pthread_mutexattr_t
);
390 // From signal.h and related
412 // From <sys/epoll.h>
413 #if defined(HAVE_SYS_EPOLL_H)
416 EREF(epoll_data_offset
);
419 #if defined(HAVE_SYS_MOUNT_H)
425 #if defined(HAVE_SYS_PTRACE_H)
426 // From <sys/ptrace.h>
427 #if defined (__aarch64__)
432 EREF(PTRACE_PEEKTEXT
);
435 // From sys/resource.h
453 // From sys/time.h and sys/times.h
460 #if defined(HAVE_SYS_TIMEX_H)
475 // From sys/ucontext.h
478 #if defined(HAVE_SYS_USER_H)
480 SREF(user_regs_struct
);
483 #if defined(HAVE_SYS_UTSNAME_H)
484 // From sys/utsname.h
499 EREF(_SC_GETPW_R_SIZE_MAX
);