The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
arch_context.h File Reference
#include "common/stdint.h"

Go to the source code of this file.

Functions

void arch_context_switch (uintptr_t *old_sp, uintptr_t new_sp)
 switch kernel execution from one process to another.
void arch_setup_initial_stack (process_t *proc, void(*entry_fn)(void))
 prepare a process's kernel stack so its first arch_context_switch() into it begins executing entry_fn.
void arch_setup_fork_stack (process_t *child, const struct registers *regs, uintptr_t user_sp)
 prepare a forked child's kernel stack so its first arch_context_switch() into it returns to user mode with the parent's registers, except that the syscall returns 0 (and, for a thread, the user stack is its own).

Function Documentation

◆ arch_context_switch()

void arch_context_switch ( uintptr_t * old_sp,
uintptr_t new_sp )

switch kernel execution from one process to another.

saves the current callee-saved state on the current kernel stack, writes the resulting stack pointer into *old_sp, then loads new_sp and resumes whatever that stack was set up to run.

Parameters
old_spwhere to store the outgoing process's kernel stack pointer.
new_spthe incoming process's saved kernel stack pointer.

◆ arch_setup_initial_stack()

void arch_setup_initial_stack ( process_t * proc,
void(* entry_fn )(void) )

prepare a process's kernel stack so its first arch_context_switch() into it begins executing entry_fn.

entry_fn takes no arguments and never returns. on return, proc->kernel_esp points at the prepared stack.

Parameters
procthe process whose kernel stack to prime (uses kernel_stack).
entry_fnthe function the process should start running.

◆ arch_setup_fork_stack()

void arch_setup_fork_stack ( process_t * child,
const struct registers * regs,
uintptr_t user_sp )

prepare a forked child's kernel stack so its first arch_context_switch() into it returns to user mode with the parent's registers, except that the syscall returns 0 (and, for a thread, the user stack is its own).

Parameters
childthe new process (uses kernel_stack, sets kernel_esp).
regsthe parent's saved user registers (its fork syscall frame).
user_spthe child's user stack pointer, or 0 for the parent's.