From c6b044acab3101b764a41257c7364581844e55c2 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 2 Oct 2022 17:10:24 +0200 Subject: [PATCH] ELFLoader: show permissions of loadable segment --- kernel/src/sys/elf/ELFLoader.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/src/sys/elf/ELFLoader.cpp b/kernel/src/sys/elf/ELFLoader.cpp index bdb082f4..c7d72f9d 100644 --- a/kernel/src/sys/elf/ELFLoader.cpp +++ b/kernel/src/sys/elf/ELFLoader.cpp @@ -8,12 +8,22 @@ #include "std/string.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) { InitRD::File elf_file = InitRD::open(filename); if (!elf_file.addr) { - kwarnln("failed to open file %s for loading", filename); + kwarnln("Failed to open file %s for loading", filename); return 0; } @@ -45,7 +55,7 @@ void* ELFLoader::load_elf_from_address(uintptr_t addr) } if (elf_ehdr->e_machine != EM_MACH) { - kwarnln("unsupported target machine"); + kwarnln("Unsupported target machine"); return 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) { - kdbgln("loading loadable segment at vaddr %lx, filesz %ld, memsz %ld", phdr->p_vaddr, phdr->p_filesz, - phdr->p_memsz); + kdbgln("Loading loadable segment at address %lx, file size %ld, mem size %ld, permissions %s", + phdr->p_vaddr, phdr->p_filesz, phdr->p_memsz, format_permissions(phdr->p_flags)); if (!phdr->p_vaddr) { - kerrorln("vaddr is NULL, this is invalid :("); + kerrorln("Address is NULL, this is invalid :("); return 0; } int pages = Utilities::get_blocks_from_size(0x1000, phdr->p_memsz);