IOBuffer - Shared memory endpoint with asymmetric access control and disciplines
An IOBuffer (IOB) is a peered Zircon kernel object designed for high-throughput, low-latency communication and shared memory transports between processes. It combines peered session management with multi-region encapsulation, asymmetric access control, and kernel-mediated access disciplines.
An IOBuffer always operates as a pair of endpoints (Endpoint 0 and Endpoint 1). It allows two processes to communicate by sharing multiple independent memory regions (up to a maximum of 64, defined by ZX_IOB_MAX_REGIONS), each configured with specific access permissions and behavior.
Like Channels and Sockets, IOBuffer endpoints are peered.
ZX_IOB_PEER_CLOSED signal on the opposing endpoint.An IOBuffer can encapsulate multiple memory regions:
ZX_IOB_REGION_TYPE_PRIVATE): Backed by a private VmObject uniquely owned by the IOBuffer pair. Used for isolated, point-to-point communication.ZX_IOB_REGION_TYPE_SHARED) (Experimental): Points to a standalone shared_region object. Multiple independent IOBuffer pairs can reference the same shared region, enabling many-to-one patterns (for example, multiple client log writers sending data to a single reader).You can configure each region with different permissions for Endpoint 0 and Endpoint 1. Permissions include:
ZX_IOB_ACCESS_EP0_CAN_MAP_READ / _WRITEZX_IOB_ACCESS_EP1_CAN_MAP_READ / _WRITEzx_iob_writev). This protects against Time-of-Check to Time-of-Use (TOCTOU) attacks.ZX_IOB_ACCESS_EP0_CAN_MEDIATED_READ / _WRITEZX_IOB_ACCESS_EP1_CAN_MEDIATED_READ / _WRITEWhen validating a memory operation, the kernel intersects the region's access permissions (logical AND) with the endpoint handle rights. Region-level permissions cannot override handle-level permissions.
uRn & hRn and uWn & hWn respectively, where u represents mapping permission and h represents handle rights.kRn & hRn and kWn & hWn respectively, where k represents mediated permission and h represents handle rights.Unlike direct mappings, kernel-mediated access operates in a logical/directional sense rather than absolute hardware permissions. For example, a logical mediated read operation (such as retrieving data from a ring buffer) may require the kernel to write to bookkeeping structures in that same region under the hood. The kernel permits such internal bookkeeping writes for read-only mediated endpoints, because the kernel acts as the trusted mediator enforcing the logic.
Disciplines define the structured memory layout and behavior for kernel-mediated operations within a region:
ZX_IOB_DISCIPLINE_TYPE_NONE): Free-form raw byte buffer. No kernel-mediated operations.ZX_IOB_DISCIPLINE_TYPE_ID_ALLOCATOR) (Experimental): A thread-safe structure mapping sized data blobs to sequentially allocated numeric IDs. Useful for string interning in tracing.ZX_IOB_DISCIPLINE_TYPE_MEDIATED_WRITE_RING_BUFFER) (Experimental): A circular ring buffer designed for concurrent, kernel-mediated writes by multiple clients and a single userspace reader (for example, high-efficiency system logging).The system maps IOBuffer regions into a VMAR via zx_vmar_map_iob. Only the following VMAR options are supported:
ZX_VM_SPECIFICZX_VM_SPECIFIC_OVERWRITEZX_VM_OFFSET_IS_UPPER_LIMITZX_VM_PERM_READZX_VM_PERM_WRITEZX_VM_MAP_RANGEAny other VMAR options return ZX_ERR_INVALID_ARGS.
IOBuffers support standard property queries via zx_object_get_info.
ZX_INFO_IOBReturns information about the overall IOBuffer instance using zx_iob_info_t:
options: The options used at creation.region_count: The number of memory regions encapsulated.ZX_INFO_IOB_REGIONSReturns information about each region as an array of zx_iob_region_info_t.
ZX_INFO_PROCESS_VMOSThe kernel reports the memory objects backing private IOB regions under this topic like standard VMOs. By default, backing VMOs share the name of the parent IOBuffer.
An IOBuffer handle has the following rights by default:
ZX_RIGHT_TRANSFERZX_RIGHT_DUPLICATEZX_RIGHT_WAITZX_RIGHT_INSPECTZX_RIGHT_READZX_RIGHT_WRITEZX_RIGHT_MAPZX_RIGHT_SIGNALZX_RIGHT_SIGNAL_PEERZX_RIGHT_GET_PROPERTYZX_RIGHT_SET_PROPERTYIOBuffers support the following properties:
ZX_PROP_NAME: Used for diagnostics and attributing memory.The system can set the following signals for an IOBuffer endpoint:
zx_iob_create() - create a new peered IOBuffer pairzx_iob_create_shared_region() (Experimental) - create a standalone shared regionzx_iob_writev() - perform a kernel-mediated write to a regionzx_iob_allocate_id() (Experimental) - allocate an ID in an ID Allocator regionzx_vmar_map_iob() - map an IOBuffer region into a VMAR