vbos/kernel/proc/elf.h
Michael Shaw cd916f624b proc: enter into userspace
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-19 19:25:38 -04:00

59 lines
2 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _ELF_H_
#define _ELF_H_
#include <kernel/common.h>
#define ET_NONE 0 /* No file type */
#define ET_EXEC 2 /* Executable file */
#define PT_NULL 0 /* Program header table entry unused */
#define PT_LOAD 1 /* Loadable program segment */
#define PT_DYNAMIC 2 /* Dynamic linking information */
#define PT_INTERP 3 /* Program interpreter */
#define PF_X (1 << 0) /* Segment is executable */
#define PF_W (1 << 1) /* Segment is writable */
#define PF_R (1 << 2) /* Segment is readable */
#define EM_X86_64 62
#define EV_CURRENT 1
typedef u16 Elf64_Half;
typedef u32 Elf64_Word;
typedef u64 Elf64_Xword;
typedef u64 Elf64_Addr;
typedef u64 Elf64_Off;
struct ehdr {
u8 e_ident[16]; /* Magic number and other info */
Elf64_Half e_type; /* Object file type */
Elf64_Half e_machine; /* Architecture */
Elf64_Word e_version; /* Object file version */
Elf64_Addr e_entry; /* Entry point virtual address */
Elf64_Off e_phoff; /* Program header table file offset */
Elf64_Off e_shoff; /* Section header table file offset */
Elf64_Word e_flags; /* Processor-specific flags */
Elf64_Half e_ehsize; /* ELF header size in bytes */
Elf64_Half e_phentsize; /* Program header table entry size */
Elf64_Half e_phnum; /* Program header table entry count */
Elf64_Half e_shentsize; /* Section header table entry size */
Elf64_Half e_shnum; /* Section header table entry count */
Elf64_Half e_shstrndx; /* Section header string table index */
} PACKED;
struct phdr {
Elf64_Word p_type; /* Segment type */
Elf64_Word p_flags; /* Segment flags */
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Xword p_filesz; /* Segment size in file */
Elf64_Xword p_memsz; /* Segment size in memory */
Elf64_Xword p_align; /* Segment alignment */
} PACKED;
int elf_get_headers(const char *file, struct ehdr **out_ehdr, struct phdr **out_phdrs, uaddr_t *entry);
#endif /* _ELF_H_ */