PatchworkOS
Loading...
Searching...
No Matches
Program Loader

Program loading and user stack management. More...

Functions

NORETURN void loader_jump_to_user_space (thread_t *thread)
 Performs the initial jump to userspace.
 
thread_tloader_spawn (const char **argv, priority_t priority, const path_t *cwd)
 Spawns a child process from an executable file.
 
thread_tloader_thread_create (process_t *parent, void *entry, void *arg)
 Creates a new thread within an existing process.
 

Detailed Description

Program loading and user stack management.

The loader is responsible for loading programs into memory and the jump to userspace.

Function Documentation

◆ loader_jump_to_user_space()

NORETURN void loader_jump_to_user_space ( thread_t thread)
extern

Performs the initial jump to userspace.

Parameters
threadThe curently running thread that will jump to userspace.

Referenced by loader_process_entry().

◆ loader_spawn()

thread_t * loader_spawn ( const char **  argv,
priority_t  priority,
const path_t cwd 
)

Spawns a child process from an executable file.

Parameters
argvA null-terminated array of strings storing the arguments to be passed to usespace and the executable to be loaded in argv[0].
priorityThe priority of the first thread within the child process.
cwdThe current working directory for the child process, if cwd is null then the child inherits the working directory of the parent.
Returns
On success, returns the main thread of the child process. On failure, returns NULL and errno is set.

Definition at line 154 of file loader.c.

References assert, interrupt_frame_t::cs, DEREF_DEFER, EINVAL, EISDIR, ERR, errno, thread_t::frame, GDT_CS_RING0, GDT_SS_RING0, process_t::id, info, INODE_FILE, thread_t::kernelStack, loader_process_entry(), LOG_INFO, NULL, pathname_init(), process_new(), interrupt_frame_t::rflags, RFLAGS_ALWAYS_SET, RFLAGS_INTERRUPT_ENABLE, interrupt_frame_t::rip, interrupt_frame_t::rsp, sched_process(), interrupt_frame_t::ss, thread_new(), stack_pointer_t::top, and vfs_stat().

Referenced by init_process_spawn(), and SYSCALL_DEFINE().

◆ loader_thread_create()

thread_t * loader_thread_create ( process_t parent,
void *  entry,
void *  arg 
)

Creates a new thread within an existing process.

Parameters
parentThe parent process for the new thread.
entryThe entry point address for the new thread.
argAn argument to pass to the entry point.
Returns
On success, returns the newly created thread. On failure, returns NULL and errno is set.

Definition at line 343 of file loader.c.

References interrupt_frame_t::cs, thread_t::frame, GDT_CS_RING3, GDT_SS_RING3, NULL, interrupt_frame_t::rdi, interrupt_frame_t::rflags, RFLAGS_ALWAYS_SET, RFLAGS_INTERRUPT_ENABLE, interrupt_frame_t::rip, interrupt_frame_t::rsp, interrupt_frame_t::ss, thread_new(), stack_pointer_t::top, and thread_t::userStack.

Referenced by SYSCALL_DEFINE().