github.com/kidsbmilk/gofrontend_all@v0.0.0-20220701224323-6479d5976c5d/libgo/sysinfo.c (about)

     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  #if defined(HAVE_LOFF_T)
   361  // loff_t can be defined as a macro; for -fgo-dump-spec make sure we
   362  // see a typedef.
   363  typedef loff_t libgo_loff_t_type;
   364  #endif
   365  
   366  #if defined(HAVE_OFF64_T)
   367  typedef off64_t libgo_off_t_type;
   368  #else
   369  typedef off_t libgo_off_t_type;
   370  #endif
   371  
   372  // The following section introduces explicit references to types and
   373  // constants of interest to support bootstrapping libgo using a
   374  // compiler that doesn't support -fdump-go-spec (e.g., clang), via
   375  // DWARF-based tools. This process is made more difficult due to the
   376  // fact that clang tries hard to omit types/constants from DWARF if it
   377  // can't find explicit references to them, so here we make sure that
   378  // key items are mentioned in ways that will force them into the
   379  // generated DWARF.
   380  
   381  #if defined(__clang__)
   382  
   383  // Make a reference to a type
   384  #define TREF(typ) typ typ ## ref
   385  
   386  // Make a reference to an opaque type
   387  #define OTREF(typ) typ *typ ## ref
   388  
   389  // Make a reference to a struct tag
   390  #define SREF(stag) struct stag stag ## ref
   391  
   392  // Make a reference to an enum literal
   393  #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
   394  
   395  //......................................................................
   396  
   397  // From dirent.h
   398  SREF(dirent);
   399  SREF(dirent64);
   400  OTREF(DIR);
   401  EREF(DT_UNKNOWN);
   402  
   403  // From fcntl.h
   404  SREF(flock);
   405  SREF(flock64);
   406  
   407  // From ffi headers
   408  SREF(_ffi_type);
   409  TREF(ffi_cif);
   410  TREF(ffi_abi);
   411  TREF(ffi_status);
   412  EREF(FFI_OK);
   413  
   414  // From grp.h
   415  SREF(group);
   416  
   417  #if defined(HAVE_LINUX_FILTER_H)
   418  // From linux/filter.h
   419  SREF(sock_filter);
   420  SREF(sock_fprog);
   421  #endif
   422  
   423  // From linux/if.h
   424  EREF(IFF_UP);
   425  
   426  #if defined(HAVE_LINUX_IF_ADDR_H)
   427  // From linux/if_addr.h
   428  SREF(ifaddrmsg);
   429  EREF(IFA_ADDRESS);
   430  #endif
   431  
   432  #if defined(HAVE_LINUX_RTNETLINK_H)
   433  // From linux/if_link.h
   434  EREF(IFLA_ADDRESS);
   435  #endif
   436  
   437  // From in.h, in6.h, icmp6.h
   438  SREF(ip_mreq);
   439  SREF(ip_mreqn);
   440  SREF(ipv6_mreq);
   441  SREF(ip6_mtuinfo);
   442  SREF(icmp6_filter);
   443  SREF(in_pktinfo);
   444  EREF(IPPROTO_TCP);
   445  
   446  #if defined(HAVE_LINUX_RTNETLINK_H)
   447  // From linux/rtnetlink.h
   448  SREF(rtgenmsg);
   449  SREF(rtmsg);
   450  SREF(ifinfomsg);
   451  SREF(rtattr);
   452  SREF(rtnexthop);
   453  EREF(RTM_BASE);
   454  EREF(RTN_UNSPEC);
   455  #endif
   456  
   457  // From netdb.h
   458  SREF(addrinfo);
   459  
   460  // From netlink.h
   461  SREF(nlattr);
   462  SREF(nlmsgerr);
   463  
   464  // From pthread.h and related
   465  TREF(pthread_attr_t);
   466  TREF(pthread_t);
   467  TREF(pthread_mutex_t);
   468  TREF(pthread_mutexattr_t);
   469  
   470  // From pwd.h
   471  SREF(passwd);
   472  
   473  // From signal.h and related
   474  TREF(sigset_t);
   475  TREF(siginfo_t);
   476  TREF(stack_t);
   477  SREF(sigaction);
   478  SREF(sigstack);
   479  EREF(SI_USER);
   480  EREF(FPE_INTOVF);
   481  EREF(BUS_ADRALN);
   482  EREF(SS_ONSTACK);
   483  EREF(SEGV_MAPERR);
   484  
   485  // From stat.h
   486  SREF(stat64);
   487  
   488  // From statfs.h
   489  SREF(statfs);
   490  SREF(statfs64);
   491  
   492  // From sysinfo.h
   493  SREF(sysinfo);
   494  
   495  // From <sys/epoll.h>
   496  #if defined(HAVE_SYS_EPOLL_H)
   497  SREF(epoll_event);
   498  EREF(EPOLLIN);
   499  EREF(epoll_data_offset);
   500  #endif
   501  
   502  #if defined(HAVE_SYS_MOUNT_H)
   503  // From sys/mount.h
   504  EREF(MS_PRIVATE);
   505  EREF(MNT_FORCE);
   506  #endif
   507  
   508  #if defined(HAVE_SYS_PTRACE_H)
   509  // From <sys/ptrace.h>
   510  #if defined (__aarch64__)
   511  SREF(user_pt_regs);
   512  #else
   513  SREF(pt_regs);
   514  #endif
   515  EREF(PTRACE_PEEKTEXT);
   516  #endif
   517  
   518  // From sys/resource.h
   519  SREF(rusage);
   520  SREF(rlimit64);
   521  EREF(RLIMIT_NOFILE);
   522  EREF(PRIO_USER);
   523  EREF(RUSAGE_SELF);
   524  
   525  // From sys/select.h
   526  TREF(fd_set);
   527  
   528  // From sys/socket.h
   529  SREF(msghdr);
   530  SREF(cmsghdr);
   531  SREF(ucred);
   532  EREF(MSG_OOB);
   533  EREF(SCM_RIGHTS);
   534  EREF(SOCK_RAW);
   535  EREF(SHUT_RD);
   536  
   537  // From sys/time.h and sys/times.h
   538  SREF(timespec);
   539  SREF(timeval);
   540  SREF(itimerval);
   541  SREF(tms);
   542  EREF(ITIMER_PROF);
   543  
   544  #if defined(HAVE_SYS_TIMEX_H)
   545  // From sys/timex.h
   546  SREF(timex);
   547  #endif
   548  
   549  // From sys/types.h
   550  TREF(pid_t);
   551  TREF(off_t);
   552  TREF(libgo_loff_t_type);
   553  TREF(libgo_off_t_type);
   554  TREF(size_t);
   555  TREF(ssize_t);
   556  TREF(mode_t);
   557  TREF(dev_t);
   558  TREF(time_t);
   559  
   560  // From sys/ucontext.h
   561  TREF(ucontext_t);
   562  
   563  #if defined(HAVE_SYS_USER_H)
   564  // From sys/user.h
   565  SREF(user_regs_struct);
   566  #endif
   567  
   568  #if defined(HAVE_SYS_UTSNAME_H)
   569  // From sys/utsname.h
   570  SREF(utsname);
   571  #endif
   572  
   573  // From termios.h
   574  SREF(termios);
   575  
   576  // From uio.h
   577  SREF(iovec);
   578  
   579  // From utime.h
   580  SREF(utimbuf);
   581  
   582  // From unistd.h
   583  EREF(_PC_NAME_MAX);
   584  EREF(_SC_GETPW_R_SIZE_MAX);
   585  
   586  #endif // clang