Source file src/syscall/types_linux.go

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build ignore
     6  
     7  /*
     8  Input to cgo -godefs.  See also mkerrors.sh and mkall.sh
     9  */
    10  
    11  // +godefs map struct_in_addr [4]byte /* in_addr */
    12  // +godefs map struct_in6_addr [16]byte /* in6_addr */
    13  
    14  package syscall
    15  
    16  /*
    17  #define _LARGEFILE_SOURCE
    18  #define _LARGEFILE64_SOURCE
    19  #define _FILE_OFFSET_BITS 64
    20  #define _GNU_SOURCE
    21  
    22  #include <dirent.h>
    23  #include <fcntl.h>
    24  #include <netinet/in.h>
    25  #include <netinet/tcp.h>
    26  #include <netpacket/packet.h>
    27  #include <signal.h>
    28  #include <stdio.h>
    29  #include <sys/epoll.h>
    30  #include <sys/inotify.h>
    31  #include <sys/mman.h>
    32  #include <sys/mount.h>
    33  #include <sys/param.h>
    34  #include <sys/ptrace.h>
    35  #include <sys/resource.h>
    36  #include <sys/select.h>
    37  #include <sys/signal.h>
    38  #include <sys/stat.h>
    39  #include <sys/statfs.h>
    40  #include <sys/sysinfo.h>
    41  #include <sys/time.h>
    42  #include <sys/times.h>
    43  #include <sys/timex.h>
    44  #include <sys/types.h>
    45  #include <sys/un.h>
    46  #include <sys/user.h>
    47  #include <sys/utsname.h>
    48  #include <sys/wait.h>
    49  #include <linux/filter.h>
    50  #include <linux/netlink.h>
    51  #include <linux/rtnetlink.h>
    52  #include <linux/icmpv6.h>
    53  #include <poll.h>
    54  #include <termios.h>
    55  #include <time.h>
    56  #include <unistd.h>
    57  #include <utime.h>
    58  
    59  enum {
    60  	sizeofPtr = sizeof(void*),
    61  };
    62  
    63  union sockaddr_all {
    64  	struct sockaddr s1;	// this one gets used for fields
    65  	struct sockaddr_in s2;	// these pad it out
    66  	struct sockaddr_in6 s3;
    67  	struct sockaddr_un s4;
    68  	struct sockaddr_ll s5;
    69  	struct sockaddr_nl s6;
    70  };
    71  
    72  struct sockaddr_any {
    73  	struct sockaddr addr;
    74  	char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
    75  };
    76  
    77  // copied from /usr/include/linux/un.h
    78  struct my_sockaddr_un {
    79  	sa_family_t sun_family;
    80  #if defined(__ARM_EABI__) || defined(__powerpc64__) || defined(__riscv__) || defined(__s390x__)
    81  	// on ARM, PPC, RISC-V, and s390x char is by default unsigned
    82  	signed char sun_path[108];
    83  #else
    84  	char sun_path[108];
    85  #endif
    86  };
    87  
    88  #ifdef __ARM_EABI__
    89  typedef struct user_regs PtraceRegs;
    90  #elif defined(__aarch64__)
    91  typedef struct user_pt_regs PtraceRegs;
    92  #elif defined(__powerpc64__)
    93  typedef struct pt_regs PtraceRegs;
    94  #elif defined(__mips__)
    95  typedef struct user PtraceRegs;
    96  #elif defined(__s390x__)
    97  typedef struct _user_regs_struct PtraceRegs;
    98  #else
    99  typedef struct user_regs_struct PtraceRegs;
   100  #endif
   101  
   102  #if defined(__s390x__)
   103  typedef struct _user_psw_struct ptracePsw;
   104  typedef struct _user_fpregs_struct ptraceFpregs;
   105  typedef struct _user_per_struct ptracePer;
   106  #else
   107  typedef struct {} ptracePsw;
   108  typedef struct {} ptraceFpregs;
   109  typedef struct {} ptracePer;
   110  #endif
   111  
   112  // The real epoll_event is a union, and godefs doesn't handle it well.
   113  struct my_epoll_event {
   114  	uint32_t events;
   115  #if defined(__ARM_EABI__) || defined(__aarch64__) || (defined(__mips__) && _MIPS_SIM == _ABIO32)
   116  	// padding is not specified in linux/eventpoll.h but added to conform to the
   117  	// alignment requirements of EABI
   118  	int32_t padFd;
   119  #endif
   120  #if defined(__powerpc64__) || defined(__s390x__) || (defined(__riscv_xlen) && __riscv_xlen == 64) \
   121  		|| (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64)
   122  	int32_t _padFd;
   123  #endif
   124  	int32_t fd;
   125  	int32_t pad;
   126  };
   127  
   128  // ustat is deprecated and glibc 2.28 removed ustat.h. Provide the type here for
   129  // backwards compatibility. Copied from /usr/include/bits/ustat.h
   130  struct ustat {
   131  	__daddr_t f_tfree;
   132  	__ino_t f_tinode;
   133  	char f_fname[6];
   134  	char f_fpack[6];
   135  };
   136  
   137  */
   138  import "C"
   139  
   140  // Machine characteristics; for internal use.
   141  
   142  const (
   143  	sizeofPtr      = C.sizeofPtr
   144  	sizeofShort    = C.sizeof_short
   145  	sizeofInt      = C.sizeof_int
   146  	sizeofLong     = C.sizeof_long
   147  	sizeofLongLong = C.sizeof_longlong
   148  	PathMax        = C.PATH_MAX
   149  )
   150  
   151  // Basic types
   152  
   153  type (
   154  	_C_short     C.short
   155  	_C_int       C.int
   156  	_C_long      C.long
   157  	_C_long_long C.longlong
   158  )
   159  
   160  // Time
   161  
   162  type Timespec C.struct_timespec
   163  
   164  type Timeval C.struct_timeval
   165  
   166  type Timex C.struct_timex
   167  
   168  type Time_t C.time_t
   169  
   170  type Tms C.struct_tms
   171  
   172  type Utimbuf C.struct_utimbuf
   173  
   174  // Processes
   175  
   176  type Rusage C.struct_rusage
   177  
   178  type Rlimit C.struct_rlimit
   179  
   180  type _Gid_t C.gid_t
   181  
   182  // Files
   183  
   184  type Stat_t C.struct_stat
   185  
   186  type Statfs_t C.struct_statfs
   187  
   188  type Dirent C.struct_dirent
   189  
   190  type Fsid C.fsid_t
   191  
   192  type Flock_t C.struct_flock
   193  
   194  // Sockets
   195  
   196  type RawSockaddrInet4 C.struct_sockaddr_in
   197  
   198  type RawSockaddrInet6 C.struct_sockaddr_in6
   199  
   200  type RawSockaddrUnix C.struct_my_sockaddr_un
   201  
   202  type RawSockaddrLinklayer C.struct_sockaddr_ll
   203  
   204  type RawSockaddrNetlink C.struct_sockaddr_nl
   205  
   206  type RawSockaddr C.struct_sockaddr
   207  
   208  type RawSockaddrAny C.struct_sockaddr_any
   209  
   210  type _Socklen C.socklen_t
   211  
   212  type Linger C.struct_linger
   213  
   214  type Iovec C.struct_iovec
   215  
   216  type IPMreq C.struct_ip_mreq
   217  
   218  type IPMreqn C.struct_ip_mreqn
   219  
   220  type IPv6Mreq C.struct_ipv6_mreq
   221  
   222  type Msghdr C.struct_msghdr
   223  
   224  type Cmsghdr C.struct_cmsghdr
   225  
   226  type Inet4Pktinfo C.struct_in_pktinfo
   227  
   228  type Inet6Pktinfo C.struct_in6_pktinfo
   229  
   230  type IPv6MTUInfo C.struct_ip6_mtuinfo
   231  
   232  type ICMPv6Filter C.struct_icmp6_filter
   233  
   234  type Ucred C.struct_ucred
   235  
   236  type TCPInfo C.struct_tcp_info
   237  
   238  const (
   239  	SizeofSockaddrInet4     = C.sizeof_struct_sockaddr_in
   240  	SizeofSockaddrInet6     = C.sizeof_struct_sockaddr_in6
   241  	SizeofSockaddrAny       = C.sizeof_struct_sockaddr_any
   242  	SizeofSockaddrUnix      = C.sizeof_struct_sockaddr_un
   243  	SizeofSockaddrLinklayer = C.sizeof_struct_sockaddr_ll
   244  	SizeofSockaddrNetlink   = C.sizeof_struct_sockaddr_nl
   245  	SizeofLinger            = C.sizeof_struct_linger
   246  	SizeofIPMreq            = C.sizeof_struct_ip_mreq
   247  	SizeofIPMreqn           = C.sizeof_struct_ip_mreqn
   248  	SizeofIPv6Mreq          = C.sizeof_struct_ipv6_mreq
   249  	SizeofMsghdr            = C.sizeof_struct_msghdr
   250  	SizeofCmsghdr           = C.sizeof_struct_cmsghdr
   251  	SizeofInet4Pktinfo      = C.sizeof_struct_in_pktinfo
   252  	SizeofInet6Pktinfo      = C.sizeof_struct_in6_pktinfo
   253  	SizeofIPv6MTUInfo       = C.sizeof_struct_ip6_mtuinfo
   254  	SizeofICMPv6Filter      = C.sizeof_struct_icmp6_filter
   255  	SizeofUcred             = C.sizeof_struct_ucred
   256  	SizeofTCPInfo           = C.sizeof_struct_tcp_info
   257  )
   258  
   259  // Netlink routing and interface messages
   260  
   261  const (
   262  	IFA_UNSPEC          = C.IFA_UNSPEC
   263  	IFA_ADDRESS         = C.IFA_ADDRESS
   264  	IFA_LOCAL           = C.IFA_LOCAL
   265  	IFA_LABEL           = C.IFA_LABEL
   266  	IFA_BROADCAST       = C.IFA_BROADCAST
   267  	IFA_ANYCAST         = C.IFA_ANYCAST
   268  	IFA_CACHEINFO       = C.IFA_CACHEINFO
   269  	IFA_MULTICAST       = C.IFA_MULTICAST
   270  	IFLA_UNSPEC         = C.IFLA_UNSPEC
   271  	IFLA_ADDRESS        = C.IFLA_ADDRESS
   272  	IFLA_BROADCAST      = C.IFLA_BROADCAST
   273  	IFLA_IFNAME         = C.IFLA_IFNAME
   274  	IFLA_MTU            = C.IFLA_MTU
   275  	IFLA_LINK           = C.IFLA_LINK
   276  	IFLA_QDISC          = C.IFLA_QDISC
   277  	IFLA_STATS          = C.IFLA_STATS
   278  	IFLA_COST           = C.IFLA_COST
   279  	IFLA_PRIORITY       = C.IFLA_PRIORITY
   280  	IFLA_MASTER         = C.IFLA_MASTER
   281  	IFLA_WIRELESS       = C.IFLA_WIRELESS
   282  	IFLA_PROTINFO       = C.IFLA_PROTINFO
   283  	IFLA_TXQLEN         = C.IFLA_TXQLEN
   284  	IFLA_MAP            = C.IFLA_MAP
   285  	IFLA_WEIGHT         = C.IFLA_WEIGHT
   286  	IFLA_OPERSTATE      = C.IFLA_OPERSTATE
   287  	IFLA_LINKMODE       = C.IFLA_LINKMODE
   288  	IFLA_LINKINFO       = C.IFLA_LINKINFO
   289  	IFLA_NET_NS_PID     = C.IFLA_NET_NS_PID
   290  	IFLA_IFALIAS        = C.IFLA_IFALIAS
   291  	IFLA_MAX            = C.IFLA_MAX
   292  	RT_SCOPE_UNIVERSE   = C.RT_SCOPE_UNIVERSE
   293  	RT_SCOPE_SITE       = C.RT_SCOPE_SITE
   294  	RT_SCOPE_LINK       = C.RT_SCOPE_LINK
   295  	RT_SCOPE_HOST       = C.RT_SCOPE_HOST
   296  	RT_SCOPE_NOWHERE    = C.RT_SCOPE_NOWHERE
   297  	RT_TABLE_UNSPEC     = C.RT_TABLE_UNSPEC
   298  	RT_TABLE_COMPAT     = C.RT_TABLE_COMPAT
   299  	RT_TABLE_DEFAULT    = C.RT_TABLE_DEFAULT
   300  	RT_TABLE_MAIN       = C.RT_TABLE_MAIN
   301  	RT_TABLE_LOCAL      = C.RT_TABLE_LOCAL
   302  	RT_TABLE_MAX        = C.RT_TABLE_MAX
   303  	RTA_UNSPEC          = C.RTA_UNSPEC
   304  	RTA_DST             = C.RTA_DST
   305  	RTA_SRC             = C.RTA_SRC
   306  	RTA_IIF             = C.RTA_IIF
   307  	RTA_OIF             = C.RTA_OIF
   308  	RTA_GATEWAY         = C.RTA_GATEWAY
   309  	RTA_PRIORITY        = C.RTA_PRIORITY
   310  	RTA_PREFSRC         = C.RTA_PREFSRC
   311  	RTA_METRICS         = C.RTA_METRICS
   312  	RTA_MULTIPATH       = C.RTA_MULTIPATH
   313  	RTA_FLOW            = C.RTA_FLOW
   314  	RTA_CACHEINFO       = C.RTA_CACHEINFO
   315  	RTA_TABLE           = C.RTA_TABLE
   316  	RTN_UNSPEC          = C.RTN_UNSPEC
   317  	RTN_UNICAST         = C.RTN_UNICAST
   318  	RTN_LOCAL           = C.RTN_LOCAL
   319  	RTN_BROADCAST       = C.RTN_BROADCAST
   320  	RTN_ANYCAST         = C.RTN_ANYCAST
   321  	RTN_MULTICAST       = C.RTN_MULTICAST
   322  	RTN_BLACKHOLE       = C.RTN_BLACKHOLE
   323  	RTN_UNREACHABLE     = C.RTN_UNREACHABLE
   324  	RTN_PROHIBIT        = C.RTN_PROHIBIT
   325  	RTN_THROW           = C.RTN_THROW
   326  	RTN_NAT             = C.RTN_NAT
   327  	RTN_XRESOLVE        = C.RTN_XRESOLVE
   328  	RTNLGRP_NONE        = C.RTNLGRP_NONE
   329  	RTNLGRP_LINK        = C.RTNLGRP_LINK
   330  	RTNLGRP_NOTIFY      = C.RTNLGRP_NOTIFY
   331  	RTNLGRP_NEIGH       = C.RTNLGRP_NEIGH
   332  	RTNLGRP_TC          = C.RTNLGRP_TC
   333  	RTNLGRP_IPV4_IFADDR = C.RTNLGRP_IPV4_IFADDR
   334  	RTNLGRP_IPV4_MROUTE = C.RTNLGRP_IPV4_MROUTE
   335  	RTNLGRP_IPV4_ROUTE  = C.RTNLGRP_IPV4_ROUTE
   336  	RTNLGRP_IPV4_RULE   = C.RTNLGRP_IPV4_RULE
   337  	RTNLGRP_IPV6_IFADDR = C.RTNLGRP_IPV6_IFADDR
   338  	RTNLGRP_IPV6_MROUTE = C.RTNLGRP_IPV6_MROUTE
   339  	RTNLGRP_IPV6_ROUTE  = C.RTNLGRP_IPV6_ROUTE
   340  	RTNLGRP_IPV6_IFINFO = C.RTNLGRP_IPV6_IFINFO
   341  	RTNLGRP_IPV6_PREFIX = C.RTNLGRP_IPV6_PREFIX
   342  	RTNLGRP_IPV6_RULE   = C.RTNLGRP_IPV6_RULE
   343  	RTNLGRP_ND_USEROPT  = C.RTNLGRP_ND_USEROPT
   344  	SizeofNlMsghdr      = C.sizeof_struct_nlmsghdr
   345  	SizeofNlMsgerr      = C.sizeof_struct_nlmsgerr
   346  	SizeofRtGenmsg      = C.sizeof_struct_rtgenmsg
   347  	SizeofNlAttr        = C.sizeof_struct_nlattr
   348  	SizeofRtAttr        = C.sizeof_struct_rtattr
   349  	SizeofIfInfomsg     = C.sizeof_struct_ifinfomsg
   350  	SizeofIfAddrmsg     = C.sizeof_struct_ifaddrmsg
   351  	SizeofRtMsg         = C.sizeof_struct_rtmsg
   352  	SizeofRtNexthop     = C.sizeof_struct_rtnexthop
   353  )
   354  
   355  type NlMsghdr C.struct_nlmsghdr
   356  
   357  type NlMsgerr C.struct_nlmsgerr
   358  
   359  type RtGenmsg C.struct_rtgenmsg
   360  
   361  type NlAttr C.struct_nlattr
   362  
   363  type RtAttr C.struct_rtattr
   364  
   365  type IfInfomsg C.struct_ifinfomsg
   366  
   367  type IfAddrmsg C.struct_ifaddrmsg
   368  
   369  type RtMsg C.struct_rtmsg
   370  
   371  type RtNexthop C.struct_rtnexthop
   372  
   373  // Linux socket filter
   374  
   375  const (
   376  	SizeofSockFilter = C.sizeof_struct_sock_filter
   377  	SizeofSockFprog  = C.sizeof_struct_sock_fprog
   378  )
   379  
   380  type SockFilter C.struct_sock_filter
   381  
   382  type SockFprog C.struct_sock_fprog
   383  
   384  // Inotify
   385  
   386  type InotifyEvent C.struct_inotify_event
   387  
   388  const SizeofInotifyEvent = C.sizeof_struct_inotify_event
   389  
   390  // Ptrace
   391  
   392  // Register structures
   393  type PtraceRegs C.PtraceRegs
   394  
   395  // Structures contained in PtraceRegs on s390x (exported by post.go)
   396  type ptracePsw C.ptracePsw
   397  
   398  type ptraceFpregs C.ptraceFpregs
   399  
   400  type ptracePer C.ptracePer
   401  
   402  // Misc
   403  
   404  type FdSet C.fd_set
   405  
   406  type Sysinfo_t C.struct_sysinfo
   407  
   408  type Utsname C.struct_utsname
   409  
   410  type Ustat_t C.struct_ustat
   411  
   412  type EpollEvent C.struct_my_epoll_event
   413  
   414  const (
   415  	_AT_FDCWD            = C.AT_FDCWD
   416  	_AT_REMOVEDIR        = C.AT_REMOVEDIR
   417  	_AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
   418  	_AT_EACCESS          = C.AT_EACCESS
   419  )
   420  
   421  type pollFd C.struct_pollfd
   422  
   423  // Terminal handling
   424  
   425  type Termios C.struct_termios
   426  
   427  const (
   428  	IUCLC  = C.IUCLC
   429  	OLCUC  = C.OLCUC
   430  	TCGETS = C.TCGETS
   431  	TCSETS = C.TCSETS
   432  	XCASE  = C.XCASE
   433  )
   434  

View as plain text