23#error "the architecture's config.h has no ELF_MACHINE"
27#define ELF_CLASS ELFCLASS32
31#define ELF_CLASS ELFCLASS64
62 for (
int i = 0; i < hdr.
e_phnum; ++i) {
65 if (
vfs_read(
vnode, offset,
sizeof(phdr), &phdr) !=
sizeof(phdr))
79 base + memsz < base ||
129 if (
base + memsz > proc_heap)
130 proc_heap =
base + memsz;
143 if (!split)
goto e_nomem;
145 split->
base = bss_init_end;
164 memset((
void *) bss, 0, bss_init_end-bss);
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.
struct elf64_phdr elf_phdr
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 i...
struct vm_object * vm_object_vnode(struct vnode *vnode)
Gets a vnode's vm object, making it the first time.
void kfree(void *)
Frees an object that kmalloc() gave.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
uint8_t e_ident[EI_NIDENT]
An ELF32 program header: a segment to load.
uint8_t e_ident[EI_NIDENT]
An ELF64 program header: a segment to load.
struct vm_space vm_space
its address space
uintptr_t heap_start
where its heap starts, and where it ends now (sbrk())
uintptr_t entry
its program's entry point
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
uint32_t flags
its permissions and flags (VM_*)
size_t off
where the mapping starts in its object
vaddr_t base
where the mapping starts in its address space
struct vm_object * vm_object
its object: what its other pages come from (a file)
struct qnode * qnode
its node in its address space's list of mappings
An address space: its mappings, and its page tables.
struct queue vm_entries
its mappings (map entries), in address order
A file in memory (a vnode): what its inode says, and the kernel's own state.
#define VM_COPY
to be copied before it's written to
struct vm_entry * vm_entry_new(void)
Makes a new, empty map entry.
#define VM_UX
user execute
void vm_object_incref(struct vm_object *vm_object)
Adds a reference to a vm object: one more mapping of it.