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 <stdlib.h> 14 #include <stdio.h> 15 #include <sys/types.h> 16 #include <dirent.h> 17 #include <errno.h> 18 #include <fcntl.h> 19 #include <ucontext.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 23 && !_XOPEN_SOURCE. 24 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while 25 <sys/ttold.h> does so unconditionally. */ 26 #ifdef __sgi__ 27 #include <sys/bsd_types.h> 28 #include <sys/ttold.h> 29 #endif 30 #include <netinet/tcp.h> 31 #if defined(HAVE_NETINET_IN_SYSTM_H) 32 #include <netinet/in_systm.h> 33 #endif 34 #if defined(HAVE_NETINET_IP_H) 35 #include <netinet/ip.h> 36 #endif 37 #if defined(HAVE_NETINET_IP_MROUTE_H) 38 #include <netinet/ip_mroute.h> 39 #endif 40 #if defined(HAVE_NETINET_IF_ETHER_H) 41 #include <netinet/if_ether.h> 42 #endif 43 #include <signal.h> 44 #include <sys/ioctl.h> 45 #include <termios.h> 46 #if defined(HAVE_SYSCALL_H) 47 #include <syscall.h> 48 #endif 49 #if defined(HAVE_SYS_SYSCALL_H) 50 #include <sys/syscall.h> 51 #endif 52 #if defined(HAVE_SYS_SYSCTL_H) 53 #include <sys/sysctl.h> 54 #endif 55 #if defined(HAVE_SYS_EPOLL_H) 56 #include <sys/epoll.h> 57 #endif 58 #if defined(HAVE_SYS_EVENT_H) 59 #include <sys/event.h> 60 #endif 61 #if defined(HAVE_SYS_FILE_H) 62 #include <sys/file.h> 63 #endif 64 #if defined(HAVE_SYS_MMAN_H) 65 #include <sys/mman.h> 66 #endif 67 #if defined(HAVE_SYS_PRCTL_H) 68 #include <sys/prctl.h> 69 #endif 70 #if defined(HAVE_SYS_PTRACE_H) 71 #include <sys/ptrace.h> 72 #endif 73 #include <sys/resource.h> 74 #include <sys/uio.h> 75 #include <sys/socket.h> 76 #include <sys/stat.h> 77 #include <sys/time.h> 78 #include <sys/times.h> 79 #include <sys/wait.h> 80 #include <sys/un.h> 81 #if defined(HAVE_SYS_USER_H) 82 #include <sys/user.h> 83 #endif 84 #if defined(HAVE_SYS_UTSNAME_H) 85 #include <sys/utsname.h> 86 #endif 87 #if defined(HAVE_SYS_SELECT_H) 88 #include <sys/select.h> 89 #endif 90 #include <time.h> 91 #include <unistd.h> 92 #include <netdb.h> 93 #include <pwd.h> 94 #include <grp.h> 95 #if defined(HAVE_LINUX_FILTER_H) 96 #include <linux/filter.h> 97 #endif 98 #if defined(HAVE_LINUX_IF_ADDR_H) 99 #include <linux/if_addr.h> 100 #endif 101 #if defined(HAVE_LINUX_IF_ETHER_H) 102 #include <linux/if_ether.h> 103 #endif 104 #if defined(HAVE_LINUX_IF_TUN_H) 105 #include <linux/if_tun.h> 106 #endif 107 #if defined(HAVE_LINUX_NETLINK_H) 108 #include <linux/netlink.h> 109 #endif 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> 118 #undef ia64_fpreg 119 #undef pt_all_user_regs 120 #undef ptrace_peeksiginfo_args 121 #endif 122 #if defined(HAVE_LINUX_RTNETLINK_H) 123 #include <linux/rtnetlink.h> 124 #endif 125 #if defined(HAVE_NET_BPF_H) 126 #include <net/bpf.h> 127 #endif 128 #if defined(HAVE_NET_IF_H) 129 #include <net/if.h> 130 #endif 131 #if defined(HAVE_NET_IF_ARP_H) 132 #include <net/if_arp.h> 133 #endif 134 #if defined(HAVE_NET_ROUTE_H) 135 #include <net/route.h> 136 #endif 137 #if defined (HAVE_NETPACKET_PACKET_H) 138 #include <netpacket/packet.h> 139 #endif 140 #if defined(HAVE_SYS_MOUNT_H) 141 #include <sys/mount.h> 142 #endif 143 #if defined(HAVE_SYS_VFS_H) 144 #include <sys/vfs.h> 145 #endif 146 #if defined(HAVE_STATFS_H) 147 #include <sys/statfs.h> 148 #endif 149 #if defined(HAVE_SYS_TIMEX_H) 150 #include <sys/timex.h> 151 #endif 152 #if defined(HAVE_SYS_SYSINFO_H) 153 #include <sys/sysinfo.h> 154 #endif 155 #if defined(HAVE_UTIME_H) 156 #include <utime.h> 157 #endif 158 #if defined(HAVE_LINUX_ETHER_H) 159 #include <linux/ether.h> 160 #endif 161 #if defined(HAVE_LINUX_FS_H) 162 #include <linux/fs.h> 163 #endif 164 #if defined(HAVE_LINUX_REBOOT_H) 165 #include <linux/reboot.h> 166 #endif 167 #if defined(HAVE_SYS_INOTIFY_H) 168 #include <sys/inotify.h> 169 #endif 170 #if defined(HAVE_NETINET_ICMP6_H) 171 #include <netinet/icmp6.h> 172 #endif 173 #if defined(HAVE_SCHED_H) 174 #include <sched.h> 175 #endif 176 #if defined(HAVE_SEMAPHORE_H) 177 #include <semaphore.h> 178 #endif 179 #if defined(HAVE_PORT_H) 180 #include <port.h> 181 #endif 182 #if defined(HAVE_LWP_H) 183 #include <lwp.h> 184 #endif 185 186 #ifdef USE_LIBFFI 187 #include "ffi.h" 188 #endif 189 190 /* Constants that may only be defined as expressions on some systems, 191 expressions too complex for -fdump-go-spec to handle. These are 192 handled specially below. */ 193 enum { 194 #ifdef TIOCGWINSZ 195 TIOCGWINSZ_val = TIOCGWINSZ, 196 #endif 197 #ifdef TIOCSWINSZ 198 TIOCSWINSZ_val = TIOCSWINSZ, 199 #endif 200 #ifdef TIOCNOTTY 201 TIOCNOTTY_val = TIOCNOTTY, 202 #endif 203 #ifdef TIOCSCTTY 204 TIOCSCTTY_val = TIOCSCTTY, 205 #endif 206 #ifdef TIOCGPGRP 207 TIOCGPGRP_val = TIOCGPGRP, 208 #endif 209 #ifdef TIOCSPGRP 210 TIOCSPGRP_val = TIOCSPGRP, 211 #endif 212 #ifdef TIOCGPTN 213 TIOCGPTN_val = TIOCGPTN, 214 #endif 215 #ifdef TIOCSPTLCK 216 TIOCSPTLCK_val = TIOCSPTLCK, 217 #endif 218 #ifdef TIOCGDEV 219 TIOCGDEV_val = TIOCGDEV, 220 #endif 221 #ifdef TIOCSIG 222 TIOCSIG_val = TIOCSIG, 223 #endif 224 #ifdef TCGETS 225 TCGETS_val = TCGETS, 226 #endif 227 #ifdef TCSETS 228 TCSETS_val = TCSETS, 229 #endif 230 #ifdef TUNSETIFF 231 TUNSETIFF_val = TUNSETIFF, 232 #endif 233 #ifdef TUNSETNOCSUM 234 TUNSETNOCSUM_val = TUNSETNOCSUM, 235 #endif 236 #ifdef TUNSETDEBUG 237 TUNSETDEBUG_val = TUNSETDEBUG, 238 #endif 239 #ifdef TUNSETPERSIST 240 TUNSETPERSIST_val = TUNSETPERSIST, 241 #endif 242 #ifdef TUNSETOWNER 243 TUNSETOWNER_val = TUNSETOWNER, 244 #endif 245 #ifdef TUNSETLINK 246 TUNSETLINK_val = TUNSETLINK, 247 #endif 248 #ifdef TUNSETGROUP 249 TUNSETGROUP_val = TUNSETGROUP, 250 #endif 251 #ifdef TUNGETFEATURES 252 TUNGETFEATURES_val = TUNGETFEATURES, 253 #endif 254 #ifdef TUNSETOFFLOAD 255 TUNSETOFFLOAD_val = TUNSETOFFLOAD, 256 #endif 257 #ifdef TUNSETTXFILTER 258 TUNSETTXFILTER_val = TUNSETTXFILTER, 259 #endif 260 #ifdef TUNGETIFF 261 TUNGETIFF_val = TUNGETIFF, 262 #endif 263 #ifdef TUNGETSNDBUF 264 TUNGETSNDBUF_val = TUNGETSNDBUF, 265 #endif 266 #ifdef TUNSETSNDBUF 267 TUNSETSNDBUF_val = TUNSETSNDBUF, 268 #endif 269 #ifdef TUNATTACHFILTER 270 TUNATTACHFILTER_val = TUNATTACHFILTER, 271 #endif 272 #ifdef TUNDETACHFILTER 273 TUNDETACHFILTER_val = TUNDETACHFILTER, 274 #endif 275 #ifdef TUNGETVNETHDRSZ 276 TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ, 277 #endif 278 #ifdef TUNSETVNETHDRSZ 279 TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ, 280 #endif 281 #ifdef TUNSETQUEUE 282 TUNSETQUEUE_val = TUNSETQUEUE, 283 #endif 284 #ifdef TUNSETIFINDEX 285 TUNSETIFINDEX_val = TUNSETIFINDEX, 286 #endif 287 #ifdef TUNGETFILTER 288 TUNGETFILTER_val = TUNGETFILTER, 289 #endif 290 #ifdef NLA_HDRLEN 291 NLA_HDRLEN_val = NLA_HDRLEN, 292 #endif 293 #ifdef BIOCFLUSH 294 BIOCFLUSH_val = BIOCFLUSH, 295 #endif 296 #ifdef BIOCGBLEN 297 BIOCGBLEN_val = BIOCGBLEN, 298 #endif 299 #ifdef BIOCGDLT 300 BIOCGDLT_val = BIOCGDLT, 301 #endif 302 #ifdef BIOCGETIF 303 BIOCGETIF_val = BIOCGETIF, 304 #endif 305 #ifdef BIOCGHDRCMPLT 306 BIOCGHDRCMPLT_val = BIOCGHDRCMPLT, 307 #endif 308 #ifdef BIOCGRTIMEOUT 309 BIOCGRTIMEOUT_val = BIOCGRTIMEOUT, 310 #endif 311 #ifdef BIOCGSTATS 312 BIOCGSTATS_val = BIOCGSTATS, 313 #endif 314 #ifdef BIOCIMMEDIATE 315 BIOCIMMEDIATE_val = BIOCIMMEDIATE, 316 #endif 317 #ifdef BIOCPROMISC 318 BIOCPROMISC_val = BIOCPROMISC, 319 #endif 320 #ifdef BIOCSBLEN 321 BIOCSBLEN_val = BIOCSBLEN, 322 #endif 323 #ifdef BIOCSDLT 324 BIOCSDLT_val = BIOCSDLT, 325 #endif 326 #ifdef BIOCSETF 327 BIOCSETF_val = BIOCSETF, 328 #endif 329 #ifdef BIOCSETIF 330 BIOCSETIF_val = BIOCSETIF, 331 #endif 332 #ifdef BIOCSHDRCMPLT 333 BIOCSHDRCMPLT_val = BIOCSHDRCMPLT, 334 #endif 335 #ifdef BIOCSRTIMEOUT 336 BIOCSRTIMEOUT_val = BIOCSRTIMEOUT, 337 #endif 338 #ifdef BIOCVERSION 339 BIOCVERSION_val = BIOCVERSION, 340 #endif 341 #ifdef SO_RCVTIMEO 342 SO_RCVTIMEO_val = SO_RCVTIMEO, 343 #endif 344 }; 345 346 // SIOCGIFMTU can't be added in the above enum as it might 347 // be signed in some OSes. 348 #ifdef SIOCGIFMTU 349 enum { 350 SIOCGIFMTU_val = SIOCGIFMTU, 351 }; 352 #endif 353 354 #if defined(HAVE_SYS_EPOLL_H) 355 enum { 356 epoll_data_offset = offsetof(struct epoll_event, data) 357 }; 358 #endif 359 360 // The following section introduces explicit references to types and 361 // constants of interest to support bootstrapping libgo using a 362 // compiler that doesn't support -fdump-go-spec (e.g., clang), via 363 // DWARF-based tools. This process is made more difficult due to the 364 // fact that clang tries hard to omit types/constants from DWARF if it 365 // can't find explicit references to them, so here we make sure that 366 // key items are mentioned in ways that will force them into the 367 // generated DWARF. 368 369 #if defined(__clang__) 370 371 // Make a reference to a type 372 #define TREF(typ) typ typ ## ref 373 374 // Make a reference to an opaque type 375 #define OTREF(typ) typ *typ ## ref 376 377 // Make a reference to a struct tag 378 #define SREF(stag) struct stag stag ## ref 379 380 // Make a reference to an enum literal 381 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; } 382 383 //...................................................................... 384 385 // From dirent.h 386 SREF(dirent); 387 SREF(dirent64); 388 OTREF(DIR); 389 EREF(DT_UNKNOWN); 390 391 // From fcntl.h 392 SREF(flock); 393 SREF(flock64); 394 395 // From ffi headers 396 SREF(_ffi_type); 397 TREF(ffi_cif); 398 TREF(ffi_abi); 399 TREF(ffi_status); 400 EREF(FFI_OK); 401 402 // From grp.h 403 SREF(group); 404 405 #if defined(HAVE_LINUX_FILTER_H) 406 // From linux/filter.h 407 SREF(sock_filter); 408 SREF(sock_fprog); 409 #endif 410 411 // From linux/if.h 412 EREF(IFF_UP); 413 414 #if defined(HAVE_LINUX_IF_ADDR_H) 415 // From linux/if_addr.h 416 SREF(ifaddrmsg); 417 EREF(IFA_ADDRESS); 418 #endif 419 420 #if defined(HAVE_LINUX_RTNETLINK_H) 421 // From linux/if_link.h 422 EREF(IFLA_ADDRESS); 423 #endif 424 425 // From in.h, in6.h, icmp6.h 426 SREF(ip_mreq); 427 SREF(ip_mreqn); 428 SREF(ipv6_mreq); 429 SREF(ip6_mtuinfo); 430 SREF(icmp6_filter); 431 SREF(in_pktinfo); 432 EREF(IPPROTO_TCP); 433 434 #if defined(HAVE_LINUX_RTNETLINK_H) 435 // From linux/rtnetlink.h 436 SREF(rtgenmsg); 437 SREF(rtmsg); 438 SREF(ifinfomsg); 439 SREF(rtattr); 440 SREF(rtnexthop); 441 EREF(RTM_BASE); 442 EREF(RTN_UNSPEC); 443 #endif 444 445 // From netdb.h 446 SREF(addrinfo); 447 448 // From netlink.h 449 SREF(nlattr); 450 SREF(nlmsgerr); 451 452 // From pthread.h and related 453 TREF(pthread_attr_t); 454 TREF(pthread_t); 455 TREF(pthread_mutex_t); 456 TREF(pthread_mutexattr_t); 457 458 // From pwd.h 459 SREF(passwd); 460 461 // From signal.h and related 462 TREF(sigset_t); 463 TREF(siginfo_t); 464 TREF(stack_t); 465 SREF(sigaction); 466 SREF(sigstack); 467 EREF(SI_USER); 468 EREF(FPE_INTOVF); 469 EREF(BUS_ADRALN); 470 EREF(SS_ONSTACK); 471 EREF(SEGV_MAPERR); 472 473 // From stat.h 474 SREF(stat64); 475 476 // From statfs.h 477 SREF(statfs); 478 SREF(statfs64); 479 480 // From sysinfo.h 481 SREF(sysinfo); 482 483 // From <sys/epoll.h> 484 #if defined(HAVE_SYS_EPOLL_H) 485 SREF(epoll_event); 486 EREF(EPOLLIN); 487 EREF(epoll_data_offset); 488 #endif 489 490 #if defined(HAVE_SYS_MOUNT_H) 491 // From sys/mount.h 492 EREF(MS_PRIVATE); 493 EREF(MNT_FORCE); 494 #endif 495 496 #if defined(HAVE_SYS_PTRACE_H) 497 // From <sys/ptrace.h> 498 #if defined (__aarch64__) 499 SREF(user_pt_regs); 500 #else 501 SREF(pt_regs); 502 #endif 503 EREF(PTRACE_PEEKTEXT); 504 #endif 505 506 // From sys/resource.h 507 SREF(rusage); 508 SREF(rlimit64); 509 EREF(RLIMIT_NOFILE); 510 EREF(PRIO_USER); 511 EREF(RUSAGE_SELF); 512 513 // From sys/select.h 514 TREF(fd_set); 515 516 // From sys/socket.h 517 SREF(msghdr); 518 SREF(cmsghdr); 519 SREF(ucred); 520 EREF(MSG_OOB); 521 EREF(SCM_RIGHTS); 522 EREF(SOCK_RAW); 523 EREF(SHUT_RD); 524 525 // From sys/time.h and sys/times.h 526 SREF(timespec); 527 SREF(timeval); 528 SREF(itimerval); 529 SREF(tms); 530 EREF(ITIMER_PROF); 531 532 #if defined(HAVE_SYS_TIMEX_H) 533 // From sys/timex.h 534 SREF(timex); 535 #endif 536 537 // From sys/types.h 538 TREF(pid_t); 539 TREF(off_t); 540 TREF(loff_t); 541 TREF(size_t); 542 TREF(ssize_t); 543 TREF(mode_t); 544 TREF(dev_t); 545 TREF(time_t); 546 547 // From sys/ucontext.h 548 TREF(ucontext_t); 549 550 #if defined(HAVE_SYS_USER_H) 551 // From sys/user.h 552 SREF(user_regs_struct); 553 #endif 554 555 #if defined(HAVE_SYS_UTSNAME_H) 556 // From sys/utsname.h 557 SREF(utsname); 558 #endif 559 560 // From termios.h 561 SREF(termios); 562 563 // From uio.h 564 SREF(iovec); 565 566 // From utime.h 567 SREF(utimbuf); 568 569 // From unistd.h 570 EREF(_PC_NAME_MAX); 571 EREF(_SC_GETPW_R_SIZE_MAX); 572 573 #endif // clang 574