Line data Source code
1 : #ifndef HEADER_fd_src_util_io_fd_io_uring_register_h 2 : #define HEADER_fd_src_util_io_fd_io_uring_register_h 3 : 4 : /* fd_io_uring_register.h provides APIs to add file descriptors and 5 : sandbox restrictions to an ioring. */ 6 : 7 : #include "fd_io_uring_sys.h" 8 : #include <errno.h> 9 : #include <sys/uio.h> 10 : #include "../../util/fd_util_base.h" 11 : 12 : FD_PROTOTYPES_BEGIN 13 : 14 : static inline int 15 : fd_io_uring_register_buffers( int ring_fd, 16 : struct iovec const * iovecs, 17 0 : ulong iovec_cnt ) { 18 0 : if( FD_UNLIKELY( iovec_cnt > UINT_MAX ) ) return -EINVAL; 19 0 : return fd_io_uring_register( ring_fd, FD_IORING_REGISTER_BUFFERS, iovecs, (uint)iovec_cnt ); 20 0 : } 21 : 22 : static inline int 23 : fd_io_uring_register_files( int ring_fd, 24 : int const * fds, 25 0 : ulong fd_cnt ) { 26 0 : if( FD_UNLIKELY( fd_cnt > UINT_MAX ) ) return -EINVAL; 27 0 : return fd_io_uring_register( ring_fd, FD_IORING_REGISTER_FILES, fds, (uint)fd_cnt ); 28 0 : } 29 : 30 : static inline int 31 : fd_io_uring_register_files_update( int ring_fd, 32 : unsigned off, 33 : const int * files, 34 0 : unsigned nr_files ) { 35 0 : fd_io_uring_rsrc_update_t up = { 36 0 : .offset = off, 37 0 : .data = (unsigned long) files, 38 0 : }; 39 0 : return fd_io_uring_register( ring_fd, FD_IORING_REGISTER_FILES_UPDATE, &up, nr_files ); 40 0 : } 41 : 42 : static inline int 43 : fd_io_uring_register_restrictions( int ring_fd, 44 : fd_io_uring_restriction_t * res, 45 0 : uint res_cnt ) { 46 0 : return fd_io_uring_register( ring_fd, FD_IORING_REGISTER_RESTRICTIONS, res, res_cnt ); 47 0 : } 48 : 49 : static inline int 50 0 : fd_io_uring_enable_rings( int ring_fd ) { 51 0 : return fd_io_uring_register( ring_fd, FD_IORING_REGISTER_ENABLE_RINGS, NULL, 0 ); 52 0 : } 53 : 54 : FD_PROTOTYPES_END 55 : 56 : #endif /* HEADER_fd_src_util_io_fd_io_uring_register_h */