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_REBOOT_H)
162 #include <linux/reboot.h>
164 #if defined(HAVE_SYS_INOTIFY_H)
165 #include <sys/inotify.h>
167 #if defined(HAVE_NETINET_ICMP6_H)
168 #include <netinet/icmp6.h>
170 #if defined(HAVE_SCHED_H)
173 #if defined(HAVE_SEMAPHORE_H)
174 #include <semaphore.h>
176 #if defined(HAVE_PORT_H)
179 #if defined(HAVE_LWP_H)
187 /* Constants that may only be defined as expressions on some systems,
188 expressions too complex for -fdump-go-spec to handle. These are
189 handled specially below. */
192 TIOCGWINSZ_val
= TIOCGWINSZ
,
195 TIOCSWINSZ_val
= TIOCSWINSZ
,
198 TIOCNOTTY_val
= TIOCNOTTY
,
201 TIOCSCTTY_val
= TIOCSCTTY
,
204 TIOCGPGRP_val
= TIOCGPGRP
,
207 TIOCSPGRP_val
= TIOCSPGRP
,
210 TIOCGPTN_val
= TIOCGPTN
,
213 TIOCSPTLCK_val
= TIOCSPTLCK
,
216 TIOCGDEV_val
= TIOCGDEV
,
219 TIOCSIG_val
= TIOCSIG
,
228 TUNSETIFF_val
= TUNSETIFF
,
231 TUNSETNOCSUM_val
= TUNSETNOCSUM
,
234 TUNSETDEBUG_val
= TUNSETDEBUG
,
237 TUNSETPERSIST_val
= TUNSETPERSIST
,
240 TUNSETOWNER_val
= TUNSETOWNER
,
243 TUNSETLINK_val
= TUNSETLINK
,
246 TUNSETGROUP_val
= TUNSETGROUP
,
248 #ifdef TUNGETFEATURES
249 TUNGETFEATURES_val
= TUNGETFEATURES
,
252 TUNSETOFFLOAD_val
= TUNSETOFFLOAD
,
254 #ifdef TUNSETTXFILTER
255 TUNSETTXFILTER_val
= TUNSETTXFILTER
,
258 TUNGETIFF_val
= TUNGETIFF
,
261 TUNGETSNDBUF_val
= TUNGETSNDBUF
,
264 TUNSETSNDBUF_val
= TUNSETSNDBUF
,
266 #ifdef TUNATTACHFILTER
267 TUNATTACHFILTER_val
= TUNATTACHFILTER
,
269 #ifdef TUNDETACHFILTER
270 TUNDETACHFILTER_val
= TUNDETACHFILTER
,
272 #ifdef TUNGETVNETHDRSZ
273 TUNGETVNETHDRSZ_val
= TUNGETVNETHDRSZ
,
275 #ifdef TUNSETVNETHDRSZ
276 TUNSETVNETHDRSZ_val
= TUNSETVNETHDRSZ
,
279 TUNSETQUEUE_val
= TUNSETQUEUE
,
282 TUNSETIFINDEX_val
= TUNSETIFINDEX
,
285 TUNGETFILTER_val
= TUNGETFILTER
,
288 NLA_HDRLEN_val
= NLA_HDRLEN
,
291 BIOCFLUSH_val
= BIOCFLUSH
,
294 BIOCGBLEN_val
= BIOCGBLEN
,
297 BIOCGDLT_val
= BIOCGDLT
,
300 BIOCGETIF_val
= BIOCGETIF
,
303 BIOCGHDRCMPLT_val
= BIOCGHDRCMPLT
,
306 BIOCGRTIMEOUT_val
= BIOCGRTIMEOUT
,
309 BIOCGSTATS_val
= BIOCGSTATS
,
312 BIOCIMMEDIATE_val
= BIOCIMMEDIATE
,
315 BIOCPROMISC_val
= BIOCPROMISC
,
318 BIOCSBLEN_val
= BIOCSBLEN
,
321 BIOCSDLT_val
= BIOCSDLT
,
324 BIOCSETF_val
= BIOCSETF
,
327 BIOCSETIF_val
= BIOCSETIF
,
330 BIOCSHDRCMPLT_val
= BIOCSHDRCMPLT
,
333 BIOCSRTIMEOUT_val
= BIOCSRTIMEOUT
,
336 BIOCVERSION_val
= BIOCVERSION
,
339 SO_RCVTIMEO_val
= SO_RCVTIMEO
,
343 // SIOCGIFMTU can't be added in the above enum as it might
344 // be signed in some OSes.
347 SIOCGIFMTU_val
= SIOCGIFMTU
,
351 #if defined(HAVE_SYS_EPOLL_H)
353 epoll_data_offset
= offsetof(struct epoll_event
, data
)
357 #if !defined(SYS_timer_settime) && defined(SYS_timer_settime32)
358 // musl defines SYS_timer_settim32 on 32-bit systems.
359 #define SYS_timer_settime SYS_timer_settime32
362 #if defined(HAVE_LOFF_T)
363 // loff_t can be defined as a macro; for -fgo-dump-spec make sure we
365 typedef loff_t libgo_loff_t_type
;
368 #if defined(HAVE_OFF64_T)
369 typedef off64_t libgo_off_t_type
;
371 typedef off_t libgo_off_t_type
;
374 // The following section introduces explicit references to types and
375 // constants of interest to support bootstrapping libgo using a
376 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
377 // DWARF-based tools. This process is made more difficult due to the
378 // fact that clang tries hard to omit types/constants from DWARF if it
379 // can't find explicit references to them, so here we make sure that
380 // key items are mentioned in ways that will force them into the
383 #if defined(__clang__)
385 // Make a reference to a type
386 #define TREF(typ) typ typ ## ref
388 // Make a reference to an opaque type
389 #define OTREF(typ) typ *typ ## ref
391 // Make a reference to a struct tag
392 #define SREF(stag) struct stag stag ## ref
394 // Make a reference to an enum literal
395 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
397 //......................................................................
419 #if defined(HAVE_LINUX_FILTER_H)
420 // From linux/filter.h
428 #if defined(HAVE_LINUX_IF_ADDR_H)
429 // From linux/if_addr.h
434 #if defined(HAVE_LINUX_RTNETLINK_H)
435 // From linux/if_link.h
439 // From in.h, in6.h, icmp6.h
448 #if defined(HAVE_LINUX_RTNETLINK_H)
449 // From linux/rtnetlink.h
466 // From pthread.h and related
467 TREF(pthread_attr_t
);
469 TREF(pthread_mutex_t
);
470 TREF(pthread_mutexattr_t
);
475 // From signal.h and related
497 // From <sys/epoll.h>
498 #if defined(HAVE_SYS_EPOLL_H)
501 EREF(epoll_data_offset
);
504 #if defined(HAVE_SYS_MOUNT_H)
510 #if defined(HAVE_SYS_PTRACE_H)
511 // From <sys/ptrace.h>
512 #if defined (__aarch64__)
517 EREF(PTRACE_PEEKTEXT
);
520 // From sys/resource.h
539 // From sys/time.h and sys/times.h
546 #if defined(HAVE_SYS_TIMEX_H)
554 TREF(libgo_loff_t_type
);
555 TREF(libgo_off_t_type
);
562 // From sys/ucontext.h
565 #if defined(HAVE_SYS_USER_H)
567 SREF(user_regs_struct
);
570 #if defined(HAVE_SYS_UTSNAME_H)
571 // From sys/utsname.h
586 EREF(_SC_GETPW_R_SIZE_MAX
);