|
1 | 1 | #include <unistd.h> |
2 | 2 | #include <sys/syscall.h> |
3 | 3 | #include <sys/uio.h> |
4 | | - |
5 | 4 | #include <signal.h> |
| 5 | + |
| 6 | +#if __has_include(<linux/io_uring.h>) |
6 | 7 | #include <linux/io_uring.h> |
| 8 | +#else |
| 9 | +// Minimal fallback definitions when linux/io_uring.h is not available (e.g. static SDK) |
| 10 | +#include <stdint.h> |
| 11 | + |
| 12 | +#define IORING_OFF_SQ_RING 0ULL |
| 13 | +#define IORING_OFF_CQ_RING 0x8000000ULL |
| 14 | +#define IORING_OFF_SQES 0x10000000ULL |
| 15 | + |
| 16 | +#define IORING_ENTER_GETEVENTS (1U << 0) |
| 17 | + |
| 18 | +#define IORING_FEAT_SINGLE_MMAP (1U << 0) |
| 19 | +#define IORING_FEAT_NODROP (1U << 1) |
| 20 | +#define IORING_FEAT_SUBMIT_STABLE (1U << 2) |
| 21 | +#define IORING_FEAT_RW_CUR_POS (1U << 3) |
| 22 | +#define IORING_FEAT_CUR_PERSONALITY (1U << 4) |
| 23 | +#define IORING_FEAT_FAST_POLL (1U << 5) |
| 24 | +#define IORING_FEAT_POLL_32BITS (1U << 6) |
| 25 | +#define IORING_FEAT_SQPOLL_NONFIXED (1U << 7) |
| 26 | +#define IORING_FEAT_EXT_ARG (1U << 8) |
| 27 | +#define IORING_FEAT_NATIVE_WORKERS (1U << 9) |
| 28 | +#define IORING_FEAT_RSRC_TAGS (1U << 10) |
| 29 | +#define IORING_FEAT_CQE_SKIP (1U << 11) |
| 30 | +#define IORING_FEAT_LINKED_FILE (1U << 12) |
| 31 | +#define IORING_FEAT_REG_REG_RING (1U << 13) |
| 32 | +#define IORING_FEAT_RECVSEND_BUNDLE (1U << 14) |
| 33 | +#define IORING_FEAT_MIN_TIMEOUT (1U << 15) |
| 34 | +#define IORING_FEAT_RW_ATTR (1U << 16) |
| 35 | +#define IORING_FEAT_NO_IOWAIT (1U << 17) |
| 36 | + |
| 37 | +typedef uint8_t __u8; |
| 38 | +typedef uint16_t __u16; |
| 39 | +typedef uint32_t __u32; |
| 40 | +typedef uint64_t __u64; |
| 41 | +typedef int32_t __s32; |
| 42 | + |
| 43 | +#ifndef __kernel_rwf_t |
| 44 | +typedef int __kernel_rwf_t; |
| 45 | +#endif |
| 46 | + |
| 47 | +struct io_uring_sqe { |
| 48 | + __u8 opcode; |
| 49 | + __u8 flags; |
| 50 | + __u16 ioprio; |
| 51 | + __s32 fd; |
| 52 | + union { |
| 53 | + __u64 off; |
| 54 | + __u64 addr2; |
| 55 | + struct { |
| 56 | + __u32 cmd_op; |
| 57 | + __u32 __pad1; |
| 58 | + }; |
| 59 | + }; |
| 60 | + union { |
| 61 | + __u64 addr; |
| 62 | + __u64 splice_off_in; |
| 63 | + struct { |
| 64 | + __u32 level; |
| 65 | + __u32 optname; |
| 66 | + }; |
| 67 | + }; |
| 68 | + __u32 len; |
| 69 | + union { |
| 70 | + __kernel_rwf_t rw_flags; |
| 71 | + __u32 fsync_flags; |
| 72 | + __u16 poll_events; |
| 73 | + __u32 poll32_events; |
| 74 | + __u32 sync_range_flags; |
| 75 | + __u32 msg_flags; |
| 76 | + __u32 timeout_flags; |
| 77 | + __u32 accept_flags; |
| 78 | + __u32 cancel_flags; |
| 79 | + __u32 open_flags; |
| 80 | + __u32 statx_flags; |
| 81 | + __u32 fadvise_advice; |
| 82 | + __u32 splice_flags; |
| 83 | + __u32 rename_flags; |
| 84 | + __u32 unlink_flags; |
| 85 | + __u32 hardlink_flags; |
| 86 | + __u32 xattr_flags; |
| 87 | + __u32 msg_ring_flags; |
| 88 | + __u32 uring_cmd_flags; |
| 89 | + __u32 waitid_flags; |
| 90 | + __u32 futex_flags; |
| 91 | + __u32 install_fd_flags; |
| 92 | + __u32 nop_flags; |
| 93 | + }; |
| 94 | + __u64 user_data; |
| 95 | + union { |
| 96 | + __u16 buf_index; |
| 97 | + __u16 buf_group; |
| 98 | + } __attribute__((packed)); |
| 99 | + __u16 personality; |
| 100 | + union { |
| 101 | + __s32 splice_fd_in; |
| 102 | + __u32 file_index; |
| 103 | + __u32 optlen; |
| 104 | + struct { |
| 105 | + __u16 addr_len; |
| 106 | + __u16 __pad3[1]; |
| 107 | + }; |
| 108 | + }; |
| 109 | + union { |
| 110 | + struct { |
| 111 | + __u64 addr3; |
| 112 | + __u64 __pad2[1]; |
| 113 | + }; |
| 114 | + __u64 optval; |
| 115 | + __u8 cmd[0]; |
| 116 | + }; |
| 117 | +}; |
| 118 | + |
| 119 | +struct io_uring_cqe { |
| 120 | + __u64 user_data; |
| 121 | + __s32 res; |
| 122 | + __u32 flags; |
| 123 | +}; |
| 124 | + |
| 125 | +struct io_sqring_offsets { |
| 126 | + __u32 head; |
| 127 | + __u32 tail; |
| 128 | + __u32 ring_mask; |
| 129 | + __u32 ring_entries; |
| 130 | + __u32 flags; |
| 131 | + __u32 dropped; |
| 132 | + __u32 array; |
| 133 | + __u32 resv1; |
| 134 | + __u64 user_addr; |
| 135 | +}; |
| 136 | + |
| 137 | +struct io_cqring_offsets { |
| 138 | + __u32 head; |
| 139 | + __u32 tail; |
| 140 | + __u32 ring_mask; |
| 141 | + __u32 ring_entries; |
| 142 | + __u32 overflow; |
| 143 | + __u32 cqes; |
| 144 | + __u32 flags; |
| 145 | + __u32 resv1; |
| 146 | + __u64 user_addr; |
| 147 | +}; |
| 148 | + |
| 149 | +struct io_uring_params { |
| 150 | + __u32 sq_entries; |
| 151 | + __u32 cq_entries; |
| 152 | + __u32 flags; |
| 153 | + __u32 sq_thread_cpu; |
| 154 | + __u32 sq_thread_idle; |
| 155 | + __u32 features; |
| 156 | + __u32 wq_fd; |
| 157 | + __u32 resv[3]; |
| 158 | + struct io_sqring_offsets sq_off; |
| 159 | + struct io_cqring_offsets cq_off; |
| 160 | +}; |
| 161 | +#endif // __has_include(<linux/io_uring.h>) |
7 | 162 |
|
8 | 163 | #ifndef SWIFT_IORING_C_WRAPPER |
9 | 164 | #define SWIFT_IORING_C_WRAPPER |
|
0 commit comments