| ... | @@ -967,3 +967,129 @@ pub const stack_t = extern struct { | ... | @@ -967,3 +967,129 @@ pub const stack_t = extern struct { |
| 967 | ss_flags: i32, | 967 | ss_flags: i32, |
| 968 | ss_size: isize, | 968 | ss_size: isize, |
| 969 | }; | 969 | }; |
| | 970 | |
| | 971 | pub const io_uring_params = extern struct { |
| | 972 | sq_entries: u32, |
| | 973 | cq_entries: u32, |
| | 974 | flags: u32, |
| | 975 | sq_thread_cpu: u32, |
| | 976 | sq_thread_idle: u32, |
| | 977 | resv: [5]u32, |
| | 978 | sq_off: io_sqring_offsets, |
| | 979 | cq_off: io_cqring_offsets, |
| | 980 | }; |
| | 981 | |
| | 982 | // io_uring_params.flags |
| | 983 | |
| | 984 | /// io_context is polled |
| | 985 | pub const IORING_SETUP_IOPOLL = (1 << 0); |
| | 986 | |
| | 987 | /// SQ poll thread |
| | 988 | pub const IORING_SETUP_SQPOLL = (1 << 1); |
| | 989 | |
| | 990 | /// sq_thread_cpu is valid |
| | 991 | pub const IORING_SETUP_SQ_AFF = (1 << 2); |
| | 992 | |
| | 993 | pub const io_sqring_offsets = extern struct { |
| | 994 | /// offset of ring head |
| | 995 | head: u32, |
| | 996 | |
| | 997 | /// offset of ring tail |
| | 998 | tail: u32, |
| | 999 | |
| | 1000 | /// ring mask value |
| | 1001 | ring_mask: u32, |
| | 1002 | |
| | 1003 | /// entries in ring |
| | 1004 | ring_entries: u32, |
| | 1005 | |
| | 1006 | /// ring flags |
| | 1007 | flags: u32, |
| | 1008 | |
| | 1009 | /// number of sqes not submitted |
| | 1010 | dropped: u32, |
| | 1011 | |
| | 1012 | /// sqe index array |
| | 1013 | array: u32, |
| | 1014 | |
| | 1015 | resv1: u32, |
| | 1016 | resv2: u64, |
| | 1017 | }; |
| | 1018 | |
| | 1019 | // io_sqring_offsets.flags |
| | 1020 | |
| | 1021 | /// needs io_uring_enter wakeup |
| | 1022 | pub const IORING_SQ_NEED_WAKEUP = 1 << 0; |
| | 1023 | |
| | 1024 | pub const io_cqring_offsets = extern struct { |
| | 1025 | head: u32, |
| | 1026 | tail: u32, |
| | 1027 | ring_mask: u32, |
| | 1028 | ring_entries: u32, |
| | 1029 | overflow: u32, |
| | 1030 | cqes: u32, |
| | 1031 | resv: [2]u64, |
| | 1032 | }; |
| | 1033 | |
| | 1034 | pub const io_uring_sqe = extern struct { |
| | 1035 | opcode: u8, |
| | 1036 | flags: u8, |
| | 1037 | ioprio: u16, |
| | 1038 | fd: i32, |
| | 1039 | off: u64, |
| | 1040 | addr: u64, |
| | 1041 | len: u32, |
| | 1042 | pub const union1 = extern union { |
| | 1043 | rw_flags: kernel_rwf, |
| | 1044 | fsync_flags: u32, |
| | 1045 | poll_event: u16, |
| | 1046 | }; |
| | 1047 | union1: union1, |
| | 1048 | user_data: u64, |
| | 1049 | pub const union2 = extern union { |
| | 1050 | buf_index: u16, |
| | 1051 | __pad2: [3]u64, |
| | 1052 | }; |
| | 1053 | union2: union2, |
| | 1054 | }; |
| | 1055 | |
| | 1056 | // io_uring_sqe.flags |
| | 1057 | |
| | 1058 | /// use fixed fileset |
| | 1059 | pub const IOSQE_FIXED_FILE = (1 << 0); |
| | 1060 | |
| | 1061 | pub const IORING_OP_NOP = 0; |
| | 1062 | pub const IORING_OP_READV = 1; |
| | 1063 | pub const IORING_OP_WRITEV = 2; |
| | 1064 | pub const IORING_OP_FSYNC = 3; |
| | 1065 | pub const IORING_OP_READ_FIXED = 4; |
| | 1066 | pub const IORING_OP_WRITE_FIXED = 5; |
| | 1067 | pub const IORING_OP_POLL_ADD = 6; |
| | 1068 | pub const IORING_OP_POLL_REMOVE = 7; |
| | 1069 | |
| | 1070 | // io_uring_sqe.fsync_flags |
| | 1071 | pub const IORING_FSYNC_DATASYNC = (1 << 0); |
| | 1072 | |
| | 1073 | // IO completion data structure (Completion Queue Entry) |
| | 1074 | pub const io_uring_cqe = extern struct { |
| | 1075 | /// io_uring_sqe.data submission passed back |
| | 1076 | user_data: u64, |
| | 1077 | |
| | 1078 | /// result code for this event |
| | 1079 | res: i32, |
| | 1080 | flags: u32, |
| | 1081 | }; |
| | 1082 | |
| | 1083 | pub const IORING_OFF_SQ_RING = 0; |
| | 1084 | pub const IORING_OFF_CQ_RING = 0x8000000; |
| | 1085 | pub const IORING_OFF_SQES = 0x10000000; |
| | 1086 | |
| | 1087 | // io_uring_enter flags |
| | 1088 | pub const IORING_ENTER_GETEVENTS = (1 << 0); |
| | 1089 | pub const IORING_ENTER_SQ_WAKEUP = (1 << 1); |
| | 1090 | |
| | 1091 | // io_uring_register opcodes and arguments |
| | 1092 | pub const IORING_REGISTER_BUFFERS = 0; |
| | 1093 | pub const IORING_UNREGISTER_BUFFERS = 1; |
| | 1094 | pub const IORING_REGISTER_FILES = 2; |
| | 1095 | pub const IORING_UNREGISTER_FILES = 3; |