The kernel implements a minimalist microkernel system call interface (kcalls). All kernel services, drivers, and user tasks communicate across privilege boundaries via standard architectural traps. The core kernel exposes only fundamental primitives: context yielding, synchronous inter-process communication (IPC), service discovery, and privileged hardware mapping.
- Trap instruction:
ecall - Call vector:
trap_handlerviastvec/mtvec - System Call ID: Register
a7 - Arguments:
a0,a1,a2,a3,a4,a5 - Return value: Register
a0 - State preservation: All 32 general-purpose registers saved in
struct trap_frameon kernel stack.
- Trap instruction:
int 0x80/syscall - Call ID: Register
eax/rax - Arguments:
ebx,ecx,edx,esi,edi,ebp(IA-32) orrdi,rsi,rdx,r10,r8,r9(x86_64) - Return value:
eax/rax
- Trap instruction:
svc 0 - Call ID: Register
r7(AArch32) /x8(AArch64) - Arguments:
r0-r5(AArch32) /x0-x5(AArch64) - Return value:
r0/x0
| ID | Constant | Function Prototype | Privilege | Description |
|---|---|---|---|---|
0 |
KCALL_YIELD |
uint32_t user_yield(void) |
Unprivileged | Voluntarily yields current time slice to scheduler |
1 |
KCALL_IPC_SEND |
uint32_t user_ipc_send(uint32_t dest_pid, void *msg) |
Capability checked | Synchronous message transmission to destination process |
2 |
KCALL_IPC_RECV |
uint32_t user_ipc_recv(uint32_t src_pid, void *buf) |
Capability checked | Synchronous message reception from source process |
3 |
KCALL_IPC_CALL |
uint32_t user_ipc_call(uint32_t dest_pid, void *msg, void *reply) |
Capability checked | Atomic bidirectional synchronous RPC transaction |
4 |
KCALL_GET_PID_BY_GID |
uint32_t user_get_pid_by_gid(uint32_t gid) |
Unprivileged | Resolves process ID for designated capability Group ID |
10 |
PKCALL_MAP_DEVICE |
uint32_t pkcall_map_device(uintptr_t phys, uintptr_t virt) |
Privileged (SID/GID) |
Maps physical device MMIO range into address space |
uint32_t user_yield(void);- Description: Relinquishes remaining CPU quantum. Places calling process at tail of round-robin runnable queue and dispatches next
PROCESS_READYthread. - Parameters: None.
- Return Value:
0on successful dispatch. - Side Effects: Modifies process state from
PROCESS_RUNNINGtoPROCESS_READY; triggers immediate context switch.
uint32_t user_ipc_send(uint32_t dest_pid, void *message_ptr);- Description: Initiates synchronous message transfer to
dest_pid. - Validation:
dest_pidmust exist and be within range[MIN_PID, MAX_PID].message_ptrvalidated viais_valid_user_buf(message_ptr, 64).- Sender and receiver GID relationship validated via
check_gid_permission().
- Rendezvous Logic:
- If target process is in state
PROCESS_BLOCKED_RECVwaiting for sender:- Kernel copies 64 bytes directly from
message_ptrto targetipc_msg_buf. - Target process state set to
PROCESS_READY. - Caller continues running or yields depending on scheduling policy.
- Kernel copies 64 bytes directly from
- If target process is not awaiting message:
- Calling process state set to
PROCESS_BLOCKED_SEND. - Sender
ipc_target_pidset todest_pid;ipc_msg_bufrecorded. - Scheduler dispatches next runnable thread.
- Calling process state set to
- If target process is in state
- Return Value:
0on success; negative error code on failure.
uint32_t user_ipc_recv(uint32_t src_pid, void *message_buf);- Description: Receives 64-byte message from
src_pid. Ifsrc_pid == 0, receives from any authorized sender. - Validation:
message_bufvalidated viais_valid_user_buf(message_buf, 64).
- Rendezvous Logic:
- If matching sender is blocked in
PROCESS_BLOCKED_SEND:- Kernel copies 64 bytes from sender buffer to
message_buf. - Blocked sender transitioned to
PROCESS_READY. - Receiver remains
PROCESS_RUNNING.
- Kernel copies 64 bytes from sender buffer to
- If no sender is pending:
- Receiver transitioned to
PROCESS_BLOCKED_RECV. - Receiver
ipc_target_pidset tosrc_pid;ipc_msg_bufrecorded. - Scheduler dispatches next thread.
- Receiver transitioned to
- If matching sender is blocked in
- Return Value:
0on success; negative error code on failure.
uint32_t user_ipc_call(uint32_t dest_pid, void *msg, void *reply);- Description: Atomic RPC transaction combining
user_ipc_sendanduser_ipc_recv. Eliminates intermediate context switch overhead by immediately blocking caller on reply fromdest_pid. - Parameters:
dest_pid: Target service PID.msg: Pointer to 64-byte outgoing request.reply: Pointer to 64-byte buffer for incoming response.
- Return Value:
0on transaction completion; negative on transmission error or timeout.
uint32_t user_get_pid_by_gid(uint32_t gid);- Description: Queries kernel process table to resolve system service managing specified Group ID (GID).
- Parameters:
gid: Capability group identifier (e.g.,FS_GID,SCREEN_GID,ANTARTICA_GID).
- Return Value: Process ID (
pid >= MIN_PID) of registered service, or0if service not running.
Caution
Private kcall, restricted to services with SID, explained here
uint32_t pkcall_map_device(uintptr_t phys_addr, uintptr_t virt_addr);- Description: Maps physical MMIO register page into caller address space.
- Security Check:
- Verified via
verify_pkcall(current_process->gid, current_process->sid). - Process must possess hardware capability GID (
HW_GID,SCREEN_GID,KEYBOARD_GID,VIRTIO_GID,GPU_GID). - Cryptographic Security Identifier (
sid) verified against entry point signature generated at process spawn.
- Verified via
- Page Table Modifications:
- Creates PTE with
PTE_V | PTE_R | PTE_W | PTE_U(W^X strictly enforced:PTE_Xnever set).
- Creates PTE with
- Return Value:
0on success;1on authorization failure; negative on page table allocation error.
All userspace buffer pointers passed to kcalls undergo mandatory hardware and software sanity checks:
- Null Pointer Check: Buffer address must not be zero.
- Userspace Range Verification:
bool is_valid_user_buf(const void *buf, size_t len) { uintptr_t start = (uintptr_t)buf; uintptr_t end = start + len; if (end < start) return false; // Overflow check return (start >= USER_MEM_START && end <= USER_MEM_END); }
- Alignment: 64-byte IPC messages must adhere to word alignment boundaries (
sizeof(uintptr_t)).