ELFLoader: show permissions of loadable segment
This commit is contained in:
parent
3c6c94adda
commit
c6b044acab
@ -8,12 +8,22 @@
|
|||||||
#include "std/string.h"
|
#include "std/string.h"
|
||||||
#include "sys/elf/ELF.h"
|
#include "sys/elf/ELF.h"
|
||||||
|
|
||||||
|
static const char* format_permissions(uint32_t flags)
|
||||||
|
{
|
||||||
|
static char perms[4];
|
||||||
|
perms[0] = (flags & 4) > 0 ? 'r' : '-';
|
||||||
|
perms[1] = (flags & 2) > 0 ? 'w' : '-';
|
||||||
|
perms[2] = (flags & 1) > 0 ? 'x' : '-';
|
||||||
|
perms[3] = 0;
|
||||||
|
return perms;
|
||||||
|
}
|
||||||
|
|
||||||
void* ELFLoader::load_elf_from_initrd(const char* filename)
|
void* ELFLoader::load_elf_from_initrd(const char* filename)
|
||||||
{
|
{
|
||||||
InitRD::File elf_file = InitRD::open(filename);
|
InitRD::File elf_file = InitRD::open(filename);
|
||||||
if (!elf_file.addr)
|
if (!elf_file.addr)
|
||||||
{
|
{
|
||||||
kwarnln("failed to open file %s for loading", filename);
|
kwarnln("Failed to open file %s for loading", filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +55,7 @@ void* ELFLoader::load_elf_from_address(uintptr_t addr)
|
|||||||
}
|
}
|
||||||
if (elf_ehdr->e_machine != EM_MACH)
|
if (elf_ehdr->e_machine != EM_MACH)
|
||||||
{
|
{
|
||||||
kwarnln("unsupported target machine");
|
kwarnln("Unsupported target machine");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (elf_ehdr->e_phnum == 0)
|
if (elf_ehdr->e_phnum == 0)
|
||||||
@ -60,11 +70,11 @@ void* ELFLoader::load_elf_from_address(uintptr_t addr)
|
|||||||
{
|
{
|
||||||
if (phdr->p_type == PT_LOAD)
|
if (phdr->p_type == PT_LOAD)
|
||||||
{
|
{
|
||||||
kdbgln("loading loadable segment at vaddr %lx, filesz %ld, memsz %ld", phdr->p_vaddr, phdr->p_filesz,
|
kdbgln("Loading loadable segment at address %lx, file size %ld, mem size %ld, permissions %s",
|
||||||
phdr->p_memsz);
|
phdr->p_vaddr, phdr->p_filesz, phdr->p_memsz, format_permissions(phdr->p_flags));
|
||||||
if (!phdr->p_vaddr)
|
if (!phdr->p_vaddr)
|
||||||
{
|
{
|
||||||
kerrorln("vaddr is NULL, this is invalid :(");
|
kerrorln("Address is NULL, this is invalid :(");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int pages = Utilities::get_blocks_from_size(0x1000, phdr->p_memsz);
|
int pages = Utilities::get_blocks_from_size(0x1000, phdr->p_memsz);
|
||||||
|
Loading…
Reference in New Issue
Block a user