The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
exec.c File Reference

Macros

#define EXEC_FAILED_EXIT_STATUS   127
#define SCRIPT_LINE_MAX   128

Functions

int exec_program (const char *path, const char **argv)
 start a program as a new process.
kerr_t exec_replace (struct registers *regs, const char *path, const char **argv, const char **envp)
 replace the current process's program (execve).
void usermode_exit (int exit_code)
 called by SYS_exit: end the current thread, and never run again.
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.
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).
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.

Macro Definition Documentation

◆ EXEC_FAILED_EXIT_STATUS

#define EXEC_FAILED_EXIT_STATUS   127

◆ SCRIPT_LINE_MAX

#define SCRIPT_LINE_MAX   128

Function Documentation

◆ exec_program()

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.

Parameters
pathabsolute path to the ELF executable.
argvnull-terminated array of argument strings (may be NULL).
Returns
the new process's PID, or -1 on failure.

◆ exec_replace()

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).

Parameters
regsthe caller's syscall frame. a script that starts with "#!interpreter [arg]" runs as "interpreter [arg] path argv[1]...".
pathabsolute path of the ELF executable or script.
argvNULL-terminated argument strings in kernel memory.
envpNULL-terminated environment strings in kernel memory.
Returns
KERR_OK, KERR_NOENT if the file is not there, KERR_NOEXEC if it is not an ELF executable or a script, KERR_PERM if the caller may not run it, or KERR_NOMEM.

◆ usermode_exit()

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.

Parameters
exit_codethe exit code passed by the user program (low 8 bits).

◆ usermode_exit_group()

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.

Parameters
exit_codethe exit code (low 8 bits).

◆ usermode_kill()

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).

Parameters
signalthe signal number (kernel/signal/signal.h).

◆ usermode_end_thread()

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.