LibELF: Make ELF::Loader RefCounted

This commit is contained in:
Itamar 2020-04-17 14:40:38 +03:00 committed by Andreas Kling
parent 5c1b3ce42e
commit edaa9c06d9
Notes: sideshowbarker 2024-07-19 07:26:48 +09:00
5 changed files with 15 additions and 10 deletions

View file

@ -80,7 +80,7 @@ DisassemblyModel::DisassemblyModel(Profile& profile, ProfileNode& node)
if (!m_file->is_valid())
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());
if (!symbol.has_value())

View file

@ -30,6 +30,7 @@
#include <AK/HashTable.h>
#include <AK/MappedFile.h>
#include <AK/QuickSort.h>
#include <AK/RefPtr.h>
#include <LibCore/File.h>
#include <LibELF/Loader.h>
#include <stdio.h>
@ -185,12 +186,12 @@ OwnPtr<Profile> Profile::load_from_perfcore_file(const StringView& path)
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");
OwnPtr<ELF::Loader> kernel_elf_loader;
RefPtr<ELF::Loader> kernel_elf_loader;
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");
if (!events_value.is_array())

View file

@ -26,6 +26,7 @@
#include <AK/Demangle.h>
#include <AK/FileSystemPath.h>
#include <AK/RefPtr.h>
#include <AK/ScopeGuard.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
@ -885,7 +886,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
u32 entry_eip = 0;
MM.enter_process_paging_scope(*this);
OwnPtr<ELF::Loader> loader;
RefPtr<ELF::Loader> loader;
{
ArmedScopeGuard rollback_regions_guard([&]() {
ASSERT(Process::current == this);
@ -893,7 +894,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
m_regions = move(old_regions);
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.
// 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.
@ -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);
if (!bundle->region)
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;
}

View file

@ -391,7 +391,7 @@ public:
struct ELFBundle {
OwnPtr<Region> region;
OwnPtr<ELF::Loader> elf_loader;
RefPtr<ELF::Loader> elf_loader;
};
OwnPtr<ELFBundle> elf_bundle() const;

View file

@ -28,6 +28,7 @@
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
@ -42,9 +43,9 @@ class Region;
namespace ELF {
class Loader {
class Loader : public RefCounted<Loader> {
public:
explicit Loader(const u8*, size_t);
static NonnullRefPtr<Loader> create(const u8* data, size_t size) { return adopt(*new Loader(data, size)); }
~Loader();
bool load();
@ -67,6 +68,8 @@ public:
Optional<Image::Symbol> find_symbol(u32 address, u32* offset = nullptr) const;
private:
explicit Loader(const u8*, size_t);
bool layout();
bool perform_relocations();
void* lookup(const ELF::Image::Symbol&);