|
AquilaOS documentation
How it works, and its code
|
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. | |
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.
| #define ELF_CLASS ELFCLASS64 |
Definition at line 31 of file elf.c.
Referenced by binfmt_elf_check(), and binfmt_elf_load_segments().
| typedef struct elf64_phdr elf_phdr |
| 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.
| vnode | the file |
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().
Loads an ELF program into a process.
| proc | the process, whose address space is empty |
| path | not used |
| vnode | the program's file |
Definition at line 227 of file elf.c.
References binfmt_elf_load(), and binfmt_elf_load_segments().
Referenced by binfmt_elf_load().
Maps the loadable segments of an ELF file into a process, and sets its entry point and the start of its heap.
Returns 0, -EINVAL for a file whose headers aren't valid, or -ENOMEM. On failure, the mappings added so far are left for the caller to release.
Definition at line 42 of file elf.c.
References vm_entry::base, binfmt_elf_load_segments(), elf64_hdr::e_entry, elf64_hdr::e_ident, elf64_hdr::e_machine, elf64_hdr::e_phentsize, elf64_hdr::e_phnum, elf64_hdr::e_phoff, EI_CLASS, ELF_CLASS, ELF_MACHINE, proc::entry, vm_entry::flags, proc::heap, proc::heap_start, kfree(), memset(), vm_entry::off, elf64_phdr::p_filesz, elf64_phdr::p_flags, elf64_phdr::p_memsz, elf64_phdr::p_offset, elf64_phdr::p_type, elf64_phdr::p_vaddr, PAGE_ALIGN, PAGE_MASK, PAGE_ROUND, PF_R, PF_W, PF_X, PT_LOAD, vm_entry::qnode, vm_entry::size, USER_STACK_BASE, vfs_read(), VM_COPY, vm_space::vm_entries, vm_entry_new(), vm_entry::vm_object, vm_object_incref(), vm_object_vnode(), proc::vm_space, VM_UR, VM_UW, and VM_UX.
Referenced by binfmt_elf_load(), and binfmt_elf_load_segments().