github.com/mergetb/u-root@v4.0.1-0.20190719191109-b70b86b73e5b+incompatible/pkg/abi/abi_linux.go (about)

     1  // Copyright 2018 Google LLC.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package abi
    16  
    17  import (
    18  	"math"
    19  	"syscall"
    20  	"time"
    21  
    22  	"github.com/u-root/u-root/pkg/binary"
    23  	"golang.org/x/sys/unix"
    24  )
    25  
    26  // From <linux/futex.h> and <sys/time.h>.
    27  // Flags are used in syscall futex(2).
    28  const (
    29  	FUTEX_WAIT            = 0
    30  	FUTEX_WAKE            = 1
    31  	FUTEX_FD              = 2
    32  	FUTEX_REQUEUE         = 3
    33  	FUTEX_CMP_REQUEUE     = 4
    34  	FUTEX_WAKE_OP         = 5
    35  	FUTEX_LOCK_PI         = 6
    36  	FUTEX_UNLOCK_PI       = 7
    37  	FUTEX_TRYLOCK_PI      = 8
    38  	FUTEX_WAIT_BITSET     = 9
    39  	FUTEX_WAKE_BITSET     = 10
    40  	FUTEX_WAIT_REQUEUE_PI = 11
    41  	FUTEX_CMP_REQUEUE_PI  = 12
    42  
    43  	FUTEX_PRIVATE_FLAG   = 128
    44  	FUTEX_CLOCK_REALTIME = 256
    45  )
    46  
    47  // These are flags are from <linux/futex.h> and are used in FUTEX_WAKE_OP
    48  // to define the operations.
    49  const (
    50  	FUTEX_OP_SET         = 0
    51  	FUTEX_OP_ADD         = 1
    52  	FUTEX_OP_OR          = 2
    53  	FUTEX_OP_ANDN        = 3
    54  	FUTEX_OP_XOR         = 4
    55  	FUTEX_OP_OPARG_SHIFT = 8
    56  	FUTEX_OP_CMP_EQ      = 0
    57  	FUTEX_OP_CMP_NE      = 1
    58  	FUTEX_OP_CMP_LT      = 2
    59  	FUTEX_OP_CMP_LE      = 3
    60  	FUTEX_OP_CMP_GT      = 4
    61  	FUTEX_OP_CMP_GE      = 5
    62  )
    63  
    64  // FUTEX_TID_MASK is the TID portion of a PI futex word.
    65  const FUTEX_TID_MASK = 0x3fffffff
    66  
    67  // ptrace commands from include/uapi/linux/ptrace.h.
    68  const (
    69  	PTRACE_TRACEME              = 0
    70  	PTRACE_PEEKTEXT             = 1
    71  	PTRACE_PEEKDATA             = 2
    72  	PTRACE_PEEKUSR              = 3
    73  	PTRACE_POKETEXT             = 4
    74  	PTRACE_POKEDATA             = 5
    75  	PTRACE_POKEUSR              = 6
    76  	PTRACE_CONT                 = 7
    77  	PTRACE_KILL                 = 8
    78  	PTRACE_SINGLESTEP           = 9
    79  	PTRACE_ATTACH               = 16
    80  	PTRACE_DETACH               = 17
    81  	PTRACE_SYSCALL              = 24
    82  	PTRACE_SETOPTIONS           = 0x4200
    83  	PTRACE_GETEVENTMSG          = 0x4201
    84  	PTRACE_GETSIGINFO           = 0x4202
    85  	PTRACE_SETSIGINFO           = 0x4203
    86  	PTRACE_GETREGSET            = 0x4204
    87  	PTRACE_SETREGSET            = 0x4205
    88  	PTRACE_SEIZE                = 0x4206
    89  	PTRACE_INTERRUPT            = 0x4207
    90  	PTRACE_LISTEN               = 0x4208
    91  	PTRACE_PEEKSIGINFO          = 0x4209
    92  	PTRACE_GETSIGMASK           = 0x420a
    93  	PTRACE_SETSIGMASK           = 0x420b
    94  	PTRACE_SECCOMP_GET_FILTER   = 0x420c
    95  	PTRACE_SECCOMP_GET_METADATA = 0x420d
    96  )
    97  
    98  // ptrace commands from arch/x86/include/uapi/asm/ptrace-abi.h.
    99  const (
   100  	PTRACE_GETREGS           = 12
   101  	PTRACE_SETREGS           = 13
   102  	PTRACE_GETFPREGS         = 14
   103  	PTRACE_SETFPREGS         = 15
   104  	PTRACE_GETFPXREGS        = 18
   105  	PTRACE_SETFPXREGS        = 19
   106  	PTRACE_OLDSETOPTIONS     = 21
   107  	PTRACE_GET_THREAD_AREA   = 25
   108  	PTRACE_SET_THREAD_AREA   = 26
   109  	PTRACE_ARCH_PRCTL        = 30
   110  	PTRACE_SYSEMU            = 31
   111  	PTRACE_SYSEMU_SINGLESTEP = 32
   112  	PTRACE_SINGLEBLOCK       = 33
   113  )
   114  
   115  // ptrace event codes from include/uapi/linux/ptrace.h.
   116  const (
   117  	PTRACE_EVENT_FORK       = 1
   118  	PTRACE_EVENT_VFORK      = 2
   119  	PTRACE_EVENT_CLONE      = 3
   120  	PTRACE_EVENT_EXEC       = 4
   121  	PTRACE_EVENT_VFORK_DONE = 5
   122  	PTRACE_EVENT_EXIT       = 6
   123  	PTRACE_EVENT_SECCOMP    = 7
   124  	PTRACE_EVENT_STOP       = 128
   125  )
   126  
   127  // PTRACE_SETOPTIONS options from include/uapi/linux/ptrace.h.
   128  const (
   129  	PTRACE_O_TRACESYSGOOD    = 1
   130  	PTRACE_O_TRACEFORK       = 1 << PTRACE_EVENT_FORK
   131  	PTRACE_O_TRACEVFORK      = 1 << PTRACE_EVENT_VFORK
   132  	PTRACE_O_TRACECLONE      = 1 << PTRACE_EVENT_CLONE
   133  	PTRACE_O_TRACEEXEC       = 1 << PTRACE_EVENT_EXEC
   134  	PTRACE_O_TRACEVFORKDONE  = 1 << PTRACE_EVENT_VFORK_DONE
   135  	PTRACE_O_TRACEEXIT       = 1 << PTRACE_EVENT_EXIT
   136  	PTRACE_O_TRACESECCOMP    = 1 << PTRACE_EVENT_SECCOMP
   137  	PTRACE_O_EXITKILL        = 1 << 20
   138  	PTRACE_O_SUSPEND_SECCOMP = 1 << 21
   139  )
   140  
   141  // from gvisor time.go
   142  // Flags for clock_nanosleep(2).
   143  const (
   144  	TIMER_ABSTIME = 1
   145  )
   146  
   147  // Flags for timerfd syscalls (timerfd_create(2), timerfd_settime(2)).
   148  const (
   149  	// TFD_CLOEXEC is a timerfd_create flag.
   150  	TFD_CLOEXEC = unix.O_CLOEXEC
   151  
   152  	// TFD_NONBLOCK is a timerfd_create flag.
   153  	TFD_NONBLOCK = unix.O_NONBLOCK
   154  
   155  	// TFD_TIMER_ABSTIME is a timerfd_settime flag.
   156  	TFD_TIMER_ABSTIME = 1
   157  )
   158  
   159  // The safe number of seconds you can represent by int64.
   160  const maxSecInDuration = math.MaxInt64 / int64(time.Second)
   161  
   162  // TimeT represents time_t in <time.h>. It represents time in seconds.
   163  type TimeT int64
   164  
   165  // SizeOfTimeval is the size of a Timeval struct in bytes.
   166  const SizeOfTimeval = 16
   167  
   168  // ClockT represents type clock_t.
   169  type ClockT int64
   170  
   171  // Tms represents struct tms, used by times(2).
   172  type Tms struct {
   173  	UTime  ClockT
   174  	STime  ClockT
   175  	CUTime ClockT
   176  	CSTime ClockT
   177  }
   178  
   179  // TimerID represents type timer_t, which identifies a POSIX per-process
   180  // interval timer.
   181  type TimerID int32
   182  
   183  // ptrace
   184  
   185  // PtraceRequestSet are the possible ptrace(2) requests.
   186  var PtraceRequestSet = FlagSet{
   187  	&Value{
   188  		Value: PTRACE_TRACEME,
   189  		Name:  "PTRACE_TRACEME",
   190  	},
   191  	&Value{
   192  		Value: PTRACE_PEEKTEXT,
   193  		Name:  "PTRACE_PEEKTEXT",
   194  	},
   195  	&Value{
   196  		Value: PTRACE_PEEKDATA,
   197  		Name:  "PTRACE_PEEKDATA",
   198  	},
   199  	&Value{
   200  		Value: PTRACE_PEEKUSR,
   201  		Name:  "PTRACE_PEEKUSR",
   202  	},
   203  	&Value{
   204  		Value: PTRACE_POKETEXT,
   205  		Name:  "PTRACE_POKETEXT",
   206  	},
   207  	&Value{
   208  		Value: PTRACE_POKEDATA,
   209  		Name:  "PTRACE_POKEDATA",
   210  	},
   211  	&Value{
   212  		Value: PTRACE_POKEUSR,
   213  		Name:  "PTRACE_POKEUSR",
   214  	},
   215  	&Value{
   216  		Value: PTRACE_CONT,
   217  		Name:  "PTRACE_CONT",
   218  	},
   219  	&Value{
   220  		Value: PTRACE_KILL,
   221  		Name:  "PTRACE_KILL",
   222  	},
   223  	&Value{
   224  		Value: PTRACE_SINGLESTEP,
   225  		Name:  "PTRACE_SINGLESTEP",
   226  	},
   227  	&Value{
   228  		Value: PTRACE_ATTACH,
   229  		Name:  "PTRACE_ATTACH",
   230  	},
   231  	&Value{
   232  		Value: PTRACE_DETACH,
   233  		Name:  "PTRACE_DETACH",
   234  	},
   235  	&Value{
   236  		Value: PTRACE_SYSCALL,
   237  		Name:  "PTRACE_SYSCALL",
   238  	},
   239  	&Value{
   240  		Value: PTRACE_SETOPTIONS,
   241  		Name:  "PTRACE_SETOPTIONS",
   242  	},
   243  	&Value{
   244  		Value: PTRACE_GETEVENTMSG,
   245  		Name:  "PTRACE_GETEVENTMSG",
   246  	},
   247  	&Value{
   248  		Value: PTRACE_GETSIGINFO,
   249  		Name:  "PTRACE_GETSIGINFO",
   250  	},
   251  	&Value{
   252  		Value: PTRACE_SETSIGINFO,
   253  		Name:  "PTRACE_SETSIGINFO",
   254  	},
   255  	&Value{
   256  		Value: PTRACE_GETREGSET,
   257  		Name:  "PTRACE_GETREGSET",
   258  	},
   259  	&Value{
   260  		Value: PTRACE_SETREGSET,
   261  		Name:  "PTRACE_SETREGSET",
   262  	},
   263  	&Value{
   264  		Value: PTRACE_SEIZE,
   265  		Name:  "PTRACE_SEIZE",
   266  	},
   267  	&Value{
   268  		Value: PTRACE_INTERRUPT,
   269  		Name:  "PTRACE_INTERRUPT",
   270  	},
   271  	&Value{
   272  		Value: PTRACE_LISTEN,
   273  		Name:  "PTRACE_LISTEN",
   274  	},
   275  	&Value{
   276  		Value: PTRACE_PEEKSIGINFO,
   277  		Name:  "PTRACE_PEEKSIGINFO",
   278  	},
   279  	&Value{
   280  		Value: PTRACE_GETSIGMASK,
   281  		Name:  "PTRACE_GETSIGMASK",
   282  	},
   283  	&Value{
   284  		Value: PTRACE_SETSIGMASK,
   285  		Name:  "PTRACE_SETSIGMASK",
   286  	},
   287  	&Value{
   288  		Value: PTRACE_GETREGS,
   289  		Name:  "PTRACE_GETREGS",
   290  	},
   291  	&Value{
   292  		Value: PTRACE_SETREGS,
   293  		Name:  "PTRACE_SETREGS",
   294  	},
   295  	&Value{
   296  		Value: PTRACE_GETFPREGS,
   297  		Name:  "PTRACE_GETFPREGS",
   298  	},
   299  	&Value{
   300  		Value: PTRACE_SETFPREGS,
   301  		Name:  "PTRACE_SETFPREGS",
   302  	},
   303  	&Value{
   304  		Value: PTRACE_GETFPXREGS,
   305  		Name:  "PTRACE_GETFPXREGS",
   306  	},
   307  	&Value{
   308  		Value: PTRACE_SETFPXREGS,
   309  		Name:  "PTRACE_SETFPXREGS",
   310  	},
   311  	&Value{
   312  		Value: PTRACE_OLDSETOPTIONS,
   313  		Name:  "PTRACE_OLDSETOPTIONS",
   314  	},
   315  	&Value{
   316  		Value: PTRACE_GET_THREAD_AREA,
   317  		Name:  "PTRACE_GET_THREAD_AREA",
   318  	},
   319  	&Value{
   320  		Value: PTRACE_SET_THREAD_AREA,
   321  		Name:  "PTRACE_SET_THREAD_AREA",
   322  	},
   323  	&Value{
   324  		Value: PTRACE_ARCH_PRCTL,
   325  		Name:  "PTRACE_ARCH_PRCTL",
   326  	},
   327  	&Value{
   328  		Value: PTRACE_SYSEMU,
   329  		Name:  "PTRACE_SYSEMU",
   330  	},
   331  	&Value{
   332  		Value: PTRACE_SYSEMU_SINGLESTEP,
   333  		Name:  "PTRACE_SYSEMU_SINGLESTEP",
   334  	},
   335  	&Value{
   336  		Value: PTRACE_SINGLEBLOCK,
   337  		Name:  "PTRACE_SINGLEBLOCK",
   338  	},
   339  }
   340  
   341  // clone
   342  
   343  // CloneFlagSet is the set of clone(2) flags.
   344  var CloneFlagSet = FlagSet{
   345  	&BitFlag{
   346  		Value: syscall.CLONE_VM,
   347  		Name:  "CLONE_VM",
   348  	},
   349  	&BitFlag{
   350  		Value: syscall.CLONE_FS,
   351  		Name:  "CLONE_FS",
   352  	},
   353  	&BitFlag{
   354  		Value: syscall.CLONE_FILES,
   355  		Name:  "CLONE_FILES",
   356  	},
   357  	&BitFlag{
   358  		Value: syscall.CLONE_SIGHAND,
   359  		Name:  "CLONE_SIGHAND",
   360  	},
   361  	&BitFlag{
   362  		Value: syscall.CLONE_PTRACE,
   363  		Name:  "CLONE_PTRACE",
   364  	},
   365  	&BitFlag{
   366  		Value: syscall.CLONE_VFORK,
   367  		Name:  "CLONE_VFORK",
   368  	},
   369  	&BitFlag{
   370  		Value: syscall.CLONE_PARENT,
   371  		Name:  "CLONE_PARENT",
   372  	},
   373  	&BitFlag{
   374  		Value: syscall.CLONE_THREAD,
   375  		Name:  "CLONE_THREAD",
   376  	},
   377  	&BitFlag{
   378  		Value: syscall.CLONE_NEWNS,
   379  		Name:  "CLONE_NEWNS",
   380  	},
   381  	&BitFlag{
   382  		Value: syscall.CLONE_SYSVSEM,
   383  		Name:  "CLONE_SYSVSEM",
   384  	},
   385  	&BitFlag{
   386  		Value: syscall.CLONE_SETTLS,
   387  		Name:  "CLONE_SETTLS",
   388  	},
   389  	&BitFlag{
   390  		Value: syscall.CLONE_PARENT_SETTID,
   391  		Name:  "CLONE_PARENT_SETTID",
   392  	},
   393  	&BitFlag{
   394  		Value: syscall.CLONE_CHILD_CLEARTID,
   395  		Name:  "CLONE_CHILD_CLEARTID",
   396  	},
   397  	&BitFlag{
   398  		Value: syscall.CLONE_DETACHED,
   399  		Name:  "CLONE_DETACHED",
   400  	},
   401  	&BitFlag{
   402  		Value: syscall.CLONE_UNTRACED,
   403  		Name:  "CLONE_UNTRACED",
   404  	},
   405  	&BitFlag{
   406  		Value: syscall.CLONE_CHILD_SETTID,
   407  		Name:  "CLONE_CHILD_SETTID",
   408  	},
   409  	&BitFlag{
   410  		Value: syscall.CLONE_NEWUTS,
   411  		Name:  "CLONE_NEWUTS",
   412  	},
   413  	&BitFlag{
   414  		Value: syscall.CLONE_NEWIPC,
   415  		Name:  "CLONE_NEWIPC",
   416  	},
   417  	&BitFlag{
   418  		Value: syscall.CLONE_NEWUSER,
   419  		Name:  "CLONE_NEWUSER",
   420  	},
   421  	&BitFlag{
   422  		Value: syscall.CLONE_NEWPID,
   423  		Name:  "CLONE_NEWPID",
   424  	},
   425  	&BitFlag{
   426  		Value: syscall.CLONE_NEWNET,
   427  		Name:  "CLONE_NEWNET",
   428  	},
   429  	&BitFlag{
   430  		Value: syscall.CLONE_IO,
   431  		Name:  "CLONE_IO",
   432  	},
   433  }
   434  
   435  // Socket defines. Some of these might move to abi_unix.go
   436  // Address families, from linux/socket.h.
   437  const (
   438  	AF_UNSPEC     = 0
   439  	AF_UNIX       = 1
   440  	AF_INET       = 2
   441  	AF_AX25       = 3
   442  	AF_IPX        = 4
   443  	AF_APPLETALK  = 5
   444  	AF_NETROM     = 6
   445  	AF_BRIDGE     = 7
   446  	AF_ATMPVC     = 8
   447  	AF_X25        = 9
   448  	AF_INET6      = 10
   449  	AF_ROSE       = 11
   450  	AF_DECnet     = 12
   451  	AF_NETBEUI    = 13
   452  	AF_SECURITY   = 14
   453  	AF_KEY        = 15
   454  	AF_NETLINK    = 16
   455  	AF_PACKET     = 17
   456  	AF_ASH        = 18
   457  	AF_ECONET     = 19
   458  	AF_ATMSVC     = 20
   459  	AF_RDS        = 21
   460  	AF_SNA        = 22
   461  	AF_IRDA       = 23
   462  	AF_PPPOX      = 24
   463  	AF_WANPIPE    = 25
   464  	AF_LLC        = 26
   465  	AF_IB         = 27
   466  	AF_MPLS       = 28
   467  	AF_CAN        = 29
   468  	AF_TIPC       = 30
   469  	AF_BLUETOOTH  = 31
   470  	AF_IUCV       = 32
   471  	AF_RXRPC      = 33
   472  	AF_ISDN       = 34
   473  	AF_PHONET     = 35
   474  	AF_IEEE802154 = 36
   475  	AF_CAIF       = 37
   476  	AF_ALG        = 38
   477  	AF_NFC        = 39
   478  	AF_VSOCK      = 40
   479  )
   480  
   481  // sendmsg(2)/recvmsg(2) flags, from linux/socket.h.
   482  const (
   483  	MSG_OOB              = 0x1
   484  	MSG_PEEK             = 0x2
   485  	MSG_DONTROUTE        = 0x4
   486  	MSG_TRYHARD          = 0x4
   487  	MSG_CTRUNC           = 0x8
   488  	MSG_PROBE            = 0x10
   489  	MSG_TRUNC            = 0x20
   490  	MSG_DONTWAIT         = 0x40
   491  	MSG_EOR              = 0x80
   492  	MSG_WAITALL          = 0x100
   493  	MSG_FIN              = 0x200
   494  	MSG_EOF              = MSG_FIN
   495  	MSG_SYN              = 0x400
   496  	MSG_CONFIRM          = 0x800
   497  	MSG_RST              = 0x1000
   498  	MSG_ERRQUEUE         = 0x2000
   499  	MSG_NOSIGNAL         = 0x4000
   500  	MSG_MORE             = 0x8000
   501  	MSG_WAITFORONE       = 0x10000
   502  	MSG_SENDPAGE_NOTLAST = 0x20000
   503  	MSG_REINJECT         = 0x8000000
   504  	MSG_ZEROCOPY         = 0x4000000
   505  	MSG_FASTOPEN         = 0x20000000
   506  	MSG_CMSG_CLOEXEC     = 0x40000000
   507  )
   508  
   509  // SOL_SOCKET is from socket.h
   510  const SOL_SOCKET = 1
   511  
   512  // Socket types, from linux/net.h.
   513  const (
   514  	SOCK_STREAM    = 1
   515  	SOCK_DGRAM     = 2
   516  	SOCK_RAW       = 3
   517  	SOCK_RDM       = 4
   518  	SOCK_SEQPACKET = 5
   519  	SOCK_DCCP      = 6
   520  	SOCK_PACKET    = 10
   521  )
   522  
   523  // SOCK_TYPE_MASK covers all of the above socket types. The remaining bits are
   524  // flags. From linux/net.h.
   525  const SOCK_TYPE_MASK = 0xf
   526  
   527  // socket(2)/socketpair(2)/accept4(2) flags, from linux/net.h.
   528  const (
   529  	SOCK_CLOEXEC  = unix.O_CLOEXEC
   530  	SOCK_NONBLOCK = unix.O_NONBLOCK
   531  )
   532  
   533  // shutdown(2) how commands, from <linux/net.h>.
   534  const (
   535  	SHUT_RD   = 0
   536  	SHUT_WR   = 1
   537  	SHUT_RDWR = 2
   538  )
   539  
   540  // Socket options from socket.h.
   541  const (
   542  	SO_ERROR       = 4
   543  	SO_KEEPALIVE   = 9
   544  	SO_LINGER      = 13
   545  	SO_MARK        = 36
   546  	SO_PASSCRED    = 16
   547  	SO_PEERCRED    = 17
   548  	SO_PEERNAME    = 28
   549  	SO_PROTOCOL    = 38
   550  	SO_RCVBUF      = 8
   551  	SO_RCVTIMEO    = 20
   552  	SO_REUSEADDR   = 2
   553  	SO_SNDBUF      = 7
   554  	SO_SNDTIMEO    = 21
   555  	SO_TIMESTAMP   = 29
   556  	SO_TIMESTAMPNS = 35
   557  	SO_TYPE        = 3
   558  )
   559  
   560  // SockAddrMax is the maximum size of a struct sockaddr, from
   561  // uapi/linux/socket.h.
   562  const SockAddrMax = 128
   563  
   564  // SockAddrInt is struct sockaddr_in, from uapi/linux/in.h.
   565  type SockAddrInet struct {
   566  	Family uint16
   567  	Port   uint16
   568  	Addr   [4]byte
   569  	Zero   [8]uint8 // pad to sizeof(struct sockaddr).
   570  }
   571  
   572  // SockAddrInt6 is struct sockaddr_in6, from uapi/linux/in6.h.
   573  type SockAddrInet6 struct {
   574  	Family   uint16
   575  	Port     uint16
   576  	Flowinfo uint32
   577  	Addr     [16]byte
   578  	Scope_id uint32
   579  }
   580  
   581  // UnixPathMax is the maximum length of the path in an AF_UNIX socket.
   582  //
   583  // From uapi/linux/un.h.
   584  const UnixPathMax = 108
   585  
   586  // SockAddrUnix is struct sockaddr_un, from uapi/linux/un.h.
   587  type SockAddrUnix struct {
   588  	Family uint16
   589  	Path   [UnixPathMax]int8
   590  }
   591  
   592  // TCPInfo is a collection of TCP statistics.
   593  //
   594  // From uapi/linux/tcp.h.
   595  type TCPInfo struct {
   596  	State       uint8
   597  	CaState     uint8
   598  	Retransmits uint8
   599  	Probes      uint8
   600  	Backoff     uint8
   601  	Options     uint8
   602  	// WindowScale is the combination of snd_wscale (first 4 bits) and rcv_wscale (second 4 bits)
   603  	WindowScale uint8
   604  	// DeliveryRateAppLimited is a boolean and only the first bit is meaningful.
   605  	DeliveryRateAppLimited uint8
   606  
   607  	RTO    uint32
   608  	ATO    uint32
   609  	SndMss uint32
   610  	RcvMss uint32
   611  
   612  	Unacked uint32
   613  	Sacked  uint32
   614  	Lost    uint32
   615  	Retrans uint32
   616  	Fackets uint32
   617  
   618  	// Times.
   619  	LastDataSent uint32
   620  	LastAckSent  uint32
   621  	LastDataRecv uint32
   622  	LastAckRecv  uint32
   623  
   624  	// Metrics.
   625  	PMTU        uint32
   626  	RcvSsthresh uint32
   627  	RTT         uint32
   628  	RTTVar      uint32
   629  	SndSsthresh uint32
   630  	SndCwnd     uint32
   631  	Advmss      uint32
   632  	Reordering  uint32
   633  
   634  	RcvRTT   uint32
   635  	RcvSpace uint32
   636  
   637  	TotalRetrans uint32
   638  
   639  	PacingRate    uint64
   640  	MaxPacingRate uint64
   641  	// BytesAcked is RFC4898 tcpEStatsAppHCThruOctetsAcked.
   642  	BytesAcked uint64
   643  	// BytesReceived is RFC4898 tcpEStatsAppHCThruOctetsReceived.
   644  	BytesReceived uint64
   645  	// SegsOut is RFC4898 tcpEStatsPerfSegsOut.
   646  	SegsOut uint32
   647  	// SegsIn is RFC4898 tcpEStatsPerfSegsIn.
   648  	SegsIn uint32
   649  
   650  	NotSentBytes uint32
   651  	MinRTT       uint32
   652  	// DataSegsIn is RFC4898 tcpEStatsDataSegsIn.
   653  	DataSegsIn uint32
   654  	// DataSegsOut is RFC4898 tcpEStatsDataSegsOut.
   655  	DataSegsOut uint32
   656  
   657  	DeliveryRate uint64
   658  
   659  	// BusyTime is the time in microseconds busy sending data.
   660  	BusyTime uint64
   661  	// RwndLimited is the time in microseconds limited by receive window.
   662  	RwndLimited uint64
   663  	// SndBufLimited is the time in microseconds limited by send buffer.
   664  	SndBufLimited uint64
   665  }
   666  
   667  // SizeOfTCPInfo is the binary size of a TCPInfo struct (104 bytes).
   668  var SizeOfTCPInfo = binary.Size(TCPInfo{})
   669  
   670  // Control message types, from linux/socket.h.
   671  const (
   672  	SCM_CREDENTIALS = 0x2
   673  	SCM_RIGHTS      = 0x1
   674  )
   675  
   676  // A ControlMessageHeader is the header for a socket control message.
   677  //
   678  // ControlMessageHeader represents struct cmsghdr from linux/socket.h.
   679  type ControlMessageHeader struct {
   680  	Length uint64
   681  	Level  int32
   682  	Type   int32
   683  }
   684  
   685  // SizeOfControlMessageHeader is the binary size of a ControlMessageHeader
   686  // struct.
   687  var SizeOfControlMessageHeader = int(binary.Size(ControlMessageHeader{}))
   688  
   689  // A ControlMessageCredentials is an SCM_CREDENTIALS socket control message.
   690  //
   691  // ControlMessageCredentials represents struct ucred from linux/socket.h.
   692  type ControlMessageCredentials struct {
   693  	PID int32
   694  	UID uint32
   695  	GID uint32
   696  }
   697  
   698  // SizeOfControlMessageCredentials is the binary size of a
   699  // ControlMessageCredentials struct.
   700  var SizeOfControlMessageCredentials = int(binary.Size(ControlMessageCredentials{}))
   701  
   702  // A ControlMessageRights is an SCM_RIGHTS socket control message.
   703  type ControlMessageRights []int32
   704  
   705  // SizeOfControlMessageRight is the size of a single element in
   706  // ControlMessageRights.
   707  const SizeOfControlMessageRight = 4
   708  
   709  // SCM_MAX_FD is the maximum number of FDs accepted in a single sendmsg call.
   710  // From net/scm.h.
   711  const SCM_MAX_FD = 253
   712  
   713  // itimer
   714  
   715  // itimer types for getitimer(2) and setitimer(2), from
   716  // include/uapi/linux/time.h.
   717  const (
   718  	ITIMER_REAL    = 0
   719  	ITIMER_VIRTUAL = 1
   720  	ITIMER_PROF    = 2
   721  )
   722  
   723  // ItimerTypes are the possible itimer types.
   724  var ItimerTypes = FlagSet{
   725  	&Value{
   726  		Value: ITIMER_REAL,
   727  		Name:  "ITIMER_REAL",
   728  	},
   729  	&Value{
   730  		Value: ITIMER_VIRTUAL,
   731  		Name:  "ITIMER_VIRTUAL",
   732  	},
   733  	&Value{
   734  		Value: ITIMER_PROF,
   735  		Name:  "ITIMER_PROF",
   736  	},
   737  }
   738  
   739  // from gvisor futex.go
   740  // FutexCmd are the possible futex(2) commands.
   741  var FutexCmd = FlagSet{
   742  	&Value{
   743  		Value: FUTEX_WAIT,
   744  		Name:  "FUTEX_WAIT",
   745  	},
   746  	&Value{
   747  		Value: FUTEX_WAKE,
   748  		Name:  "FUTEX_WAKE",
   749  	},
   750  	&Value{
   751  		Value: FUTEX_FD,
   752  		Name:  "FUTEX_FD",
   753  	},
   754  	&Value{
   755  		Value: FUTEX_REQUEUE,
   756  		Name:  "FUTEX_REQUEUE",
   757  	},
   758  	&Value{
   759  		Value: FUTEX_CMP_REQUEUE,
   760  		Name:  "FUTEX_CMP_REQUEUE",
   761  	},
   762  	&Value{
   763  		Value: FUTEX_WAKE_OP,
   764  		Name:  "FUTEX_WAKE_OP",
   765  	},
   766  	&Value{
   767  		Value: FUTEX_LOCK_PI,
   768  		Name:  "FUTEX_LOCK_PI",
   769  	},
   770  	&Value{
   771  		Value: FUTEX_UNLOCK_PI,
   772  		Name:  "FUTEX_UNLOCK_PI",
   773  	},
   774  	&Value{
   775  		Value: FUTEX_TRYLOCK_PI,
   776  		Name:  "FUTEX_TRYLOCK_PI",
   777  	},
   778  	&Value{
   779  		Value: FUTEX_WAIT_BITSET,
   780  		Name:  "FUTEX_WAIT_BITSET",
   781  	},
   782  	&Value{
   783  		Value: FUTEX_WAKE_BITSET,
   784  		Name:  "FUTEX_WAKE_BITSET",
   785  	},
   786  	&Value{
   787  		Value: FUTEX_WAIT_REQUEUE_PI,
   788  		Name:  "FUTEX_WAIT_REQUEUE_PI",
   789  	},
   790  	&Value{
   791  		Value: FUTEX_CMP_REQUEUE_PI,
   792  		Name:  "FUTEX_CMP_REQUEUE_PI",
   793  	},
   794  }
   795  
   796  func Futex(op uint64) string {
   797  	cmd := op &^ (FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
   798  	clockRealtime := (op & FUTEX_CLOCK_REALTIME) == FUTEX_CLOCK_REALTIME
   799  	private := (op & FUTEX_PRIVATE_FLAG) == FUTEX_PRIVATE_FLAG
   800  
   801  	s := FutexCmd.Parse(cmd)
   802  	if clockRealtime {
   803  		s += "|FUTEX_CLOCK_REALTIME"
   804  	}
   805  	if private {
   806  		s += "|FUTEX_PRIVATE_FLAG"
   807  	}
   808  	return s
   809  }