serenity/AK/ELF/ELFLoader.h
Andreas Kling f83263a72b Kernel: Use a raw VM region for sorting ELF symbols instead of a Vector.
This avoids putting pressure on kmalloc() during backtrace symbolication.
Since we dump backtrace for every process that exits, this is actually a
decent performance improvement for things like GCC that chain a lot of
processes together.
2019-06-27 10:49:49 +02:00

61 lines
1.4 KiB
C++

#pragma once
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/Vector.h>
#include <AK/ELF/ELFImage.h>
#ifdef KERNEL
#include <Kernel/VirtualAddress.h>
class Region;
#endif
class ELFLoader {
public:
explicit ELFLoader(const byte*);
~ELFLoader();
bool load();
#if defined(KERNEL)
Function<void*(VirtualAddress, size_t, size_t, bool, bool, const String&)> alloc_section_hook;
Function<void*(VirtualAddress, size_t, size_t, size_t, bool r, bool w, bool x, const String&)> map_section_hook;
VirtualAddress entry() const { return m_image.entry(); }
#endif
char* symbol_ptr(const char* name);
bool has_symbols() const { return m_image.symbol_count(); }
String symbolicate(dword address) const;
private:
bool layout();
bool perform_relocations();
void* lookup(const ELFImage::Symbol&);
char* area_for_section(const ELFImage::Section&);
char* area_for_section_name(const char*);
struct PtrAndSize {
PtrAndSize() {}
PtrAndSize(char* p, unsigned s)
: ptr(p)
, size(s)
{
}
char* ptr { nullptr };
unsigned size { 0 };
};
ELFImage m_image;
struct SortedSymbol {
dword address;
const char* name;
};
#ifdef KERNEL
mutable RefPtr<Region> m_sorted_symbols_region;
#else
mutable Vector<SortedSymbol> m_sorted_symbols;
#endif
};