Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

io_submit (nr 502)

Submit async I/O operations to a completion port.

Signature

io_submit(port_fd: i32, entries_ptr: *const IoSubmission, count: u32) → processed or -errno

Arguments

ArgRegisterDescription
port_fdrdiCompletion port fd (from io_create)
entries_ptrrsiPointer to array of submission entries
countrdxNumber of entries to submit

Submission entry layout

struct IoSubmission {       // 48 bytes, repr(C)
    uint64_t user_data;     // Opaque value returned in completion
    uint32_t opcode;        // Operation type (see below)
    uint32_t flags;         // Reserved, must be 0
    int32_t  fd;            // Target file descriptor (opcode-dependent)
    int32_t  _pad;
    uint64_t buf_addr;      // User buffer address
    uint32_t buf_len;       // User buffer length
    uint32_t offset;        // Reserved
    uint64_t timeout_ns;    // Timeout in nanoseconds (OP_TIMEOUT)
};

Opcodes

ValueNameDescription
0OP_NOPImmediate completion (testing/synchronization)
1OP_TIMEOUTTimer that completes after timeout_ns nanoseconds
2OP_READAsync read from fd into buf_addr
3OP_WRITEAsync write from buf_addr to fd
4OP_IRQ_WAITWait for an interrupt on an IRQ fd
5OP_IPC_SENDSend an IPC message on a channel send-end fd
6OP_IPC_RECVReceive an IPC message on a channel recv-end fd
7OP_RING_WAITWait for a notification fd signal

Return value

On success, returns the number of entries processed.

Errors

ErrorCondition
EFAULTentries_ptr is invalid
EBADFport_fd is not a valid completion port

Per-entry errors (EBADF, EFAULT, EINVAL) are reported via the completion result field rather than failing the entire submission.

Description

Each submission entry describes an async operation. The kernel processes entries sequentially, spawning async tasks for operations that cannot complete immediately. When an operation finishes, a completion entry is posted to the port and can be harvested via io_wait.

For OP_READ, data is read into a kernel buffer and copied to user space during io_wait (which runs in the process’s syscall context with the correct page tables).

For OP_IPC_SEND/RECV, buf_addr points to an IpcMessage struct. File descriptors in msg.fds are transferred across the channel.

For OP_RING_WAIT, fd must be a notification fd (from notify_create). The completion fires when another process calls notify(fd). Edge- triggered, one-shot: re-submit to rearm.

Implementation

osl/src/io_port.rssys_io_submit

See also