111
|
1 /* sysinfo.c -- input for mksysinfo.sh
|
|
2
|
|
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. */
|
|
6
|
|
7 /* This file is passed to GCC with the -fdump-go-spec option to
|
|
8 generate a Go version of the system information. */
|
|
9
|
|
10 #include "config.h"
|
|
11
|
|
12 #include <stddef.h>
|
|
13 #include <sys/types.h>
|
|
14 #include <dirent.h>
|
|
15 #include <errno.h>
|
|
16 #include <fcntl.h>
|
|
17 #include <ucontext.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
|
|
21 && !_XOPEN_SOURCE.
|
|
22 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
|
|
23 <sys/ttold.h> does so unconditionally. */
|
|
24 #ifdef __sgi__
|
|
25 #include <sys/bsd_types.h>
|
|
26 #include <sys/ttold.h>
|
|
27 #endif
|
|
28 #include <netinet/tcp.h>
|
|
29 #if defined(HAVE_NETINET_IN_SYSTM_H)
|
|
30 #include <netinet/in_systm.h>
|
|
31 #endif
|
|
32 #if defined(HAVE_NETINET_IP_H)
|
|
33 #include <netinet/ip.h>
|
|
34 #endif
|
|
35 #if defined(HAVE_NETINET_IP_MROUTE_H)
|
|
36 #include <netinet/ip_mroute.h>
|
|
37 #endif
|
|
38 #if defined(HAVE_NETINET_IF_ETHER_H)
|
|
39 #include <netinet/if_ether.h>
|
|
40 #endif
|
|
41 #include <signal.h>
|
|
42 #include <sys/ioctl.h>
|
|
43 #include <termios.h>
|
|
44 #if defined(HAVE_SYSCALL_H)
|
|
45 #include <syscall.h>
|
|
46 #endif
|
|
47 #if defined(HAVE_SYS_SYSCALL_H)
|
|
48 #include <sys/syscall.h>
|
|
49 #endif
|
|
50 #if defined(HAVE_SYS_EPOLL_H)
|
|
51 #include <sys/epoll.h>
|
|
52 #endif
|
|
53 #if defined(HAVE_SYS_EVENT_H)
|
|
54 #include <sys/event.h>
|
|
55 #endif
|
|
56 #if defined(HAVE_SYS_FILE_H)
|
|
57 #include <sys/file.h>
|
|
58 #endif
|
|
59 #if defined(HAVE_SYS_MMAN_H)
|
|
60 #include <sys/mman.h>
|
|
61 #endif
|
|
62 #if defined(HAVE_SYS_PRCTL_H)
|
|
63 #include <sys/prctl.h>
|
|
64 #endif
|
|
65 #if defined(HAVE_SYS_PTRACE_H)
|
|
66 #include <sys/ptrace.h>
|
|
67 #endif
|
|
68 #include <sys/resource.h>
|
|
69 #include <sys/uio.h>
|
|
70 #include <sys/socket.h>
|
|
71 #include <sys/stat.h>
|
|
72 #include <sys/time.h>
|
|
73 #include <sys/times.h>
|
|
74 #include <sys/wait.h>
|
|
75 #include <sys/un.h>
|
|
76 #if defined(HAVE_SYS_USER_H)
|
|
77 #include <sys/user.h>
|
|
78 #endif
|
|
79 #if defined(HAVE_SYS_UTSNAME_H)
|
|
80 #include <sys/utsname.h>
|
|
81 #endif
|
|
82 #if defined(HAVE_SYS_SELECT_H)
|
|
83 #include <sys/select.h>
|
|
84 #endif
|
|
85 #include <time.h>
|
|
86 #include <unistd.h>
|
|
87 #include <netdb.h>
|
|
88 #include <pwd.h>
|
|
89 #include <grp.h>
|
|
90 #if defined(HAVE_LINUX_FILTER_H)
|
|
91 #include <linux/filter.h>
|
|
92 #endif
|
|
93 #if defined(HAVE_LINUX_IF_ADDR_H)
|
|
94 #include <linux/if_addr.h>
|
|
95 #endif
|
|
96 #if defined(HAVE_LINUX_IF_ETHER_H)
|
|
97 #include <linux/if_ether.h>
|
|
98 #endif
|
|
99 #if defined(HAVE_LINUX_IF_TUN_H)
|
|
100 #include <linux/if_tun.h>
|
|
101 #endif
|
|
102 #if defined(HAVE_LINUX_NETLINK_H)
|
|
103 #include <linux/netlink.h>
|
|
104 #endif
|
|
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>
|
|
113 #undef ia64_fpreg
|
|
114 #undef pt_all_user_regs
|
|
115 #undef ptrace_peeksiginfo_args
|
|
116 #endif
|
|
117 #if defined(HAVE_LINUX_RTNETLINK_H)
|
|
118 #include <linux/rtnetlink.h>
|
|
119 #endif
|
|
120 #if defined(HAVE_NET_IF_H)
|
|
121 #include <net/if.h>
|
|
122 #endif
|
|
123 #if defined(HAVE_NET_IF_ARP_H)
|
|
124 #include <net/if_arp.h>
|
|
125 #endif
|
|
126 #if defined(HAVE_NET_ROUTE_H)
|
|
127 #include <net/route.h>
|
|
128 #endif
|
|
129 #if defined (HAVE_NETPACKET_PACKET_H)
|
|
130 #include <netpacket/packet.h>
|
|
131 #endif
|
|
132 #if defined(HAVE_SYS_MOUNT_H)
|
|
133 #include <sys/mount.h>
|
|
134 #endif
|
|
135 #if defined(HAVE_SYS_VFS_H)
|
|
136 #include <sys/vfs.h>
|
|
137 #endif
|
|
138 #if defined(HAVE_STATFS_H)
|
|
139 #include <sys/statfs.h>
|
|
140 #endif
|
|
141 #if defined(HAVE_SYS_TIMEX_H)
|
|
142 #include <sys/timex.h>
|
|
143 #endif
|
|
144 #if defined(HAVE_SYS_SYSINFO_H)
|
|
145 #include <sys/sysinfo.h>
|
|
146 #endif
|
|
147 #if defined(HAVE_UTIME_H)
|
|
148 #include <utime.h>
|
|
149 #endif
|
|
150 #if defined(HAVE_LINUX_ETHER_H)
|
|
151 #include <linux/ether.h>
|
|
152 #endif
|
|
153 #if defined(HAVE_LINUX_FS_H)
|
|
154 #include <linux/fs.h>
|
|
155 #endif
|
|
156 #if defined(HAVE_LINUX_REBOOT_H)
|
|
157 #include <linux/reboot.h>
|
|
158 #endif
|
|
159 #if defined(HAVE_SYS_INOTIFY_H)
|
|
160 #include <sys/inotify.h>
|
|
161 #endif
|
|
162 #if defined(HAVE_NETINET_ICMP6_H)
|
|
163 #include <netinet/icmp6.h>
|
|
164 #endif
|
|
165 #if defined(HAVE_SCHED_H)
|
|
166 #include <sched.h>
|
|
167 #endif
|
|
168 #if defined(HAVE_SEMAPHORE_H)
|
|
169 #include <semaphore.h>
|
|
170 #endif
|
|
171 #if defined(HAVE_PORT_H)
|
|
172 #include <port.h>
|
|
173 #endif
|
|
174
|
|
175 #ifdef USE_LIBFFI
|
|
176 #include "ffi.h"
|
|
177 #endif
|
|
178
|
|
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. */
|
|
182 enum {
|
|
183 #ifdef TIOCGWINSZ
|
|
184 TIOCGWINSZ_val = TIOCGWINSZ,
|
|
185 #endif
|
|
186 #ifdef TIOCSWINSZ
|
|
187 TIOCSWINSZ_val = TIOCSWINSZ,
|
|
188 #endif
|
|
189 #ifdef TIOCNOTTY
|
|
190 TIOCNOTTY_val = TIOCNOTTY,
|
|
191 #endif
|
|
192 #ifdef TIOCSCTTY
|
|
193 TIOCSCTTY_val = TIOCSCTTY,
|
|
194 #endif
|
|
195 #ifdef TIOCGPGRP
|
|
196 TIOCGPGRP_val = TIOCGPGRP,
|
|
197 #endif
|
|
198 #ifdef TIOCSPGRP
|
|
199 TIOCSPGRP_val = TIOCSPGRP,
|
|
200 #endif
|
|
201 #ifdef TIOCGPTN
|
|
202 TIOCGPTN_val = TIOCGPTN,
|
|
203 #endif
|
|
204 #ifdef TIOCSPTLCK
|
|
205 TIOCSPTLCK_val = TIOCSPTLCK,
|
|
206 #endif
|
|
207 #ifdef TIOCGDEV
|
|
208 TIOCGDEV_val = TIOCGDEV,
|
|
209 #endif
|
|
210 #ifdef TIOCSIG
|
|
211 TIOCSIG_val = TIOCSIG,
|
|
212 #endif
|
|
213 #ifdef TCGETS
|
|
214 TCGETS_val = TCGETS,
|
|
215 #endif
|
|
216 #ifdef TCSETS
|
|
217 TCSETS_val = TCSETS,
|
|
218 #endif
|
|
219 #ifdef TUNSETIFF
|
|
220 TUNSETIFF_val = TUNSETIFF,
|
|
221 #endif
|
|
222 #ifdef TUNSETNOCSUM
|
|
223 TUNSETNOCSUM_val = TUNSETNOCSUM,
|
|
224 #endif
|
|
225 #ifdef TUNSETDEBUG
|
|
226 TUNSETDEBUG_val = TUNSETDEBUG,
|
|
227 #endif
|
|
228 #ifdef TUNSETPERSIST
|
|
229 TUNSETPERSIST_val = TUNSETPERSIST,
|
|
230 #endif
|
|
231 #ifdef TUNSETOWNER
|
|
232 TUNSETOWNER_val = TUNSETOWNER,
|
|
233 #endif
|
|
234 #ifdef TUNSETLINK
|
|
235 TUNSETLINK_val = TUNSETLINK,
|
|
236 #endif
|
|
237 #ifdef TUNSETGROUP
|
|
238 TUNSETGROUP_val = TUNSETGROUP,
|
|
239 #endif
|
|
240 #ifdef TUNGETFEATURES
|
|
241 TUNGETFEATURES_val = TUNGETFEATURES,
|
|
242 #endif
|
|
243 #ifdef TUNSETOFFLOAD
|
|
244 TUNSETOFFLOAD_val = TUNSETOFFLOAD,
|
|
245 #endif
|
|
246 #ifdef TUNSETTXFILTER
|
|
247 TUNSETTXFILTER_val = TUNSETTXFILTER,
|
|
248 #endif
|
|
249 #ifdef TUNGETIFF
|
|
250 TUNGETIFF_val = TUNGETIFF,
|
|
251 #endif
|
|
252 #ifdef TUNGETSNDBUF
|
|
253 TUNGETSNDBUF_val = TUNGETSNDBUF,
|
|
254 #endif
|
|
255 #ifdef TUNSETSNDBUF
|
|
256 TUNSETSNDBUF_val = TUNSETSNDBUF,
|
|
257 #endif
|
|
258 #ifdef TUNATTACHFILTER
|
|
259 TUNATTACHFILTER_val = TUNATTACHFILTER,
|
|
260 #endif
|
|
261 #ifdef TUNDETACHFILTER
|
|
262 TUNDETACHFILTER_val = TUNDETACHFILTER,
|
|
263 #endif
|
|
264 #ifdef TUNGETVNETHDRSZ
|
|
265 TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ,
|
|
266 #endif
|
|
267 #ifdef TUNSETVNETHDRSZ
|
|
268 TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ,
|
|
269 #endif
|
|
270 #ifdef TUNSETQUEUE
|
|
271 TUNSETQUEUE_val = TUNSETQUEUE,
|
|
272 #endif
|
|
273 #ifdef TUNSETIFINDEX
|
|
274 TUNSETIFINDEX_val = TUNSETIFINDEX,
|
|
275 #endif
|
|
276 #ifdef TUNGETFILTER
|
|
277 TUNGETFILTER_val = TUNGETFILTER,
|
|
278 #endif
|
|
279 #ifdef NLA_HDRLEN
|
|
280 NLA_HDRLEN_val = NLA_HDRLEN,
|
|
281 #endif
|
|
282 };
|
|
283
|
|
284 #if defined(HAVE_SYS_EPOLL_H)
|
|
285 enum {
|
|
286 epoll_data_offset = offsetof(struct epoll_event, data)
|
|
287 };
|
|
288 #endif
|
131
|
289
|
|
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
|
|
297 // generated DWARF.
|
|
298
|
|
299 #if defined(__clang__)
|
|
300
|
|
301 // Make a reference to a type
|
|
302 #define TREF(typ) typ typ ## ref
|
|
303
|
|
304 // Make a reference to an opaque type
|
|
305 #define OTREF(typ) typ *typ ## ref
|
|
306
|
|
307 // Make a reference to a struct tag
|
|
308 #define SREF(stag) struct stag stag ## ref
|
|
309
|
|
310 // Make a reference to an enum literal
|
|
311 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
|
|
312
|
|
313 //......................................................................
|
|
314
|
|
315 // From dirent.h
|
|
316 SREF(dirent);
|
|
317 SREF(dirent64);
|
|
318 OTREF(DIR);
|
|
319
|
|
320 // From fcntl.h
|
|
321 SREF(flock);
|
|
322 SREF(flock64);
|
|
323
|
|
324 // From ffi headers
|
|
325 SREF(_ffi_type);
|
|
326 TREF(ffi_cif);
|
|
327 TREF(ffi_abi);
|
|
328 TREF(ffi_status);
|
|
329 EREF(FFI_OK);
|
|
330
|
|
331 // From grp.h
|
|
332 SREF(group);
|
|
333
|
|
334 #if defined(HAVE_LINUX_FILTER_H)
|
|
335 // From linux/filter.h
|
|
336 SREF(sock_filter);
|
|
337 SREF(sock_fprog);
|
|
338 #endif
|
|
339
|
|
340 // From linux/if.h
|
|
341 EREF(IFF_UP);
|
|
342
|
|
343 #if defined(HAVE_LINUX_IF_ADDR_H)
|
|
344 // From linux/if_addr.h
|
|
345 SREF(ifaddrmsg);
|
|
346 EREF(IFA_ADDRESS);
|
|
347 #endif
|
|
348
|
|
349 #if defined(HAVE_LINUX_RTNETLINK_H)
|
|
350 // From linux/if_link.h
|
|
351 EREF(IFLA_ADDRESS);
|
|
352 #endif
|
|
353
|
|
354 // From in.h, in6.h, icmp6.h
|
|
355 SREF(ip_mreq);
|
|
356 SREF(ip_mreqn);
|
|
357 SREF(ipv6_mreq);
|
|
358 SREF(ip6_mtuinfo);
|
|
359 SREF(icmp6_filter);
|
|
360 SREF(in_pktinfo);
|
|
361 EREF(IPPROTO_TCP);
|
|
362
|
|
363 #if defined(HAVE_LINUX_RTNETLINK_H)
|
|
364 // From linux/rtnetlink.h
|
|
365 SREF(rtgenmsg);
|
|
366 SREF(rtmsg);
|
|
367 SREF(ifinfomsg);
|
|
368 SREF(rtattr);
|
|
369 SREF(rtnexthop);
|
|
370 EREF(RTM_BASE);
|
|
371 EREF(RTN_UNSPEC);
|
|
372 #endif
|
|
373
|
|
374 // From netdb.h
|
|
375 SREF(addrinfo);
|
|
376
|
|
377 // From netlink.h
|
|
378 SREF(nlattr);
|
|
379 SREF(nlmsgerr);
|
|
380
|
|
381 // From pthread.h and related
|
|
382 TREF(pthread_attr_t);
|
|
383 TREF(pthread_t);
|
|
384 TREF(pthread_mutex_t);
|
|
385 TREF(pthread_mutexattr_t);
|
|
386
|
|
387 // From pwd.h
|
|
388 SREF(passwd);
|
|
389
|
|
390 // From signal.h and related
|
|
391 TREF(sigset_t);
|
|
392 TREF(siginfo_t);
|
|
393 TREF(stack_t);
|
|
394 SREF(sigaction);
|
|
395 SREF(sigstack);
|
|
396 EREF(SI_USER);
|
|
397 EREF(FPE_INTOVF);
|
|
398 EREF(BUS_ADRALN);
|
|
399 EREF(SS_ONSTACK);
|
|
400 EREF(SEGV_MAPERR);
|
|
401
|
|
402 // From stat.h
|
|
403 SREF(stat64);
|
|
404
|
|
405 // From statfs.h
|
|
406 SREF(statfs);
|
|
407 SREF(statfs64);
|
|
408
|
|
409 // From sysinfo.h
|
|
410 SREF(sysinfo);
|
|
411
|
|
412 // From <sys/epoll.h>
|
|
413 #if defined(HAVE_SYS_EPOLL_H)
|
|
414 SREF(epoll_event);
|
|
415 EREF(EPOLLIN);
|
|
416 EREF(epoll_data_offset);
|
|
417 #endif
|
|
418
|
|
419 #if defined(HAVE_SYS_MOUNT_H)
|
|
420 // From sys/mount.h
|
|
421 EREF(MS_PRIVATE);
|
|
422 EREF(MNT_FORCE);
|
|
423 #endif
|
|
424
|
|
425 #if defined(HAVE_SYS_PTRACE_H)
|
|
426 // From <sys/ptrace.h>
|
145
|
427 #if defined (__aarch64__)
|
|
428 SREF(user_pt_regs);
|
|
429 #else
|
131
|
430 SREF(pt_regs);
|
145
|
431 #endif
|
131
|
432 EREF(PTRACE_PEEKTEXT);
|
|
433 #endif
|
|
434
|
|
435 // From sys/resource.h
|
|
436 SREF(rusage);
|
|
437 SREF(rlimit64);
|
|
438 EREF(RLIMIT_NOFILE);
|
|
439 EREF(PRIO_USER);
|
|
440
|
|
441 // From sys/select.h
|
|
442 TREF(fd_set);
|
|
443
|
|
444 // From sys/socket.h
|
|
445 SREF(msghdr);
|
|
446 SREF(cmsghdr);
|
|
447 SREF(ucred);
|
|
448 EREF(MSG_OOB);
|
|
449 EREF(SCM_RIGHTS);
|
|
450 EREF(SOCK_RAW);
|
|
451 EREF(SHUT_RD);
|
|
452
|
|
453 // From sys/time.h and sys/times.h
|
|
454 SREF(timespec);
|
|
455 SREF(timeval);
|
|
456 SREF(itimerval);
|
|
457 SREF(tms);
|
|
458 EREF(ITIMER_PROF);
|
|
459
|
|
460 #if defined(HAVE_SYS_TIMEX_H)
|
|
461 // From sys/timex.h
|
|
462 SREF(timex);
|
|
463 #endif
|
|
464
|
|
465 // From sys/types.h
|
|
466 TREF(pid_t);
|
|
467 TREF(off_t);
|
|
468 TREF(loff_t);
|
|
469 TREF(size_t);
|
|
470 TREF(ssize_t);
|
|
471 TREF(mode_t);
|
|
472 TREF(dev_t);
|
|
473 TREF(time_t);
|
|
474
|
|
475 // From sys/ucontext.h
|
|
476 TREF(ucontext_t);
|
|
477
|
|
478 #if defined(HAVE_SYS_USER_H)
|
|
479 // From sys/user.h
|
|
480 SREF(user_regs_struct);
|
|
481 #endif
|
|
482
|
|
483 #if defined(HAVE_SYS_UTSNAME_H)
|
|
484 // From sys/utsname.h
|
|
485 SREF(utsname);
|
|
486 #endif
|
|
487
|
|
488 // From termios.h
|
|
489 SREF(termios);
|
|
490
|
|
491 // From uio.h
|
|
492 SREF(iovec);
|
|
493
|
|
494 // From utime.h
|
|
495 SREF(utimbuf);
|
|
496
|
|
497 // From unistd.h
|
|
498 EREF(_PC_NAME_MAX);
|
|
499 EREF(_SC_GETPW_R_SIZE_MAX);
|
|
500
|
|
501 #endif // clang
|