AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
binfmt.c File Reference

Loading a program into a process, for execve(). More...

#include <core/arch.h>
#include <sys/binfmt.h>
#include <sys/elf.h>
#include <mm/vm.h>

Go to the source code of this file.

Macros

#define NR_BINFMT   ((sizeof(binfmt_list)/sizeof(binfmt_list[0])))

Functions

static int binfmt_fmt_load (struct proc *proc, const char *path, struct vnode *vnode, struct binfmt *binfmt, struct proc **ref)
 Replaces a process's memory with a program, loaded by a format: the process's other threads end, its old address space goes, and the program, a heap, a stack and the signal code page are mapped.
int binfmt_load (struct proc *proc, const char *path, struct proc **ref)
 Loads a program into a process, for execve().

Variables

static struct binfmt binfmt_list []

Detailed Description

Loading a program into a process, for execve().

The program's file is looked up and checked, then each executable format the kernel knows (only ELF) is asked whether the file is one of its own; the first that says yes loads it. Then the process gets its heap, its stack and the signal code page.

Definition in file binfmt.c.

Macro Definition Documentation

◆ NR_BINFMT

#define NR_BINFMT   ((sizeof(binfmt_list)/sizeof(binfmt_list[0])))

Definition at line 19 of file binfmt.c.

Referenced by binfmt_load().

Function Documentation

◆ binfmt_fmt_load()

int binfmt_fmt_load ( struct proc * proc,
const char * path,
struct vnode * vnode,
struct binfmt * binfmt,
struct proc ** ref )
static

Replaces a process's memory with a program, loaded by a format: the process's other threads end, its old address space goes, and the program, a heap, a stack and the signal code page are mapped.

Returns 0 or a negative errno; on failure the address space is left empty, and the caller has to kill the process.

Definition at line 28 of file binfmt.c.

References arch_sigcode_map(), vm_entry::base, binfmt_fmt_load(), vm_entry::flags, queue::head, proc::heap, proc::heap_start, proc::heap_vm, kfree(), kmalloc(), binfmt::load, M_ZERO, proc::name, NULL, PAGE_ROUND, proc_threads_exec(), vm_entry::qnode, vm_entry::size, thread::stack_base, thread::stack_size, proc::stack_vm, proc::threads, USER_STACK_BASE, USER_STACK_SIZE, qnode::value, vm_space::vm_entries, vm_entry::vm_object, proc::vm_space, vm_space_destroy(), and VM_URW.

Referenced by binfmt_fmt_load(), and binfmt_load().

◆ binfmt_load()

int binfmt_load ( struct proc * proc,
const char * path,
struct proc ** ref )

Loads a program into a process, for execve().

The file must be a regular file that the process may execute, in a format the kernel knows.

Parameters
procthe process, whose memory the program replaces
paththe program's path
refnot used
Returns
0, or a negative errno: -ENOENT, -EACCES, -ENOEXEC (no format knows the file) or the loader's

Definition at line 124 of file binfmt.c.

References binfmt_fmt_load(), binfmt_list, binfmt_load(), memset(), vnode::mode, NR_BINFMT, NULL, PROC_UIO, vfs_access(), vfs_close(), vfs_lookup(), and VFS_X.

Referenced by binfmt_load(), kmain(), and proc_execve().

Variable Documentation

◆ binfmt_list

struct binfmt binfmt_list[]
static
Initial value:
= {
}
int binfmt_elf_check(struct vnode *vnode)
Says whether a file is an ELF program this kernel can run: its magic number, class and machine.
Definition elf.c:199
int binfmt_elf_load(struct proc *proc, const char *path, struct vnode *vnode)
Loads an ELF program into a process.
Definition elf.c:227

Definition at line 15 of file binfmt.c.

Referenced by binfmt_load().