PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
loader.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <stdarg.h>
6
7/**
8 * @brief Program loading and user stack management.
9 * @defgroup kernel_sched_loader Program Loader
10 * @ingroup kernel_sched
11 *
12 * The loader is responsible for loading programs into memory, setting up the initial user stack, and performing the
13 * jump to userspace.
14 *
15 * ## Initial User Stack and Registers
16 *
17 * When a new program is loaded, we pass the command line arguments (argv) to the program via the user stack and
18 * registers.
19 *
20 * The stack is set up as follows:
21 *
22 * <div align="center">
23 * | Stack Contents |
24 * |---------------------|
25 * | *argv[argc - 1] |
26 * | ... |
27 * | *argv[0] |
28 * | NULL |
29 * | argv[argc - 1] |
30 * | ... |
31 * | argv[0] |
32 * | padding |
33 * </div>
34 *
35 * The `argv` pointer is placed in the `rsi` register, and the `argc` value is placed in the `rdi` register.
36 *
37 * Note that rsp points to argc when the program starts executing.
38 *
39 * @{
40 */
41
42/**
43 * @brief Causes the currently running thread to load and execute a new program.
44 *
45 * Intended to be used as the entry point for a newly created process, causing it to run the executable specified in its
46 * command line arguments.
47 *
48 * @note This function does not return, instead it transfers execution to the new program in user space, if it fails it
49 * will exit the process.
50 */
51_NORETURN void loader_exec(void);
52
53/** @} */
#define _NORETURN
Definition config.h:28
_NORETURN void loader_exec(void)
Causes the currently running thread to load and execute a new program.
Definition loader.c:40