Bläddra i källkod

Kernel: Simplify ELF loader by removing the allocator indirections.

Andreas Kling 6 år sedan
förälder
incheckning
c5434e0cfa
2 ändrade filer med 19 tillägg och 17 borttagningar
  1. 17 14
      Kernel/ELF/ELFLoader.cpp
  2. 2 3
      Kernel/ELF/ELFLoader.h

+ 17 - 14
Kernel/ELF/ELFLoader.cpp

@@ -45,10 +45,25 @@ bool ELFLoader::layout()
         kprintf("PH: L%x %u r:%u w:%u\n", program_header.laddr().get(), program_header.size_in_memory(), program_header.is_readable(), program_header.is_writable());
         kprintf("PH: L%x %u r:%u w:%u\n", program_header.laddr().get(), program_header.size_in_memory(), program_header.is_readable(), program_header.is_writable());
 #endif
 #endif
         if (program_header.is_writable()) {
         if (program_header.is_writable()) {
-            allocate_section(program_header.laddr(), program_header.size_in_memory(), program_header.alignment(), program_header.is_readable(), program_header.is_writable());
+            alloc_section_hook(
+                program_header.laddr(),
+                program_header.size_in_memory(),
+                program_header.alignment(),
+                program_header.is_readable(),
+                program_header.is_writable(),
+                String::format("elf-alloc-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "")
+            );
             memcpy(program_header.laddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
             memcpy(program_header.laddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
         } else {
         } else {
-            map_section(program_header.laddr(), program_header.size_in_memory(), program_header.alignment(), program_header.offset(), program_header.is_readable(), program_header.is_writable());
+            map_section_hook(
+                program_header.laddr(),
+                program_header.size_in_memory(),
+                program_header.alignment(),
+                program_header.offset(),
+                program_header.is_readable(),
+                program_header.is_writable(),
+                String::format("elf-map-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "")
+            );
         }
         }
     });
     });
     return !failed;
     return !failed;
@@ -162,15 +177,3 @@ char* ELFLoader::symbol_ptr(const char* name)
     });
     });
     return found_ptr;
     return found_ptr;
 }
 }
-
-bool ELFLoader::allocate_section(LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable)
-{
-    ASSERT(alloc_section_hook);
-    return alloc_section_hook(laddr, size, alignment, is_readable, is_writable, String::format("elf-alloc-%s%s", is_readable ? "r" : "", is_writable ? "w" : ""));
-}
-
-bool ELFLoader::map_section(LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable)
-{
-    ASSERT(alloc_section_hook);
-    return map_section_hook(laddr, size, alignment, offset_in_image, is_readable, is_writable, String::format("elf-map-%s%s", is_readable ? "r" : "", is_writable ? "w" : ""));
-}

+ 2 - 3
Kernel/ELF/ELFLoader.h

@@ -4,7 +4,8 @@
 #include <AK/HashMap.h>
 #include <AK/HashMap.h>
 #include <AK/OwnPtr.h>
 #include <AK/OwnPtr.h>
 #include <AK/Vector.h>
 #include <AK/Vector.h>
-#include "ELFImage.h"
+#include <Kernel/LinearAddress.h>
+#include <Kernel/ELF/ELFImage.h>
 
 
 class ELFLoader {
 class ELFLoader {
 public:
 public:
@@ -15,8 +16,6 @@ public:
     Function<void*(LinearAddress, size_t, size_t, bool, bool, const String&)> alloc_section_hook;
     Function<void*(LinearAddress, size_t, size_t, bool, bool, const String&)> alloc_section_hook;
     Function<void*(LinearAddress, size_t, size_t, size_t, bool, bool, const String&)> map_section_hook;
     Function<void*(LinearAddress, size_t, size_t, size_t, bool, bool, const String&)> map_section_hook;
     char* symbol_ptr(const char* name);
     char* symbol_ptr(const char* name);
-    bool allocate_section(LinearAddress, size_t, size_t alignment, bool is_readable, bool is_writable);
-    bool map_section(LinearAddress, size_t, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable);
     LinearAddress entry() const { return m_image.entry(); }
     LinearAddress entry() const { return m_image.entry(); }
 
 
 private:
 private: