mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +00:00
LibELF: Make ELF::Loader RefCounted
This commit is contained in:
parent
5c1b3ce42e
commit
edaa9c06d9
5 changed files with 15 additions and 10 deletions
|
@ -80,7 +80,7 @@ DisassemblyModel::DisassemblyModel(Profile& profile, ProfileNode& node)
|
||||||
if (!m_file->is_valid())
|
if (!m_file->is_valid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto elf_loader = make<ELF::Loader>((const u8*)m_file->data(), m_file->size());
|
auto elf_loader = ELF::Loader::create((const u8*)m_file->data(), m_file->size());
|
||||||
|
|
||||||
auto symbol = elf_loader->find_symbol(node.address());
|
auto symbol = elf_loader->find_symbol(node.address());
|
||||||
if (!symbol.has_value())
|
if (!symbol.has_value())
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/MappedFile.h>
|
#include <AK/MappedFile.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
|
#include <AK/RefPtr.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibELF/Loader.h>
|
#include <LibELF/Loader.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -185,12 +186,12 @@ OwnPtr<Profile> Profile::load_from_perfcore_file(const StringView& path)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto elf_loader = make<ELF::Loader>(static_cast<const u8*>(elf_file.data()), elf_file.size());
|
auto elf_loader = ELF::Loader::create(static_cast<const u8*>(elf_file.data()), elf_file.size());
|
||||||
|
|
||||||
MappedFile kernel_elf_file("/boot/kernel");
|
MappedFile kernel_elf_file("/boot/kernel");
|
||||||
OwnPtr<ELF::Loader> kernel_elf_loader;
|
RefPtr<ELF::Loader> kernel_elf_loader;
|
||||||
if (kernel_elf_file.is_valid())
|
if (kernel_elf_file.is_valid())
|
||||||
kernel_elf_loader = make<ELF::Loader>(static_cast<const u8*>(kernel_elf_file.data()), kernel_elf_file.size());
|
kernel_elf_loader = ELF::Loader::create(static_cast<const u8*>(kernel_elf_file.data()), kernel_elf_file.size());
|
||||||
|
|
||||||
auto events_value = object.get("events");
|
auto events_value = object.get("events");
|
||||||
if (!events_value.is_array())
|
if (!events_value.is_array())
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <AK/Demangle.h>
|
#include <AK/Demangle.h>
|
||||||
#include <AK/FileSystemPath.h>
|
#include <AK/FileSystemPath.h>
|
||||||
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -885,7 +886,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
|
||||||
u32 entry_eip = 0;
|
u32 entry_eip = 0;
|
||||||
|
|
||||||
MM.enter_process_paging_scope(*this);
|
MM.enter_process_paging_scope(*this);
|
||||||
OwnPtr<ELF::Loader> loader;
|
RefPtr<ELF::Loader> loader;
|
||||||
{
|
{
|
||||||
ArmedScopeGuard rollback_regions_guard([&]() {
|
ArmedScopeGuard rollback_regions_guard([&]() {
|
||||||
ASSERT(Process::current == this);
|
ASSERT(Process::current == this);
|
||||||
|
@ -893,7 +894,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
|
||||||
m_regions = move(old_regions);
|
m_regions = move(old_regions);
|
||||||
MM.enter_process_paging_scope(*this);
|
MM.enter_process_paging_scope(*this);
|
||||||
});
|
});
|
||||||
loader = make<ELF::Loader>(region->vaddr().as_ptr(), loader_metadata.size);
|
loader = ELF::Loader::create(region->vaddr().as_ptr(), loader_metadata.size);
|
||||||
// Load the correct executable -- either interp or main program.
|
// Load the correct executable -- either interp or main program.
|
||||||
// FIXME: Once we actually load both interp and main, we'll need to be more clever about this.
|
// FIXME: Once we actually load both interp and main, we'll need to be more clever about this.
|
||||||
// In that case, both will be ET_DYN objects, so they'll both be completely relocatable.
|
// In that case, both will be ET_DYN objects, so they'll both be completely relocatable.
|
||||||
|
@ -4888,7 +4889,7 @@ OwnPtr<Process::ELFBundle> Process::elf_bundle() const
|
||||||
bundle->region = MM.allocate_kernel_region_with_vmobject(const_cast<SharedInodeVMObject&>(vmobject), vmobject.size(), "ELF bundle", Region::Access::Read);
|
bundle->region = MM.allocate_kernel_region_with_vmobject(const_cast<SharedInodeVMObject&>(vmobject), vmobject.size(), "ELF bundle", Region::Access::Read);
|
||||||
if (!bundle->region)
|
if (!bundle->region)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
bundle->elf_loader = make<ELF::Loader>(bundle->region->vaddr().as_ptr(), bundle->region->size());
|
bundle->elf_loader = ELF::Loader::create(bundle->region->vaddr().as_ptr(), bundle->region->size());
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -391,7 +391,7 @@ public:
|
||||||
|
|
||||||
struct ELFBundle {
|
struct ELFBundle {
|
||||||
OwnPtr<Region> region;
|
OwnPtr<Region> region;
|
||||||
OwnPtr<ELF::Loader> elf_loader;
|
RefPtr<ELF::Loader> elf_loader;
|
||||||
};
|
};
|
||||||
OwnPtr<ELFBundle> elf_bundle() const;
|
OwnPtr<ELFBundle> elf_bundle() const;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
@ -42,9 +43,9 @@ class Region;
|
||||||
|
|
||||||
namespace ELF {
|
namespace ELF {
|
||||||
|
|
||||||
class Loader {
|
class Loader : public RefCounted<Loader> {
|
||||||
public:
|
public:
|
||||||
explicit Loader(const u8*, size_t);
|
static NonnullRefPtr<Loader> create(const u8* data, size_t size) { return adopt(*new Loader(data, size)); }
|
||||||
~Loader();
|
~Loader();
|
||||||
|
|
||||||
bool load();
|
bool load();
|
||||||
|
@ -67,6 +68,8 @@ public:
|
||||||
Optional<Image::Symbol> find_symbol(u32 address, u32* offset = nullptr) const;
|
Optional<Image::Symbol> find_symbol(u32 address, u32* offset = nullptr) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit Loader(const u8*, size_t);
|
||||||
|
|
||||||
bool layout();
|
bool layout();
|
||||||
bool perform_relocations();
|
bool perform_relocations();
|
||||||
void* lookup(const ELF::Image::Symbol&);
|
void* lookup(const ELF::Image::Symbol&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue