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

The ELF loader. More...

#include <core/system.h>
#include <core/panic.h>
#include <core/arch.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/elf.h>
#include <mm/vm.h>

Go to the source code of this file.

Macros

#define ELF_CLASS   ELFCLASS64

Typedefs

typedef struct elf64_hdr elf_hdr
typedef struct elf64_phdr elf_phdr

Functions

static int binfmt_elf_load_segments (struct proc *proc, struct vnode *vnode)
 Maps the loadable segments of an ELF file into a process, and sets its entry point and the start of its heap.
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.
int binfmt_elf_load (struct proc *proc, const char *path, struct vnode *vnode)
 Loads an ELF program into a process.

Detailed Description

The ELF loader.

A program's loadable segments (PT_LOAD) are mapped from its file, lazily: the pages are read in by page faults, when the program first touches them. A writable segment is copied on write, so that the file stays as it is. The heap starts after the last segment.

Definition in file elf.c.

Macro Definition Documentation

◆ ELF_CLASS

#define ELF_CLASS   ELFCLASS64

Definition at line 31 of file elf.c.

Referenced by binfmt_elf_check(), and binfmt_elf_load_segments().

Typedef Documentation

◆ elf_hdr

typedef struct elf64_hdr elf_hdr

Definition at line 32 of file elf.c.

◆ elf_phdr

typedef struct elf64_phdr elf_phdr

Definition at line 33 of file elf.c.

Function Documentation

◆ binfmt_elf_check()

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.

It is checked before the process's old program is destroyed.

Parameters
vnodethe file
Returns
0 if it is, or -ENOEXEC

Definition at line 199 of file elf.c.

References binfmt_elf_check(), elf32_hdr::e_ident, elf32_hdr::e_machine, EI_CLASS, EI_MAG0, EI_MAG1, EI_MAG2, EI_MAG3, ELF_CLASS, ELF_MACHINE, ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, and vfs_read().

Referenced by binfmt_elf_check().

◆ binfmt_elf_load()

int binfmt_elf_load ( struct proc * proc,
const char * path,
struct vnode * vnode )

Loads an ELF program into a process.

Parameters
procthe process, whose address space is empty
pathnot used
vnodethe program's file
Returns
0, -EINVAL or -ENOMEM

Definition at line 227 of file elf.c.

References binfmt_elf_load(), and binfmt_elf_load_segments().

Referenced by binfmt_elf_load().

◆ binfmt_elf_load_segments()

int binfmt_elf_load_segments ( struct proc * proc,
struct vnode * vnode )
static