13using namespace MaxOS::processes;
14using namespace MaxOS::memory;
24: m_elf_header_address(elf_header_address)
43 load_program_headers();
66 if (index >=
header()->program_header_count)
71 return &program_headers[index];
84 if (index >=
header()->section_header_count)
89 return §ion_headers[index];
103 for (
size_t i = 0; i < 4; i++)
108 if (
header()->identification[(
int) ELFIdentification::Class] != (
int) ELFClass::Bits64)
112 if (
header()->identification[(
int) ELFIdentification::Data] != (
int) ELFData::LittleEndian)
116 if (
header()->identification[(
int) ELFIdentification::Version] != (
int) ELFVersion::Current)
124 if (
header()->type != (
int) ELFType::Executable)
128 if (
header()->machine != (
int) ELFMachine::x86_64)
139void ELF64::load_program_headers()
const {
147 if (program_header->
type != (
int) ELFProgramType::Load)
152 ASSERT(address !=
nullptr,
"Failed to allocate memory for program header\n");
159 memset((
void*) ((uintptr_t) address + program_header->
file_size), 0, zero_size);
188 if (type & ELFExecute)
189 flags &= ~NO_EXECUTE;
static MemoryManager * s_current_memory_manager
The memory manager for the current process.
VirtualMemoryManager * vmm()
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.
void * allocate(size_t size, size_t flags)
Allocate a new chunk of virtual memory.
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.
void load()
Loads the elf program into memory if a valid 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.
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...
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
void * memcpy(void *destination, const void *source, uint64_t num)
Copies a block of memory from one location to another.
void * memset(void *ptr, uint32_t value, uint64_t num)
Fills a block of memory with a specified value.
@ 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.