|
ginnOS
The reference: libc, the libraries and the kernel
|
Go to the source code of this file.
Macros | |
| #define | USER_ARG_MAX (128u * 1024u) |
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) __attribute__((noreturn)) |
| 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. | |
| kerr_t | exec_replace (struct registers *regs, const char *path, const char **argv, const char **envp) |
| replace the current process's program (execve). | |
| int | exec_program (const char *path, const char **argv) |
| start a program as a new process. | |
| void | usermode_exit (int exit_code) __attribute__((noreturn)) |
| called by SYS_exit: end the current thread, and never run again. | |
| void | usermode_exit_group (int exit_code) __attribute__((noreturn)) |
| called by SYS_exit_group (and so by exit()): end every thread of the current process, which then ends with exit_code. | |
| void | usermode_kill (int signal) __attribute__((noreturn)) |
| end the current process (every thread) as killed by a signal: the wait status names the signal (SIGSEGV for a bad memory access). | |
| void | usermode_end_thread (void) __attribute__((noreturn)) |
| end the current thread because its process is ending (exit_group or a fatal signal in another thread), with the process's status. | |
| uintptr_t | usermode_get_brk (void) |
| get the current program break (end of the user heap). | |
| void | usermode_set_brk (uintptr_t brk) |
| set the program break. | |
| void | setup_child_stack (process_t *child, uintptr_t entry) |
| set up a child process's kernel stack so that context_switch returns into the process entry trampoline. | |
| #define USER_ARG_MAX (128u * 1024u) |
| 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. |
| kerr_t exec_replace | ( | struct registers * | regs, |
| const char * | path, | ||
| const char ** | argv, | ||
| const char ** | envp ) |
replace the current process's program (execve).
the new image is loaded into a new address space first, so on failure the caller keeps running its old program. on success the old address space is gone, the areas and break are the new program's, its stack holds argv and envp, and the syscall frame returns into its entry point. pid, parent, cwd and fds stay (except FD_CLOEXEC ones, which are closed).
| regs | the caller's syscall frame. a script that starts with "#!interpreter [arg]" runs as "interpreter [arg] path argv[1]...". |
| path | absolute path of the ELF executable or script. |
| argv | NULL-terminated argument strings in kernel memory. |
| envp | NULL-terminated environment strings in kernel memory. |
| int exec_program | ( | const char * | path, |
| const char ** | argv ) |
start a program as a new process.
creates the process, loads the ELF at path into its address space, copies argv, inherits the caller's cwd and its fds without FD_CLOEXEC (when called from a process) and queues it on the scheduler. with no current process (boot), the new process has no parent: PID 1.
| path | absolute path to the ELF executable. |
| argv | null-terminated array of argument strings (may be NULL). |
| void usermode_exit | ( | int | exit_code | ) |
called by SYS_exit: end the current thread, and never run again.
if it is the last thread of its process, the process ends: it becomes a zombie for its parent to reap, with a wait status that says it exited with exit_code. if PID 1 ends, the system halts.
| exit_code | the exit code passed by the user program (low 8 bits). |
| void usermode_exit_group | ( | int | exit_code | ) |
called by SYS_exit_group (and so by exit()): end every thread of the current process, which then ends with exit_code.
| exit_code | the exit code (low 8 bits). |
| void usermode_kill | ( | int | signal | ) |
end the current process (every thread) as killed by a signal: the wait status names the signal (SIGSEGV for a bad memory access).
| signal | the signal number (kernel/signal/signal.h). |
| void usermode_end_thread | ( | void | ) |
end the current thread because its process is ending (exit_group or a fatal signal in another thread), with the process's status.
| uintptr_t usermode_get_brk | ( | void | ) |
get the current program break (end of the user heap).
| void usermode_set_brk | ( | uintptr_t | brk | ) |
set the program break.
called by exec_program after ELF loading to initialize the break.
| brk | the initial break address (page-aligned end of loaded segments). |
set up a child process's kernel stack so that context_switch returns into the process entry trampoline.
set up a child process's kernel stack so that when arch_context_switch switches to it, it "returns" into process_entry_trampoline.
| child | pointer to the child process control block. |
| entry | ELF entry point for the child. |
set up a child process's kernel stack so that context_switch returns into the process entry trampoline.
the ELF entry point is stashed in the process so the trampoline can read it later.