github.com/ii64/gouring@v0.4.1/hdr.go (about)

     1  /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
     2  /*
     3   * Header file for the io_uring interface.
     4   *
     5   * Copyright (C) 2019 Jens Axboe
     6   * Copyright (C) 2019 Christoph Hellwig
     7   */
     8  package gouring
     9  
    10  import "unsafe"
    11  
    12  /*
    13   * IO submission data structure (Submission Queue Entry)
    14   */
    15  type IoUringSqe_Union1 uint64
    16  
    17  func (u *IoUringSqe_Union1) SetOffset(v uint64) { *u = IoUringSqe_Union1(v) }
    18  func (u *IoUringSqe_Union1) SetAddr2(v uint64)  { *u = IoUringSqe_Union1(v) }
    19  
    20  type IoUringSqe_Union2 uint64
    21  
    22  func (u *IoUringSqe_Union2) SetAddr_Value(v uint64)     { *u = IoUringSqe_Union2(v) }
    23  func (u *IoUringSqe_Union2) SetAddr(v unsafe.Pointer)   { *u = IoUringSqe_Union2((uintptr)(v)) }
    24  func (u *IoUringSqe_Union2) SetSpliceOffsetIn(v uint64) { *u = IoUringSqe_Union2(v) }
    25  
    26  type IoUringSqe_Union3 uint32
    27  
    28  func (u *IoUringSqe_Union3) SetRwFlags(v uint32)        { *u = IoUringSqe_Union3(v) }
    29  func (u *IoUringSqe_Union3) SetPollEvents(v uint16)     { *u = IoUringSqe_Union3(v) }
    30  func (u *IoUringSqe_Union3) SetPoll32Events(v uint32)   { *u = IoUringSqe_Union3(v) }
    31  func (u *IoUringSqe_Union3) SetSyncRangeFlags(v uint32) { *u = IoUringSqe_Union3(v) }
    32  func (u *IoUringSqe_Union3) SetMsgFlags(v uint32)       { *u = IoUringSqe_Union3(v) }
    33  func (u *IoUringSqe_Union3) SetTimeoutFlags(v uint32)   { *u = IoUringSqe_Union3(v) }
    34  func (u *IoUringSqe_Union3) SetAcceptFlags(v uint32)    { *u = IoUringSqe_Union3(v) }
    35  func (u *IoUringSqe_Union3) SetCancelFlags(v uint32)    { *u = IoUringSqe_Union3(v) }
    36  func (u *IoUringSqe_Union3) SetOpenFlags(v uint32)      { *u = IoUringSqe_Union3(v) }
    37  func (u *IoUringSqe_Union3) SetStatxFlags(v uint32)     { *u = IoUringSqe_Union3(v) }
    38  func (u *IoUringSqe_Union3) SetFadviseAdvice(v uint32)  { *u = IoUringSqe_Union3(v) }
    39  func (u *IoUringSqe_Union3) SetSpliceFlags(v uint32)    { *u = IoUringSqe_Union3(v) }
    40  func (u *IoUringSqe_Union3) SetRenameFlags(v uint32)    { *u = IoUringSqe_Union3(v) }
    41  func (u *IoUringSqe_Union3) SetUnlinkFlags(v uint32)    { *u = IoUringSqe_Union3(v) }
    42  func (u *IoUringSqe_Union3) SetHardlinkFlags(v uint32)  { *u = IoUringSqe_Union3(v) }
    43  func (u *IoUringSqe_Union3) SetXattrFlags(v uint32)     { *u = IoUringSqe_Union3(v) }
    44  func (u *IoUringSqe_Union3) SetOpFlags(v uint32)        { *u = IoUringSqe_Union3(v) } //generic
    45  func (u IoUringSqe_Union3) GetOpFlags() uint32          { return uint32(u) }          //generic
    46  
    47  type IoUringSqe_Union4 uint16
    48  
    49  func (u *IoUringSqe_Union4) SetBufIndex(v uint16) { *u = IoUringSqe_Union4(v) }
    50  func (u *IoUringSqe_Union4) SetBufGroup(v uint16) { *u = IoUringSqe_Union4(v) }
    51  
    52  type IoUringSqe_Union5 uint32
    53  
    54  func (u *IoUringSqe_Union5) SetSpliceFdIn(v int32) { *u = IoUringSqe_Union5(v) }
    55  func (u *IoUringSqe_Union5) SetFileIndex(v uint32) { *u = IoUringSqe_Union5(v) }
    56  
    57  type IoUringSqe struct {
    58  	Opcode IoUringOp /* type of operation for this sqe */
    59  	Flags  uint8     /* IOSQE_ flags */
    60  	IoPrio uint16    /* ioprio for the request */
    61  	Fd     int32     /* file descriptor to do IO on */
    62  
    63  	//  union {
    64  	// 	 __u64	off;	/* offset into file */
    65  	// 	 __u64	addr2;
    66  	//  };
    67  	IoUringSqe_Union1
    68  
    69  	//  union {
    70  	// 	 __u64	addr;	/* pointer to buffer or iovecs */
    71  	// 	 __u64	splice_off_in;
    72  	//  };
    73  	IoUringSqe_Union2
    74  
    75  	Len uint32 /* buffer size or number of iovecs */
    76  
    77  	//  union {
    78  	// 	 __kernel_rwf_t	rw_flags;
    79  	// 	 __u32		fsync_flags;
    80  	// 	 __u16		poll_events;	/* compatibility */
    81  	// 	 __u32		poll32_events;	/* word-reversed for BE */
    82  	// 	 __u32		sync_range_flags;
    83  	// 	 __u32		msg_flags;
    84  	// 	 __u32		timeout_flags;
    85  	// 	 __u32		accept_flags;
    86  	// 	 __u32		cancel_flags;
    87  	// 	 __u32		open_flags;
    88  	// 	 __u32		statx_flags;
    89  	// 	 __u32		fadvise_advice;
    90  	// 	 __u32		splice_flags;
    91  	// 	 __u32		rename_flags;
    92  	// 	 __u32		unlink_flags;
    93  	// 	 __u32		hardlink_flags;
    94  	// 	 __u32		xattr_flags;
    95  	//  };
    96  	IoUringSqe_Union3
    97  
    98  	UserData UserData /* data to be passed back at completion time */
    99  
   100  	/* pack this to avoid bogus arm OABI complaints */
   101  	//  union {
   102  	// 	 /* index into fixed buffers, if used */
   103  	// 	 __u16	buf_index;
   104  	// 	 /* for grouped buffer selection */
   105  	// 	 __u16	buf_group;
   106  	//  } __attribute__((packed));
   107  	IoUringSqe_Union4
   108  
   109  	/* personality to use, if used */
   110  	Personality uint16
   111  
   112  	//  union {
   113  	// 	 __s32	splice_fd_in;
   114  	// 	 __u32	file_index;
   115  	//  };
   116  	IoUringSqe_Union5
   117  
   118  	Addr3  uint64
   119  	__pad2 [1]uint64
   120  }
   121  
   122  /*
   123   * If sqe->file_index is set to this for opcodes that instantiate a new
   124   * direct descriptor (like openat/openat2/accept), then io_uring will allocate
   125   * an available direct descriptor instead of having the application pass one
   126   * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE
   127   * if the space is full.
   128   */
   129  const IORING_FILE_INDEX_ALLOC = ^uint32(0)
   130  
   131  const (
   132  	IOSQE_FIXED_FILE_BIT = iota
   133  	IOSQE_IO_DRAIN_BIT
   134  	IOSQE_IO_LINK_BIT
   135  	IOSQE_IO_HARDLINK_BIT
   136  	IOSQE_ASYNC_BIT
   137  	IOSQE_BUFFER_SELECT_BIT
   138  	IOSQE_CQE_SKIP_SUCCESS_BIT
   139  )
   140  
   141  /*
   142   * sqe->flags
   143   */
   144  const (
   145  	/* use fixed fileset */
   146  	IOSQE_FIXED_FILE = (1 << IOSQE_FIXED_FILE_BIT)
   147  	/* issue after inflight IO */
   148  	IOSQE_IO_DRAIN = (1 << IOSQE_IO_DRAIN_BIT)
   149  	/* links next sqe */
   150  	IOSQE_IO_LINK = (1 << IOSQE_IO_LINK_BIT)
   151  	/* like LINK, but stronger */
   152  	IOSQE_IO_HARDLINK = (1 << IOSQE_IO_HARDLINK_BIT)
   153  	/* always go async */
   154  	IOSQE_ASYNC = (1 << IOSQE_ASYNC_BIT)
   155  	/* select buffer from sqe->buf_group */
   156  	IOSQE_BUFFER_SELECT = (1 << IOSQE_BUFFER_SELECT_BIT)
   157  	/* don't post CQE if request succeeded */
   158  	IOSQE_CQE_SKIP_SUCCESS = (1 << IOSQE_CQE_SKIP_SUCCESS_BIT)
   159  )
   160  
   161  /*
   162   * io_uring_setup() flags
   163   */
   164  const (
   165  	IORING_SETUP_IOPOLL     = (1 << 0) /* io_context is polled */
   166  	IORING_SETUP_SQPOLL     = (1 << 1) /* SQ poll thread */
   167  	IORING_SETUP_SQ_AFF     = (1 << 2) /* sq_thread_cpu is valid */
   168  	IORING_SETUP_CQSIZE     = (1 << 3) /* app defines CQ size */
   169  	IORING_SETUP_CLAMP      = (1 << 4) /* clamp SQ/CQ ring sizes */
   170  	IORING_SETUP_ATTACH_WQ  = (1 << 5) /* attach to existing wq */
   171  	IORING_SETUP_R_DISABLED = (1 << 6) /* start with ring disabled */
   172  	IORING_SETUP_SUBMIT_ALL = (1 << 7) /* continue submit on error */
   173  )
   174  
   175  /*
   176   * Cooperative task running. When requests complete, they often require
   177   * forcing the submitter to transition to the kernel to complete. If this
   178   * flag is set, work will be done when the task transitions anyway, rather
   179   * than force an inter-processor interrupt reschedule. This avoids interrupting
   180   * a task running in userspace, and saves an IPI.
   181   */
   182  const IORING_SETUP_COOP_TASKRUN = (1 << 8)
   183  
   184  /*
   185   * If COOP_TASKRUN is set, get notified if task work is available for
   186   * running and a kernel transition would be needed to run it. This sets
   187   * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
   188   */
   189  const IORING_SETUP_TASKRUN_FLAG = (1 << 9)
   190  
   191  const IORING_SETUP_SQE128 = (1 << 10) /* SQEs are 128 byte */
   192  const IORING_SETUP_CQE32 = (1 << 11)  /* CQEs are 32 byte */
   193  
   194  type IoUringOp = uint8
   195  
   196  //go:generate stringerx -type=IoUringOp
   197  
   198  const (
   199  	IORING_OP_NOP IoUringOp = iota
   200  	IORING_OP_READV
   201  	IORING_OP_WRITEV
   202  	IORING_OP_FSYNC
   203  	IORING_OP_READ_FIXED
   204  	IORING_OP_WRITE_FIXED
   205  	IORING_OP_POLL_ADD
   206  	IORING_OP_POLL_REMOVE
   207  	IORING_OP_SYNC_FILE_RANGE
   208  	IORING_OP_SENDMSG
   209  	IORING_OP_RECVMSG
   210  	IORING_OP_TIMEOUT
   211  	IORING_OP_TIMEOUT_REMOVE
   212  	IORING_OP_ACCEPT
   213  	IORING_OP_ASYNC_CANCEL
   214  	IORING_OP_LINK_TIMEOUT
   215  	IORING_OP_CONNECT
   216  	IORING_OP_FALLOCATE
   217  	IORING_OP_OPENAT
   218  	IORING_OP_CLOSE
   219  	IORING_OP_FILES_UPDATE
   220  	IORING_OP_STATX
   221  	IORING_OP_READ
   222  	IORING_OP_WRITE
   223  	IORING_OP_FADVISE
   224  	IORING_OP_MADVISE
   225  	IORING_OP_SEND
   226  	IORING_OP_RECV
   227  	IORING_OP_OPENAT2
   228  	IORING_OP_EPOLL_CTL
   229  	IORING_OP_SPLICE
   230  	IORING_OP_PROVIDE_BUFFERS
   231  	IORING_OP_REMOVE_BUFFERS
   232  	IORING_OP_TEE
   233  	IORING_OP_SHUTDOWN
   234  	IORING_OP_RENAMEAT
   235  	IORING_OP_UNLINKAT
   236  	IORING_OP_MKDIRAT
   237  	IORING_OP_SYMLINKAT
   238  	IORING_OP_LINKAT
   239  	IORING_OP_MSG_RING
   240  	IORING_OP_FSETXATTR
   241  	IORING_OP_SETXATTR
   242  	IORING_OP_FGETXATTR
   243  	IORING_OP_GETXATTR
   244  	IORING_OP_SOCKET
   245  	IORING_OP_URING_CMD
   246  
   247  	/* this goes last, obviously */
   248  	IORING_OP_LAST
   249  )
   250  
   251  /*
   252   * sqe->fsync_flags
   253   */
   254  const IORING_FSYNC_DATASYNC = (1 << 0)
   255  
   256  /*
   257   * sqe->timeout_flags
   258   */
   259  const (
   260  	IORING_TIMEOUT_ABS           = (1 << 0)
   261  	IORING_TIMEOUT_UPDATE        = (1 << 1)
   262  	IORING_TIMEOUT_BOOTTIME      = (1 << 2)
   263  	IORING_TIMEOUT_REALTIME      = (1 << 3)
   264  	IORING_LINK_TIMEOUT_UPDATE   = (1 << 4)
   265  	IORING_TIMEOUT_ETIME_SUCCESS = (1 << 5)
   266  	IORING_TIMEOUT_CLOCK_MASK    = (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
   267  	IORING_TIMEOUT_UPDATE_MASK   = (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
   268  )
   269  
   270  /*
   271   * sqe->splice_flags
   272   * extends splice(2) flags
   273   */
   274  const SPLICE_F_FD_IN_FIXED = (1 << 31) /* the last bit of __u32 */
   275  
   276  /*
   277   * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the
   278   * command flags for POLL_ADD are stored in sqe->len.
   279   *
   280   * IORING_POLL_ADD_MULTI	Multishot poll. Sets IORING_CQE_F_MORE if
   281   *				the poll handler will continue to report
   282   *				CQEs on behalf of the same SQE.
   283   *
   284   * IORING_POLL_UPDATE		Update existing poll request, matching
   285   *				sqe->addr as the old user_data field.
   286   */
   287  const (
   288  	IORING_POLL_ADD_MULTI        = (1 << 0)
   289  	IORING_POLL_UPDATE_EVENTS    = (1 << 1)
   290  	IORING_POLL_UPDATE_USER_DATA = (1 << 2)
   291  )
   292  
   293  /*
   294   * ASYNC_CANCEL flags.
   295   *
   296   * IORING_ASYNC_CANCEL_ALL	Cancel all requests that match the given key
   297   * IORING_ASYNC_CANCEL_FD	Key off 'fd' for cancelation rather than the
   298   *				request 'user_data'
   299   * IORING_ASYNC_CANCEL_ANY	Match any request
   300   */
   301  const (
   302  	IORING_ASYNC_CANCEL_ALL = (1 << 0)
   303  	IORING_ASYNC_CANCEL_FD  = (1 << 1)
   304  	IORING_ASYNC_CANCEL_ANY = (1 << 2)
   305  )
   306  
   307  /*
   308   * send/sendmsg and recv/recvmsg flags (sqe->addr2)
   309   *
   310   * IORING_RECVSEND_POLL_FIRST	If set, instead of first attempting to send
   311   *				or receive and arm poll if that yields an
   312   *				-EAGAIN result, arm poll upfront and skip
   313   *				the initial transfer attempt.
   314   */
   315  const IORING_RECVSEND_POLL_FIRST = (1 << 0)
   316  
   317  /*
   318   * accept flags stored in sqe->ioprio
   319   */
   320  const IORING_ACCEPT_MULTISHOT = (1 << 0)
   321  
   322  /*
   323   * IO completion data structure (Completion Queue Entry)
   324   */
   325  type IoUringCqe struct {
   326  	UserData UserData /* sqe->data submission passed back */
   327  	Res      int32    /* result code for this event */
   328  	Flags    uint32
   329  
   330  	/*
   331  	 * If the ring is initialized with IORING_SETUP_CQE32, then this field
   332  	 * contains 16-bytes of padding, doubling the size of the CQE.
   333  	 */
   334  	//  __u64 big_cqe[];
   335  
   336  	// 8+4+4 == 16 , correct
   337  }
   338  
   339  /*
   340   * cqe->flags
   341   *
   342   * IORING_CQE_F_BUFFER	If set, the upper 16 bits are the buffer ID
   343   * IORING_CQE_F_MORE	If set, parent SQE will generate more CQE entries
   344   * IORING_CQE_F_SOCK_NONEMPTY	If set, more data to read after socket recv
   345   */
   346  
   347  const (
   348  	IORING_CQE_F_BUFFER        = (1 << 0)
   349  	IORING_CQE_F_MORE          = (1 << 1)
   350  	IORING_CQE_F_SOCK_NONEMPTY = (1 << 2)
   351  )
   352  
   353  const (
   354  	IORING_CQE_BUFFER_SHIFT = 16
   355  )
   356  
   357  /*
   358   * Magic offsets for the application to mmap the data it needs
   359   */
   360  const (
   361  	IORING_OFF_SQ_RING = 0
   362  	IORING_OFF_CQ_RING = 0x8000000
   363  	IORING_OFF_SQES    = 0x10000000
   364  )
   365  
   366  /*
   367   * Filled with the offset for mmap(2)
   368   */
   369  
   370  type IoSqringOffsets struct {
   371  	Head        uint32
   372  	Tail        uint32
   373  	RingMask    uint32
   374  	RingEntries uint32
   375  	Flags       uint32
   376  	Dropped     uint32
   377  	Array       uint32
   378  	resv1       uint32
   379  	resv2       uint64
   380  }
   381  
   382  /*
   383   * sq_ring->flags
   384   */
   385  const (
   386  	IORING_SQ_NEED_WAKEUP = (1 << 0) /* needs io_uring_enter wakeup */
   387  	IORING_SQ_CQ_OVERFLOW = (1 << 1) /* CQ ring is overflown */
   388  	IORING_SQ_TASKRUN     = (1 << 2) /* task should enter the kernel */
   389  )
   390  
   391  type IoCqringOffsets struct {
   392  	Head        uint32
   393  	Tail        uint32
   394  	RingMask    uint32
   395  	RingEntries uint32
   396  	Overflow    uint32
   397  	Cqes        uint32
   398  	Flags       uint32
   399  	resv1       uint32
   400  	resv2       uint64
   401  }
   402  
   403  /*
   404   * cq_ring->flags
   405   */
   406  
   407  /* disable eventfd notifications */
   408  const IORING_CQ_EVENTFD_DISABLED = (1 << 0)
   409  
   410  /*
   411   * io_uring_enter(2) flags
   412   */
   413  const (
   414  	IORING_ENTER_GETEVENTS       = (1 << 0)
   415  	IORING_ENTER_SQ_WAKEUP       = (1 << 1)
   416  	IORING_ENTER_SQ_WAIT         = (1 << 2)
   417  	IORING_ENTER_EXT_ARG         = (1 << 3)
   418  	IORING_ENTER_REGISTERED_RING = (1 << 4)
   419  )
   420  
   421  /*
   422   * Passed in for io_uring_setup(2). Copied back with updated info on success
   423   */
   424  
   425  type IoUringParams struct {
   426  	SqEntries    uint32
   427  	CqEntries    uint32
   428  	Flags        uint32
   429  	SqThreadCpu  uint32
   430  	SqThreadIdle uint32
   431  	Features     uint32
   432  	WqFd         uint32
   433  	resv         [3]uint32
   434  	SqOff        IoSqringOffsets
   435  	CqOff        IoCqringOffsets
   436  }
   437  
   438  /*
   439   * io_uring_params->features flags
   440   */
   441  const (
   442  	IORING_FEAT_SINGLE_MMAP     = (1 << 0)
   443  	IORING_FEAT_NODROP          = (1 << 1)
   444  	IORING_FEAT_SUBMIT_STABLE   = (1 << 2)
   445  	IORING_FEAT_RW_CUR_POS      = (1 << 3)
   446  	IORING_FEAT_CUR_PERSONALITY = (1 << 4)
   447  	IORING_FEAT_FAST_POLL       = (1 << 5)
   448  	IORING_FEAT_POLL_32BITS     = (1 << 6)
   449  	IORING_FEAT_SQPOLL_NONFIXED = (1 << 7)
   450  	IORING_FEAT_EXT_ARG         = (1 << 8)
   451  	IORING_FEAT_NATIVE_WORKERS  = (1 << 9)
   452  	IORING_FEAT_RSRC_TAGS       = (1 << 10)
   453  	IORING_FEAT_CQE_SKIP        = (1 << 11)
   454  	IORING_FEAT_LINKED_FILE     = (1 << 12)
   455  )
   456  
   457  /*
   458   * io_uring_register(2) opcodes and arguments
   459   */
   460  const (
   461  	IORING_REGISTER_BUFFERS       = 0
   462  	IORING_UNREGISTER_BUFFERS     = 1
   463  	IORING_REGISTER_FILES         = 2
   464  	IORING_UNREGISTER_FILES       = 3
   465  	IORING_REGISTER_EVENTFD       = 4
   466  	IORING_UNREGISTER_EVENTFD     = 5
   467  	IORING_REGISTER_FILES_UPDATE  = 6
   468  	IORING_REGISTER_EVENTFD_ASYNC = 7
   469  	IORING_REGISTER_PROBE         = 8
   470  	IORING_REGISTER_PERSONALITY   = 9
   471  	IORING_UNREGISTER_PERSONALITY = 10
   472  	IORING_REGISTER_RESTRICTIONS  = 11
   473  	IORING_REGISTER_ENABLE_RINGS  = 12
   474  
   475  	/* extended with tagging */
   476  	IORING_REGISTER_FILES2         = 13
   477  	IORING_REGISTER_FILES_UPDATE2  = 14
   478  	IORING_REGISTER_BUFFERS2       = 15
   479  	IORING_REGISTER_BUFFERS_UPDATE = 16
   480  
   481  	/* set/clear io-wq thread affinities */
   482  	IORING_REGISTER_IOWQ_AFF   = 17
   483  	IORING_UNREGISTER_IOWQ_AFF = 18
   484  
   485  	/* set/get max number of io-wq workers */
   486  	IORING_REGISTER_IOWQ_MAX_WORKERS = 19
   487  
   488  	/* register/unregister io_uring fd with the ring */
   489  	IORING_REGISTER_RING_FDS   = 20
   490  	IORING_UNREGISTER_RING_FDS = 21
   491  
   492  	/* register ring based provide buffer group */
   493  	IORING_REGISTER_PBUF_RING   = 22
   494  	IORING_UNREGISTER_PBUF_RING = 23
   495  
   496  	/* this goes last */
   497  	IORING_REGISTER_LAST
   498  )
   499  
   500  /* io-wq worker categories */
   501  const (
   502  	IO_WQ_BOUND = iota
   503  	IO_WQ_UNBOUND
   504  )
   505  
   506  /* deprecated, see struct IoUringRsrcUpdate */
   507  type IoUringFilesUpdate struct {
   508  	Offset uint32
   509  	resv   uint32
   510  	Fds    uint64 // __aligned_u64/* __s32 * */
   511  }
   512  
   513  /*
   514   * Register a fully sparse file space, rather than pass in an array of all
   515   * -1 file descriptors.
   516   */
   517  const IORING_RSRC_REGISTER_SPARSE = (1 << 0)
   518  
   519  type IoUringRsrcRegister struct {
   520  	Nr    uint32
   521  	Flags uint32
   522  	resv2 uint64
   523  	Data  uint64 // __aligned_u64
   524  	Tags  uint64 // __aligned_u64
   525  }
   526  
   527  type IoUringRsrcUpdate struct {
   528  	Offset uint32
   529  	resv   uint32
   530  	Data   uint64 // __aligned_u64
   531  }
   532  
   533  type IoUringRsrcUpdate2 struct {
   534  	Offset uint32
   535  	resv   uint32
   536  	Data   uint64 // __aligned_u64
   537  	Tags   uint64 // __aligned_u64
   538  	Nr     uint32
   539  	resv2  uint32
   540  }
   541  
   542  /* Skip updating fd indexes set to this value in the fd table */
   543  const IORING_REGISTER_FILES_SKIP = (-2)
   544  
   545  const IO_URING_OP_SUPPORTED = (1 << 0)
   546  
   547  type IoUringProbeOp struct {
   548  	op    uint8
   549  	resv  uint8
   550  	flags uint16 /* IO_URING_OP_* flags */
   551  	resv2 uint32
   552  }
   553  
   554  type IoUringProbe struct {
   555  	last_op uint8 /* last opcode supported */
   556  	uint8         /* length of ops[] array below */
   557  	resv    uint16
   558  	resv2   [3]uint32
   559  	ops     [0]IoUringProbeOp
   560  }
   561  
   562  type IoUringRestriction struct {
   563  	opcode uint16
   564  	//  union {
   565  	// 	 __u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */
   566  	// 	 __u8 sqe_op;      /* IORING_RESTRICTION_SQE_OP */
   567  	// 	 __u8 sqe_flags;   /* IORING_RESTRICTION_SQE_FLAGS_* */
   568  	//  };
   569  	Union1 uint8
   570  	resv   uint8
   571  	resv2  [3]uint32
   572  }
   573  
   574  type IoUringBuf struct {
   575  	Addr uint64
   576  	Len  uint32
   577  	Bid  uint16
   578  	resv uint16
   579  }
   580  
   581  type IoUringBufRing struct {
   582  	//  union {
   583  	/*
   584  	 * To avoid spilling into more pages than we need to, the
   585  	 * ring tail is overlaid with the IoUringBuf->resv field.
   586  	 */
   587  	Anon0 struct {
   588  		resv1 uint64
   589  		resv2 uint32
   590  		resv3 uint16
   591  		Tail  uint16
   592  	}
   593  	// bufs [0]IoUringBuf
   594  	//  };
   595  }
   596  
   597  /* argument for IORING_(UN)REGISTER_PBUF_RING */
   598  type IoUringBufReg struct {
   599  	RingAddr    uint64
   600  	RingEntries uint32
   601  	Bgid        uint16
   602  	Pad         uint16
   603  	resv        [3]uint64
   604  }
   605  
   606  /*
   607   * IoUringRestriction->opcode values
   608   */
   609  const (
   610  	/* Allow an io_uring_register(2) opcode */
   611  	IORING_RESTRICTION_REGISTER_OP = 0
   612  
   613  	/* Allow an sqe opcode */
   614  	IORING_RESTRICTION_SQE_OP = 1
   615  
   616  	/* Allow sqe flags */
   617  	IORING_RESTRICTION_SQE_FLAGS_ALLOWED = 2
   618  
   619  	/* Require sqe flags (these flags must be set on each submission) */
   620  	IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3
   621  
   622  	IORING_RESTRICTION_LAST
   623  )
   624  
   625  type IoUringGeteventsArg struct {
   626  	Sigmask   uint64
   627  	SigmaskSz uint32
   628  	Pad       uint32
   629  	Ts        uint64
   630  }
   631  
   632  /*
   633   * accept flags stored in sqe->ioprio
   634   */
   635  // const IORING_ACCEPT_MULTISHOT = (1 << 0)