mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:37:35 +00:00
ELF: Make code a little more buildable on other platforms
Patch from Anonymous.
This commit is contained in:
parent
0b59c0d0dc
commit
9c3c117f05
3 changed files with 7 additions and 2 deletions
|
@ -98,7 +98,7 @@ bool ELFImage::parse()
|
||||||
{
|
{
|
||||||
// We only support i386.
|
// We only support i386.
|
||||||
if (header().e_machine != 3) {
|
if (header().e_machine != 3) {
|
||||||
kprintf("ELFImage::parse(): e_machine=%u not supported!\n");
|
kprintf("ELFImage::parse(): e_machine=%u not supported!\n", header().e_machine);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <AK/ELF/exec_elf.h>
|
#include <AK/ELF/exec_elf.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
#include <Kernel/VM/VirtualAddress.h>
|
||||||
|
|
||||||
class ELFImage {
|
class ELFImage {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -36,8 +36,10 @@ bool ELFLoader::layout()
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
m_image.for_each_program_header([&](const ELFImage::ProgramHeader& program_header) {
|
m_image.for_each_program_header([&](const ELFImage::ProgramHeader& program_header) {
|
||||||
if (program_header.type() == PT_TLS) {
|
if (program_header.type() == PT_TLS) {
|
||||||
|
#ifdef KERNEL
|
||||||
auto* tls_image = tls_section_hook(program_header.size_in_memory(), program_header.alignment());
|
auto* tls_image = tls_section_hook(program_header.size_in_memory(), program_header.alignment());
|
||||||
memcpy(tls_image, program_header.raw_data(), program_header.size_in_image());
|
memcpy(tls_image, program_header.raw_data(), program_header.size_in_image());
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (program_header.type() != PT_LOAD)
|
if (program_header.type() != PT_LOAD)
|
||||||
|
@ -45,6 +47,7 @@ bool ELFLoader::layout()
|
||||||
#ifdef ELFLOADER_DEBUG
|
#ifdef ELFLOADER_DEBUG
|
||||||
kprintf("PH: V%p %u r:%u w:%u\n", program_header.vaddr().get(), program_header.size_in_memory(), program_header.is_readable(), program_header.is_writable());
|
kprintf("PH: V%p %u r:%u w:%u\n", program_header.vaddr().get(), program_header.size_in_memory(), program_header.is_readable(), program_header.is_writable());
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef KERNEL
|
||||||
if (program_header.is_writable()) {
|
if (program_header.is_writable()) {
|
||||||
alloc_section_hook(
|
alloc_section_hook(
|
||||||
program_header.vaddr(),
|
program_header.vaddr(),
|
||||||
|
@ -65,6 +68,7 @@ bool ELFLoader::layout()
|
||||||
program_header.is_executable(),
|
program_header.is_executable(),
|
||||||
String::format("elf-map-%s%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : ""));
|
String::format("elf-map-%s%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : ""));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
return !failed;
|
return !failed;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +82,7 @@ char* ELFLoader::symbol_ptr(const char* name)
|
||||||
if (strcmp(symbol.name(), name))
|
if (strcmp(symbol.name(), name))
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
if (m_image.is_executable())
|
if (m_image.is_executable())
|
||||||
found_ptr = (char*)symbol.value();
|
found_ptr = (char*)(size_t)symbol.value();
|
||||||
else
|
else
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue