diff --git a/ELFLoader/ELFImage.cpp b/ELFLoader/ELFImage.cpp index 33d4de35c7..34e740d0dd 100644 --- a/ELFLoader/ELFImage.cpp +++ b/ELFLoader/ELFImage.cpp @@ -1,19 +1,11 @@ #include "ELFImage.h" #include -#ifdef SERENITY ELFImage::ELFImage(ByteBuffer&& buffer) : m_buffer(buffer) { m_isValid = parse(); } -#else -ELFImage::ELFImage(MappedFile&& file) - : m_file(move(file)) -{ - m_isValid = parse(); -} -#endif ELFImage::~ELFImage() { diff --git a/ELFLoader/ELFImage.h b/ELFLoader/ELFImage.h index 287bdd0abf..ce905ee4a9 100644 --- a/ELFLoader/ELFImage.h +++ b/ELFLoader/ELFImage.h @@ -1,9 +1,5 @@ #pragma once -#ifndef SERENITY -#include -#endif - #include #include #include @@ -12,11 +8,7 @@ class ELFImage { public: -#ifdef SERENITY explicit ELFImage(ByteBuffer&&); -#else - explicit ELFImage(MappedFile&&); -#endif ~ELFImage(); void dump(); bool isValid() const { return m_isValid; } diff --git a/ELFLoader/ELFLoader.cpp b/ELFLoader/ELFLoader.cpp index c8e6311758..58c9708a15 100644 --- a/ELFLoader/ELFLoader.cpp +++ b/ELFLoader/ELFLoader.cpp @@ -3,14 +3,10 @@ //#define ELFLOADER_DEBUG -#ifdef SERENITY -ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file) -#else -ELFLoader::ELFLoader(ExecSpace& execSpace, MappedFile&& file) -#endif +ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& buffer) : m_execSpace(execSpace) { - m_image = make(move(file)); + m_image = make(move(buffer)); } ELFLoader::~ELFLoader() @@ -58,9 +54,10 @@ bool ELFLoader::layout() return true; char* ptr = (char*)section.address(); if (!ptr) { - kprintf("ELFLoader: failed to allocate section '%s'\n", section.name()); - failed = true; - return false; +#ifdef ELFLOADER_DEBUG + kprintf("ELFLoader: ignoring section '%s' with null address\n", section.name()); +#endif + return true; } memcpy(ptr, section.rawData(), section.size()); m_sections.set(section.name(), move(ptr)); diff --git a/ELFLoader/ELFLoader.h b/ELFLoader/ELFLoader.h index b7a1f5161f..d6ce86652a 100644 --- a/ELFLoader/ELFLoader.h +++ b/ELFLoader/ELFLoader.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include "ExecSpace.h" @@ -9,11 +8,7 @@ class ELFLoader { public: -#ifdef SERENITY ELFLoader(ExecSpace&, ByteBuffer&&); -#else - ELFLoader(ExecSpace&, MappedFile&&); -#endif ~ELFLoader(); bool load(); diff --git a/ELFLoader/ExecSpace.cpp b/ELFLoader/ExecSpace.cpp index c68010f98c..9b18e40179 100644 --- a/ELFLoader/ExecSpace.cpp +++ b/ELFLoader/ExecSpace.cpp @@ -2,41 +2,17 @@ #include "ELFLoader.h" #include -#ifndef SERENITY -#include -#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(hookableAlloc("elf-sec", size)); - else - m_universe = static_cast(kmalloc(size)); -} - bool ExecSpace::allocate_section(LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable) { ASSERT(alloc_section_hook); diff --git a/ELFLoader/ExecSpace.h b/ELFLoader/ExecSpace.h index acc384bb95..c449589e1d 100644 --- a/ELFLoader/ExecSpace.h +++ b/ELFLoader/ExecSpace.h @@ -2,9 +2,9 @@ #include #include -#include #include #include +#include #include "types.h" class ELFLoader; @@ -26,28 +26,18 @@ public: ExecSpace(); ~ExecSpace(); - Function hookableAlloc; Function alloc_section_hook; -#ifdef SERENITY bool loadELF(ByteBuffer&&); -#else - bool loadELF(MappedFile&&); -#endif char* symbolPtr(const char* name); void addSymbol(String&& name, char* ptr, unsigned size); - void allocateUniverse(size_t); - bool allocate_section(LinearAddress, size_t, size_t alignment, bool is_readable, bool is_writable); private: - void initializeBuiltins(); - Vector m_allocated_regions; HashMap m_symbols; - char* m_universe { nullptr }; }; diff --git a/ELFLoader/Makefile b/ELFLoader/Makefile deleted file mode 100644 index 1b868acee5..0000000000 --- a/ELFLoader/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -PROGRAM = run - -AK_OBJS = \ - ../AK/String.o \ - ../AK/StringImpl.o \ - ../AK/MappedFile.o \ - ../AK/TemporaryFile.o \ - ../AK/kmalloc.o - -CSILLA_OBJS = \ - ExecSpace.o \ - ELFImage.o \ - ELFLoader.o \ - test.o - -TEST_OBJ = \ - _test.o - -TEST_OBJ_CXXFLAGS = -Os -fno-exceptions -fno-rtti -fno-asynchronous-unwind-tables - -OBJS = $(AK_OBJS) $(CSILLA_OBJS) - -CXXFLAGS = -std=c++17 -Os -W -Wall -I. -I.. -ggdb3 - -all: $(PROGRAM) $(TEST_OBJ) - -_test.o: _test.cpp - $(CXX) $(TEST_OBJ_CXXFLAGS) -c $< - -.cpp.o: - $(CXX) $(CXXFLAGS) -o $@ -c $< - -clean: - rm -f $(OBJS) $(TEST_OBJ) $(PROGRAM) - -$(PROGRAM): $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) - diff --git a/ELFLoader/_test.cpp b/ELFLoader/_test.cpp deleted file mode 100644 index 2d36eb2a6f..0000000000 --- a/ELFLoader/_test.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -extern "C" const char hello_string[] = "Hello World!"; - -extern "C" int foo() -{ - volatile int i = 3; - i = 4; - return i; -} - -extern "C" int bar() -{ - return foo(); -} - -extern "C" int baz() -{ - return bar(); -} - -extern "C" int EntryPoint() -{ - puts(hello_string); - printf("abc!\n"); - printf("def!\n"); - return 10 + baz(); -} - diff --git a/ELFLoader/test.cpp b/ELFLoader/test.cpp deleted file mode 100644 index 2e66cb172e..0000000000 --- a/ELFLoader/test.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "ExecSpace.h" -#include - -typedef int (*MainFunctionPtr)(void); - -int main(int, char**) -{ - MappedFile f("_test.o"); - if (!f.isValid()) { - fprintf(stderr, "Failed to map file :(\n"); - return 1; - } - - ExecSpace space; - space.loadELF(std::move(f)); - - auto func = reinterpret_cast(space.symbolPtr("EntryPoint")); - printf("func: %p\n", func); - - int z = func(); - printf("func() returned %d\n", z); - - return 0; -}