⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

try_enter_usermode

Function try_enter_usermode 

Source
pub fn try_enter_usermode() -> Result<(), KernelError>
Expand description

Attempt to enter user mode with the embedded init binary.

This function:

  1. Retrieves the physical memory offset from BOOT_INFO
  2. Allocates physical frames for user code and stack
  3. Maps them at user-accessible virtual addresses in the current page tables
  4. Copies the embedded INIT_CODE machine code to the code page
  5. Sets up the per-CPU kernel_rsp for syscall/interrupt return
  6. Transitions to Ring 3 via iretq

On success, this function does not return (enters user mode). On failure, returns a KernelError for the caller to log.