Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:21

0001 /*
0002    This file is part of Valgrind, a dynamic binary instrumentation framework.
0003 
0004    Copyright (C) 2019 Bart Van Assche <bvanassche@acm.org>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of the
0009    License, or (at your option) any later version.
0010 
0011    This program is distributed in the hope that it will be useful, but
0012    WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    General Public License for more details.
0015 
0016    You should have received a copy of the GNU General Public License
0017    along with this program; if not, see <http://www.gnu.org/licenses/>.
0018 
0019    The GNU General Public License is contained in the file COPYING.
0020 */
0021 
0022 #ifndef _VKI_IO_URING_H_
0023 #define _VKI_IO_URING_H_
0024 
0025 // Derived from linux-5.2/include/uapi/linux/io_uring.h */
0026 
0027 /*
0028  * IO submission data structure (Submission Queue Entry)
0029  */
0030 struct vki_io_uring_sqe {
0031     __vki_u8    opcode;     /* type of operation for this sqe */
0032     __vki_u8    flags;      /* IOSQE_ flags */
0033     __vki_u16   ioprio;     /* ioprio for the request */
0034     __vki_s32   fd;     /* file descriptor to do IO on */
0035     __vki_u64   off;        /* offset into file */
0036     __vki_u64   addr;       /* pointer to buffer or iovecs */
0037     __vki_u32   len;        /* buffer size or number of iovecs */
0038     union {
0039         int     rw_flags;
0040         __vki_u32   fsync_flags;
0041         __vki_u16   poll_events;
0042         __vki_u32   sync_range_flags;
0043         __vki_u32   msg_flags;
0044     };
0045     __vki_u64   user_data;  /* data to be passed back at completion time */
0046     union {
0047         __vki_u16   buf_index;  /* index into fixed buffers, if used */
0048         __vki_u64   __pad2[3];
0049     };
0050 };
0051 
0052 /*
0053  * sqe->flags
0054  */
0055 #define VKI_IOSQE_FIXED_FILE    (1U << 0)   /* use fixed fileset */
0056 #define VKI_IOSQE_IO_DRAIN  (1U << 1)   /* issue after inflight IO */
0057 #define VKI_IOSQE_IO_LINK   (1U << 2)   /* links next sqe */
0058 
0059 /*
0060  * io_uring_setup() flags
0061  */
0062 #define VKI_IORING_SETUP_IOPOLL (1U << 0)   /* io_context is polled */
0063 #define VKI_IORING_SETUP_SQPOLL (1U << 1)   /* SQ poll thread */
0064 #define VKI_IORING_SETUP_SQ_AFF (1U << 2)   /* sq_thread_cpu is valid */
0065 
0066 #define VKI_IORING_OP_NOP       0
0067 #define VKI_IORING_OP_READV     1
0068 #define VKI_IORING_OP_WRITEV    2
0069 #define VKI_IORING_OP_FSYNC     3
0070 #define VKI_IORING_OP_READ_FIXED    4
0071 #define VKI_IORING_OP_WRITE_FIXED   5
0072 #define VKI_IORING_OP_POLL_ADD  6
0073 #define VKI_IORING_OP_POLL_REMOVE   7
0074 #define VKI_IORING_OP_SYNC_FILE_RANGE   8
0075 #define VKI_IORING_OP_SENDMSG   9
0076 #define VKI_IORING_OP_RECVMSG   10
0077 
0078 /*
0079  * sqe->fsync_flags
0080  */
0081 #define VKI_IORING_FSYNC_DATASYNC   (1U << 0)
0082 
0083 /*
0084  * IO completion data structure (Completion Queue Entry)
0085  */
0086 struct vki_io_uring_cqe {
0087     __vki_u64   user_data;  /* sqe->data submission passed back */
0088     __vki_s32   res;        /* result code for this event */
0089     __vki_u32   flags;
0090 };
0091 
0092 /*
0093  * Magic offsets for the application to mmap the data it needs
0094  */
0095 #define VKI_IORING_OFF_SQ_RING      0ULL
0096 #define VKI_IORING_OFF_CQ_RING      0x8000000ULL
0097 #define VKI_IORING_OFF_SQES     0x10000000ULL
0098 
0099 /*
0100  * Filled with the offset for mmap(2)
0101  */
0102 struct vki_io_sqring_offsets {
0103     __vki_u32 head;
0104     __vki_u32 tail;
0105     __vki_u32 ring_mask;
0106     __vki_u32 ring_entries;
0107     __vki_u32 flags;
0108     __vki_u32 dropped;
0109     __vki_u32 array;
0110     __vki_u32 resv1;
0111     __vki_u64 resv2;
0112 };
0113 
0114 /*
0115  * sq_ring->flags
0116  */
0117 #define VKI_IORING_SQ_NEED_WAKEUP   (1U << 0) /* needs io_uring_enter wakeup */
0118 
0119 struct vki_io_cqring_offsets {
0120     __vki_u32 head;
0121     __vki_u32 tail;
0122     __vki_u32 ring_mask;
0123     __vki_u32 ring_entries;
0124     __vki_u32 overflow;
0125     __vki_u32 cqes;
0126     __vki_u64 resv[2];
0127 };
0128 
0129 /*
0130  * io_uring_enter(2) flags
0131  */
0132 #define VKI_IORING_ENTER_GETEVENTS  (1U << 0)
0133 #define VKI_IORING_ENTER_SQ_WAKEUP  (1U << 1)
0134 
0135 /*
0136  * Passed in for io_uring_setup(2). Copied back with updated info on success
0137  */
0138 struct vki_io_uring_params {
0139     __vki_u32 sq_entries;
0140     __vki_u32 cq_entries;
0141     __vki_u32 flags;
0142     __vki_u32 sq_thread_cpu;
0143     __vki_u32 sq_thread_idle;
0144     __vki_u32 resv[5];
0145     struct vki_io_sqring_offsets sq_off;
0146     struct vki_io_cqring_offsets cq_off;
0147 };
0148 
0149 /*
0150  * io_uring_register(2) opcodes and arguments
0151  */
0152 #define VKI_IORING_REGISTER_BUFFERS 0
0153 #define VKI_IORING_UNREGISTER_BUFFERS   1
0154 #define VKI_IORING_REGISTER_FILES   2
0155 #define VKI_IORING_UNREGISTER_FILES 3
0156 #define VKI_IORING_REGISTER_EVENTFD 4
0157 #define VKI_IORING_UNREGISTER_EVENTFD   5
0158 
0159 #endif