|
@@ -2,41 +2,17 @@
|
|
|
#include "ELFLoader.h"
|
|
|
#include <AK/Types.h>
|
|
|
|
|
|
-#ifndef SERENITY
|
|
|
-#include <AK/TemporaryFile.h>
|
|
|
-#endif
|
|
|
-
|
|
|
//#define EXECSPACE_DEBUG
|
|
|
|
|
|
ExecSpace::ExecSpace()
|
|
|
{
|
|
|
- initializeBuiltins();
|
|
|
}
|
|
|
|
|
|
ExecSpace::~ExecSpace()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-#ifdef SERENITY
|
|
|
-int puts(const char* str)
|
|
|
-{
|
|
|
- kprintf("%s\n", str);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-void ExecSpace::initializeBuiltins()
|
|
|
-{
|
|
|
-#ifndef SERENITY
|
|
|
- m_symbols.set("puts", { (char*)puts, 0 });
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
-#ifdef SERENITY
|
|
|
bool ExecSpace::loadELF(ByteBuffer&& file)
|
|
|
-#else
|
|
|
-bool ExecSpace::loadELF(MappedFile&& file)
|
|
|
-#endif
|
|
|
{
|
|
|
ELFLoader loader(*this, move(file));
|
|
|
if (!loader.load())
|
|
@@ -53,37 +29,6 @@ bool ExecSpace::loadELF(MappedFile&& file)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-#ifdef EXECSPACE_DEBUG
|
|
|
-static void disassemble(const char* data, size_t length)
|
|
|
-{
|
|
|
- if (!length)
|
|
|
- return;
|
|
|
-
|
|
|
-#ifdef SERENITY
|
|
|
- for (unsigned i = 0; i < length; ++i) {
|
|
|
- kprintf("%b ", (unsigned char)data[i]);
|
|
|
- }
|
|
|
- kprintf("\n");
|
|
|
-#else
|
|
|
- TemporaryFile temp;
|
|
|
- if (!temp.isValid()) {
|
|
|
- fprintf(stderr, "Unable to create temp file for disassembly.\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- fprintf(temp.stream(), "db ");
|
|
|
- for (unsigned i = 0; i < length; ++i) {
|
|
|
- fprintf(temp.stream(), "0x%02x, ", (unsigned char)data[i]);
|
|
|
- }
|
|
|
- fprintf(temp.stream(), "\n");
|
|
|
- temp.sync();
|
|
|
-
|
|
|
- char cmdbuf[128];
|
|
|
- ksprintf(cmdbuf, "nasm -f bin -o /dev/stdout %s | ndisasm -b32 -", temp.fileName().characters());
|
|
|
- system(cmdbuf);
|
|
|
-#endif
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
char* ExecSpace::symbolPtr(const char* name)
|
|
|
{
|
|
|
if (auto it = m_symbols.find(name); it != m_symbols.end()) {
|
|
@@ -97,15 +42,6 @@ char* ExecSpace::symbolPtr(const char* name)
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
-void ExecSpace::allocateUniverse(size_t size)
|
|
|
-{
|
|
|
- ASSERT(!m_universe);
|
|
|
- if (hookableAlloc)
|
|
|
- m_universe = static_cast<char*>(hookableAlloc("elf-sec", size));
|
|
|
- else
|
|
|
- m_universe = static_cast<char*>(kmalloc(size));
|
|
|
-}
|
|
|
-
|
|
|
bool ExecSpace::allocate_section(LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable)
|
|
|
{
|
|
|
ASSERT(alloc_section_hook);
|