9#include <libkpi/syscalls.h>
15using namespace MaxOS::processes;
16using namespace MaxOS::memory;
17using namespace MaxOS::common;
27: m_elf_header_address(elf_header_address)
44 ASSERT(
is_valid(),
"Invaild ELF file loaded\n");
45 load_program_headers(vmm);
68 if (index >=
header()->program_header_count)
73 return &program_headers[index];
86 if (index >=
header()->section_header_count)
91 return §ion_headers[index];
105 for (
size_t i = 0; i < 4; i++)
110 if (
header()->identification[(
int) ELFIdentification::Class] != (
int) ELFClass::Bits64)
114 if (
header()->identification[(
int) ELFIdentification::Data] != (
int) ELFData::LittleEndian)
118 if (
header()->identification[(
int) ELFIdentification::Version] != (
int) ELFVersion::Current)
126 if (
header()->type != (
int) ELFType::Executable)
130 if (
header()->machine != (
int) ELFMachine::x86_64)
150 if (program_header->
type != (
int) ELFProgramType::Load)
155 ASSERT(address !=
nullptr,
"Failed to allocate memory for program header\n");
158 memcpy(address, (
void*) (m_elf_header_address + program_header->
offset), program_header->
file_size);
162 memset((
void*) ((uintptr_t) address + program_header->
file_size), 0, zero_size);
191 if (type & ELFExecute)
192 flags &= ~NO_EXECUTE;
void change_page_flags(virtual_address_t *virtual_address, size_t flags, uint64_t *pml4_root)
Changes the flags of a page.
static PhysicalMemoryManager * s_current_manager
The current physical memory manager in use.
Manages the virtual memory of the system and provides functions to allocate and free memory in the vi...
void * allocate(size_t size, size_t flags)
Allocate a new chunk of virtual memory.
uint64_t * pml4_root_address()
Get the virtual address of the PML4 root.
elf_64_header_t * header() const
Gets the header of the elf file.
static uint64_t to_vmm_flags(uint32_t type)
Converts elf flags to vmm flags.
ELF64(uintptr_t elf_header_address)
Constructor for the ELF64 class.
~ELF64()
Destructor for the ELF64 class.
elf_64_program_header_t * get_program_header(size_t index) const
Gets a program header from the elf file.
elf_64_section_header_t * get_section_header(size_t index) const
Gets a section header from the elf file.
bool is_valid() const
Checks if the elf file is valid for MaxOS runtime.
void load_into_memory(memory::VirtualMemoryManager *vmm) const
Loads the elf program into memory if a valid elf file.
Defines structures and enums for handling ELF (Executable and Linkable Format) files in MaxOS.
constexpr char ELF_MAGIC[4]
The expected ELF magic number at the start of the file.
Defines a Logger class for logging messages with different severity levels to multiple output streams...
@ PRESENT
The page is present in memory.
@ WRITE
Memory in this page is writable.
@ USER
This page is accessible from user mode.
@ NO_EXECUTE
Dont let the CPU execute code on this page.