LCOV - code coverage report
Current view: top level - util/io_uring - fd_io_uring_sys.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 9 29 31.0 %
Date: 2026-09-17 04:28:31 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_util_io_fd_io_uring_sys_h
       2             : #define HEADER_fd_src_util_io_fd_io_uring_sys_h
       3             : 
       4             : /* fd_io_uring_sys.h provides the io_uring syscall API. */
       5             : 
       6             : #include "../fd_util_base.h"
       7             : #include <sys/syscall.h> /* SYS_* */
       8             : 
       9             : /* fd_kernel_timespec_t matches struct __kernel_timespec, which
      10             :    <linux/time_types.h> only provides since Linux v5.1. */
      11             : 
      12             : struct fd_kernel_timespec {
      13             :   long tv_sec;
      14             :   long tv_nsec;
      15             : };
      16             : 
      17             : typedef struct fd_kernel_timespec fd_kernel_timespec_t;
      18             : 
      19             : struct fd_io_uring_sqe {
      20             :   uchar  opcode;  /* FD_IORING_OP_* */
      21             :   uchar  flags;   /* FD_IOSQE_* */
      22             :   ushort ioprio;
      23             :   int    fd;
      24             :   union {
      25             :     ulong off;
      26             :     ulong addr2;
      27             :   };
      28             :   union {
      29             :     ulong addr;
      30             :     ulong splice_off_in;
      31             :   };
      32             :   uint len;
      33             :   union {
      34             :     uint   rw_flags;
      35             :     uint   fsync_flags;
      36             :     ushort poll_events;
      37             :     uint   poll32_events;
      38             :     uint   sync_range_flags;
      39             :     uint   msg_flags;
      40             :     uint   timeout_flags;
      41             :     uint   accept_flags;
      42             :     uint   cancel_flags;
      43             :     uint   open_flags;
      44             :     uint   splice_flags;
      45             :     uint   futex_flags;
      46             :   };
      47             :   ulong user_data;
      48             :   union {
      49             :     ushort buf_index;
      50             :     ushort buf_group;
      51             :   } __attribute__((packed));
      52             :   ushort personality;
      53             :   union {
      54             :     int  splice_fd_in;
      55             :     uint file_index;
      56             :   };
      57             :   union {
      58             :     ulong addr3;
      59             :     ulong optval;
      60             :   };
      61             :   ulong __pad2[1];
      62             : };
      63             : 
      64             : typedef struct fd_io_uring_sqe fd_io_uring_sqe_t;
      65             : 
      66             : struct fd_io_uring_cqe {
      67             :   ulong user_data; /* sqe->user_data value passed back */
      68             :   int   res;       /* result code for this event */
      69             :   uint  flags;
      70             : };
      71             : 
      72             : typedef struct fd_io_uring_cqe fd_io_uring_cqe_t;
      73             : 
      74             : struct fd_io_uring_rsrc_update {
      75             :   uint  offset;
      76             :   uint  resv;
      77             :   ulong data;
      78             : };
      79             : 
      80             : typedef struct fd_io_uring_rsrc_update fd_io_uring_rsrc_update_t;
      81             : 
      82             : struct fd_io_uring_getevents_arg {
      83             :   ulong sigmask;
      84             :   uint  sigmask_sz;
      85             :   uint  min_wait_usec;
      86             :   ulong ts;
      87             : };
      88             : 
      89             : typedef struct fd_io_uring_getevents_arg fd_io_uring_getevents_arg_t;
      90             : 
      91             : FD_STATIC_ASSERT( sizeof(fd_kernel_timespec_t)            ==16UL, abi );
      92             : FD_STATIC_ASSERT( sizeof(fd_io_uring_sqe_t)               ==64UL, abi );
      93             : FD_STATIC_ASSERT( sizeof(fd_io_uring_cqe_t)               ==16UL, abi );
      94             : FD_STATIC_ASSERT( sizeof(fd_io_uring_rsrc_update_t)       ==16UL, abi );
      95             : FD_STATIC_ASSERT( sizeof(fd_io_uring_getevents_arg_t)     ==24UL, abi );
      96             : FD_STATIC_ASSERT( __builtin_offsetof( fd_io_uring_sqe_t, user_data )==32UL, abi );
      97             : FD_STATIC_ASSERT( __builtin_offsetof( fd_io_uring_sqe_t, addr3     )==48UL, abi );
      98             : 
      99             : /* io_uring syscall numbers are identical on all architectures that
     100             :    Firedancer supports. */
     101             : 
     102             : #ifndef SYS_io_uring_setup
     103             : #define SYS_io_uring_setup 425
     104             : #endif
     105             : 
     106             : #ifndef SYS_io_uring_enter
     107             : #define SYS_io_uring_enter 426
     108             : #endif
     109             : 
     110             : #ifndef SYS_io_uring_register
     111             : #define SYS_io_uring_register 427
     112             : #endif
     113             : 
     114           0 : #define FD_IORING_SETUP_CQSIZE        (1U<< 3)
     115           0 : #define FD_IORING_SETUP_R_DISABLED    (1U<< 6)
     116           0 : #define FD_IORING_SETUP_COOP_TASKRUN  (1U<< 8)
     117           0 : #define FD_IORING_SETUP_SINGLE_ISSUER (1U<<12)
     118           0 : #define FD_IORING_SETUP_DEFER_TASKRUN (1U<<13)
     119           0 : #define FD_IORING_SETUP_NO_MMAP       (1U<<14)
     120             : 
     121             : /* mmap(2) offsets of the ring regions */
     122             : 
     123           0 : #define FD_IORING_OFF_SQ_RING 0x0UL
     124           0 : #define FD_IORING_OFF_CQ_RING 0x8000000UL
     125           0 : #define FD_IORING_OFF_SQES    0x10000000UL
     126             : 
     127           0 : #define FD_IORING_ENTER_GETEVENTS (1U<<0)
     128           0 : #define FD_IORING_ENTER_EXT_ARG   (1U<<3)
     129             : 
     130           0 : #define FD_IORING_REGISTER_BUFFERS           0
     131           0 : #define FD_IORING_REGISTER_FILES             2
     132           0 : #define FD_IORING_REGISTER_FILES_UPDATE      6
     133           0 : #define FD_IORING_REGISTER_RESTRICTIONS     11
     134           0 : #define FD_IORING_REGISTER_ENABLE_RINGS     12
     135             : #define FD_IORING_REGISTER_IOWQ_MAX_WORKERS 19
     136             : 
     137           0 : #define FD_IORING_RESTRICTION_REGISTER_OP        0
     138           0 : #define FD_IORING_RESTRICTION_SQE_OP             1
     139           0 : #define FD_IORING_RESTRICTION_SQE_FLAGS_ALLOWED  2
     140           0 : #define FD_IORING_RESTRICTION_SQE_FLAGS_REQUIRED 3
     141             : 
     142        1791 : #define FD_IORING_OP_NOP                     0
     143             : #define FD_IORING_OP_READV                   1
     144             : #define FD_IORING_OP_WRITEV                  2
     145             : #define FD_IORING_OP_FSYNC                   3
     146          96 : #define FD_IORING_OP_READ_FIXED              4
     147             : #define FD_IORING_OP_WRITE_FIXED             5
     148             : #define FD_IORING_OP_POLL_ADD                6
     149             : #define FD_IORING_OP_POLL_REMOVE             7
     150             : #define FD_IORING_OP_SYNC_FILE_RANGE         8
     151             : #define FD_IORING_OP_SENDMSG                 9
     152             : #define FD_IORING_OP_RECVMSG                10
     153             : #define FD_IORING_OP_TIMEOUT                11
     154             : #define FD_IORING_OP_TIMEOUT_REMOVE         12
     155          36 : #define FD_IORING_OP_ACCEPT                 13
     156             : #define FD_IORING_OP_ASYNC_CANCEL           14
     157         132 : #define FD_IORING_OP_LINK_TIMEOUT           15
     158             : #define FD_IORING_OP_CONNECT                16
     159             : #define FD_IORING_OP_FALLOCATE              17
     160             : #define FD_IORING_OP_OPENAT                 18
     161             : #define FD_IORING_OP_CLOSE                  19
     162             : #define FD_IORING_OP_FILES_UPDATE           20
     163             : #define FD_IORING_OP_STATX                  21
     164             : #define FD_IORING_OP_READ                   22
     165             : #define FD_IORING_OP_WRITE                  23
     166             : #define FD_IORING_OP_FADVISE                24
     167             : #define FD_IORING_OP_MADVISE                25
     168         114 : #define FD_IORING_OP_SEND                   26
     169          36 : #define FD_IORING_OP_RECV                   27
     170             : #define FD_IORING_OP_OPENAT2                28
     171             : #define FD_IORING_OP_EPOLL_CTL              29
     172             : #define FD_IORING_OP_SPLICE                 30
     173             : #define FD_IORING_OP_PROVIDE_BUFFERS        31
     174             : #define FD_IORING_OP_REMOVE_BUFFERS         32
     175             : #define FD_IORING_OP_TEE                    33
     176             : #define FD_IORING_OP_SHUTDOWN               34
     177             : #define FD_IORING_OP_RENAMEAT               35
     178             : #define FD_IORING_OP_UNLINKAT               36
     179             : #define FD_IORING_OP_MKDIRAT                37
     180             : #define FD_IORING_OP_SYMLINKAT              38
     181             : #define FD_IORING_OP_LINKAT                 39
     182             : #define FD_IORING_OP_MSG_RING               40
     183             : #define FD_IORING_OP_FSETXATTR              41
     184             : #define FD_IORING_OP_SETXATTR               42
     185             : #define FD_IORING_OP_FGETXATTR              43
     186             : #define FD_IORING_OP_GETXATTR               44
     187             : #define FD_IORING_OP_SOCKET                 45
     188             : #define FD_IORING_OP_URING_CMD              46
     189             : #define FD_IORING_OP_SEND_ZC                47
     190             : #define FD_IORING_OP_SENDMSG_ZC             48
     191             : #define FD_IORING_OP_READ_MULTISHOT         49
     192             : #define FD_IORING_OP_WAITID                 50
     193        1584 : #define FD_IORING_OP_FUTEX_WAIT             51
     194             : #define FD_IORING_OP_FUTEX_WAKE             52
     195             : #define FD_IORING_OP_FUTEX_WAITV            53
     196             : 
     197         999 : #define FD_IOSQE_FIXED_FILE       (1U<<0)
     198          66 : #define FD_IOSQE_IO_LINK          (1U<<2)
     199             : #define FD_IOSQE_CQE_SKIP_SUCCESS (1U<<6)
     200             : 
     201             : #define FD_IORING_RECVSEND_FIXED_BUF (1U<<2)
     202             : 
     203             : #ifndef FUTEX2_SIZE_U32
     204             : #define FUTEX2_SIZE_U32 0x02
     205             : #endif
     206             : 
     207             : struct fd_io_uring_restriction {
     208             :   ushort opcode;
     209             :   union {
     210             :     uchar register_op;
     211             :     uchar sqe_op;
     212             :     uchar sqe_flags;
     213             :   };
     214             :   uchar resv;
     215             :   uint  resv2[3];
     216             : };
     217             : 
     218             : typedef struct fd_io_uring_restriction fd_io_uring_restriction_t;
     219             : 
     220             : struct fd_io_sqring_offsets {
     221             :   uint head;
     222             :   uint tail;
     223             :   uint ring_mask;
     224             :   uint ring_entries;
     225             :   uint flags;
     226             :   uint dropped;
     227             :   uint array;
     228             :   uint resv1;
     229             :   ulong user_addr;
     230             : };
     231             : 
     232             : typedef struct fd_io_sqring_offsets fd_io_sqring_offsets_t;
     233             : 
     234             : struct fd_io_cqring_offsets {
     235             :   uint head;
     236             :   uint tail;
     237             :   uint ring_mask;
     238             :   uint ring_entries;
     239             :   uint overflow;
     240             :   uint cqes;
     241             :   uint flags;
     242             :   uint resv1;
     243             :   ulong user_addr;
     244             : };
     245             : 
     246             : typedef struct fd_io_cqring_offsets fd_io_cqring_offsets_t;
     247             : 
     248             : struct fd_io_uring_params {
     249             :   uint sq_entries;
     250             :   uint cq_entries;
     251             :   uint flags;
     252             :   uint sq_thread_cpu;
     253             :   uint sq_thread_idle;
     254             :   uint features;
     255             :   uint wq_fd;
     256             :   uint resv[3];
     257             :   fd_io_sqring_offsets_t sq_off;
     258             :   fd_io_cqring_offsets_t cq_off;
     259             : };
     260             : 
     261             : typedef struct fd_io_uring_params fd_io_uring_params_t;
     262             : 
     263             : FD_PROTOTYPES_BEGIN
     264             : 
     265             : /* fd_io_uring_enter wraps the fd_io_uring_enter(2) syscall. */
     266             : 
     267             : int
     268             : fd_io_uring_enter( int    ring_fd,
     269             :                    uint   to_submit,
     270             :                    uint   min_complete,
     271             :                    uint   flags,
     272             :                    void * arg,
     273             :                    ulong  arg_sz );
     274             : 
     275             : /* fd_io_uring_register wraps the io_uring_register(2) syscall. */
     276             : 
     277             : int
     278             : fd_io_uring_register( int          ring_fd,
     279             :                       uint         opcode,
     280             :                       void const * arg,
     281             :                       uint         arg_cnt );
     282             : 
     283             : /* fd_io_uring_setup wraps the io_uring_setup(2) syscall. */
     284             : 
     285             : int
     286             : fd_io_uring_setup( uint                   entry_cnt,
     287             :                    fd_io_uring_params_t * p );
     288             : 
     289             : FD_PROTOTYPES_END
     290             : 
     291             : #endif /* HEADER_fd_src_util_io_fd_io_uring_sys_h */

Generated by: LCOV version 1.14