|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "usermode.h"#include "arch/arch.h"#include "arch/x86/cpu/gdt.h"#include "arch/x86/cpu/paging.h"#include "kernel/memory/pmm.h"#include "kernel/memory/memory_layout.h"#include "kernel/panic.h"#include "common/memory.h"#include "common/string.h"#include "arch/x86/cpu/isr.h"Macros | |
| #define | USER_EFLAGS 0x202u |
Functions | |
| uintptr_t | usermode_build_stack (addr_space_t as, const char **argv, const char **envp) |
| back the first pages of the user stack in an address space and put a new program's arguments on it, laid out the way crt0 reads them: [esp] 0 (fake return address), argc, argv, envp, then the two NULL-terminated pointer arrays and the strings. | |
| void | jump_to_usermode (uintptr_t entry, addr_space_t as, const char **argv, const char **envp) |
| start a new process's program: build its user stack (usermode_build_stack), point the TSS at the current kernel stack and iret to ring 3. | |
| void | usermode_reset_frame (struct registers *regs, uintptr_t entry, uintptr_t user_esp) |
| make a syscall frame return into a fresh program: clear the general registers and set the user entry point, stack, flags and segments. | |
| #define USER_EFLAGS 0x202u |
| uintptr_t usermode_build_stack | ( | addr_space_t | as, |
| const char ** | argv, | ||
| const char ** | envp ) |
back the first pages of the user stack in an address space and put a new program's arguments on it, laid out the way crt0 reads them: [esp] 0 (fake return address), argc, argv, envp, then the two NULL-terminated pointer arrays and the strings.
the address space must be the active one: the stack is written through its user addresses.
| as | the address space. |
| argv | NULL-terminated argument strings (may be NULL). |
| envp | NULL-terminated "KEY=VALUE" strings (may be NULL). |
| void jump_to_usermode | ( | uintptr_t | entry, |
| addr_space_t | as, | ||
| const char ** | argv, | ||
| const char ** | envp ) |
start a new process's program: build its user stack (usermode_build_stack), point the TSS at the current kernel stack and iret to ring 3.
the address space must be the active one. never returns.
| entry | the program's entry point. |
| as | the process's address space. |
| argv | NULL-terminated argument strings (may be NULL). |
| envp | NULL-terminated environment strings (may be NULL). |
make a syscall frame return into a fresh program: clear the general registers and set the user entry point, stack, flags and segments.
| regs | the syscall frame. |
| entry | the program's entry point. |
| user_esp | the initial user stack pointer. |