Skip to main content Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. Rust
  4. pw_kernel
  5. syscall_defs

Crate syscall_defs

Crate syscall_defs 

Source
Expand description

§pw_kernel User Space API

§Core Concepts

§Objects

Objects are the basic building block of functionality exposed to user space. They are polymorphic and may be one of a limited set of types:

§Handles

All system calls reference objects through a u32 handle which indexes into a process-local handle table.

§Signals and Waiting

Every kernel object has a set of signals that can be pending and waited upon. The exact meaning and semantics of each signal vary between kernel objects. The signal types are:

  • Signals::READABLE: Object is readable.
  • Signals::WRITABLE: Object is writable.
  • Signals::ERROR: Object is in an error state.
  • Signals::USER: User defined signal. Useful for out of band signaling between peers on a Channel.

Any kernel object can be waited for signals to assert using the object_wait() syscall. Multiple objects can be waited on simultaneously using a Wait Group object.

§Open Questions
  • What are the multi-threaded semantics of waiting.

§Object and Handle Creation

Initially only statically defined and allocated objects and handles are supported. The creation of these will be driven through build time configuration and the necessary code will be generated to allocate kernel data structures as well as expose handle definitions to user space processes.

§Object Types

§Channel

A channel is a unidirectional connection between two asymmetric peers: an initiator and a handler. A channel allows the initiator peer to send a buffer of data to the handler peer and wait for it’s response. A channel can have a maximum of one transaction pending at a time and is designed to not require intermediate kernel buffers.

Both a synchronous and asynchronous API is offered to the initiator while the handler side API is strictly non-blocking. All data copies between peers happen during the system call.

The flow of a transaction is as follows:

  • The initiator starts the transaction by providing send and receive buffers to one of the two transact system calls (channel_transact() or channel_async_transact()). This has the additional side effect of clearing Signals::READABLE and Signals::WRITABLE on the initiator.
  • The handler’s Signals::READABLE will become asserted.
  • The handler can now read the message in multiple calls to channel_read() causing the kernel to copy the data from the initiator’s send buffer to the buffer provided to channel_read().
  • The handler completes the transaction by calling channel_respond() and providing a response. The kernel will immediately copy the response from the handler’s buffer to the initiator’s receive buffer. There is no built in mechanism for the handler to signal an error to the initiator. This is left to the higher level protocol used to communicate over the channel. This will clear Signals::READABLE and Signals::WRITABLE on the handler and raise Signals::READABLE on the initiator.

The handler’s only ways of communicating with the initiator are by

§Initiator Signals
  • Signals::WRITABLE indicates there is no pending transaction and one can be started. Cleared on transaction initiation.
  • Signals::READABLE indicates the handler has responded to the pending transaction. Cleared on transaction initiation.
  • Signals::ERROR indicates pending transaction has an error. Cleared when the initiator is waited on.
  • Signals::USER indicates the handler calls object_set_peer_user_signal(). Cleared when the handler calls object_set_peer_user_signal() with set=false, or automatically by the kernel if the initiator handler terminates. Preserved on initiator process termination.
§Handler Signals
  • Signals::READABLE indicates there is a pending transaction. Cleared when the handler calls channel_respond().
  • Signals::WRITABLE indicates there is a pending transaction. Cleared when the handler calls channel_respond().
  • Signals::ERROR indicates a pending transaction error. No error states are defined at the moment. In the future an error may be raised when the remote peer closes.
  • Signals::USER indicates the initiator calls object_set_peer_user_signal(). Cleared when the initiator calls object_set_peer_user_signal() with set=false, or automatically by the kernel if the initiator process terminates. Preserved on handler process termination.

§Wait Group

Wait groups provide a mechanism for waiting on multiple handles at once. Handles can be added to and removed from a wait group with wait_group_add() and wait_group_remove(). In addition to a set of signals to wait on, an arbitrary user_data is provided to wait_group_add(). This value is returned by object_wait(), unmodified by the kernel, when the wait group is waited on.

§Open questions:
  • How is the wait group’s member list allocated in there kernel. To support a fully statically allocated kernel one of two approaches are being considered:
    • an object (or possibly handle) may only be in a single wait group at one time. This allows a wait group to maintain an intrusive list of objects with the list element storage being stored in the object.
    • wait queues are statically sized at compile time and adding more objects than there is space for will return an error.

§Interrupt

Interrupt objects provide a mechanism for handling hardware interrupts. A single Interrupt object can be configured to handle multiple interrupt sources (IRQs), up to a maximum of 16 per object. Each interrupt source handled by an Interrupt object is mapped to a unique signal bit within the higher 16 bits of Signals. These signals range from Signals::INTERRUPT_A (bit 16) to Signals::INTERRUPT_O (bit 30).

When a interrupt occurs for a source handled by an Interrupt object, the kernel masks the interrupt and then signals the corresponding INTERRUPT_ bit on the object. Userspace threads can wait on the Interrupt object using the object_wait() syscall.

Upon waking from object_wait(), the returned Signals mask indicates which interrupt(s) have triggered. After the userspace handler has serviced the interrupt(s), it must call the interrupt_ack() syscall to allow the interrupt(s) to be triggered again. This syscall must be provided with a Signals mask containing the bits for the interrupts that have been handled.

interrupt_ack() accomplishes two things:

  1. It clears the specified signal bits on the Interrupt object, allowing it to receive new signals for those interrupts.
  2. It signals to the underlying hardware interrupt controller (e.g., PLIC or NVIC) that the associated IRQ(s) have been acknowledged, re-enabling them at the hardware level.

§Futex

In design

§System Calls

The C ABI system calls listed here are not intended to be called directly by user space code and instead be accessed through language idiomatic wrapper libraries.

§Generic Syscalls

§Channel Initiator Syscalls

§Channel Handler Syscalls

§Wait Group Syscalls

Structs§

Signals
A set of object signals
SysCallReturnValue
WaitReturn
Return value from the object_wait() syscall.

Enums§

ExitStatus
Exit status of a process or thread.
SysCallId

Traits§

SysCallInterface

Functions§

channel_async_cancel⚠
Cancels a pending transaction on a channel
channel_async_transact⚠
Perform an asynchronous channel transaction
channel_async_transact_complete⚠
Completes an asynchronous channel transaction
channel_read⚠
Perform a non-blocking read from a pending transaction.
channel_respond⚠
Respond to and complete a pending transaction
channel_transact⚠
Perform a synchronous channel transaction
interrupt_ack⚠
Acknowledges the signaled interrupts allowing them to be signaled again.
object_set_peer_user_signal⚠
Set or clear Signals::USER on the paired peer.
object_wait⚠
Wait on a single object
wait_group_add⚠
Adds an object to a wait group
wait_group_remove⚠
Removes an object from a wait group