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