miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
Ring-3 Entry and Userspace Helpers

Functions to transfer execution to ring-3 and set up userspace argument arrays. More...

Functions

void enter_ring3 (uint64_t entry_rip, uint64_t user_rsp)
 Builds an IRETQ stack frame (SS, RSP, RFLAGS=0x202, CS=user_cs, RIP) and executes IRETQ, transferring control to @entry_rip at CPL=3. Enables interrupts (RFLAGS.IF=1) as part of the frame. Does not return — execution continues in ring 3 at @entry_rip.
int copy_string_array_to_user (struct thread *t, char *const *arr, uint64_t *user_ptr)
 Copies each string to the user stack, builds a pointer array below the strings, and writes the address of that array to *@user_ptr. Used by SYS_execve to pass argv/envp to the new process image.

Detailed Description

Functions to transfer execution to ring-3 and set up userspace argument arrays.

Function Documentation

◆ copy_string_array_to_user()

int copy_string_array_to_user ( struct thread * t,
char *const * arr,
uint64_t * user_ptr )

Copies each string to the user stack, builds a pointer array below the strings, and writes the address of that array to *@user_ptr. Used by SYS_execve to pass argv/envp to the new process image.

copy_string_array_to_user() - Copy a NULL-terminated string array into a thread's user stack.

Parameters
tDestination thread whose user stack will receive the strings.
arrNULL-terminated array of C strings (e.g. argv[] or envp[]).
user_ptrOutput; set to the user-space address of the copied pointer array.
Returns
0 on success, -1 if the user stack has insufficient space.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_ring3()

void enter_ring3 ( uint64_t entry_rip,
uint64_t user_rsp )

Builds an IRETQ stack frame (SS, RSP, RFLAGS=0x202, CS=user_cs, RIP) and executes IRETQ, transferring control to @entry_rip at CPL=3. Enables interrupts (RFLAGS.IF=1) as part of the frame. Does not return — execution continues in ring 3 at @entry_rip.

enter_ring3() - Switch from ring 0 to ring 3 via IRETQ.

Parameters
entry_ripRing-3 instruction pointer to jump to (e.g. 0x400000 for ELF entry).
user_rspRing-3 stack pointer (e.g. USER_STACK_TOP - 8).
Here is the caller graph for this function: