LibELF: We use BAN::Vector<uint8_t> as elf storage

This is made possible by the dynamic kmalloc
This commit is contained in:
Bananymous 2023-06-18 23:29:23 +03:00
parent 5e123031aa
commit 10544db52e
2 changed files with 16 additions and 25 deletions

View File

@ -23,21 +23,12 @@ namespace LibELF
#ifdef __is_kernel
BAN::ErrorOr<BAN::UniqPtr<ELF>> ELF::load_from_file(BAN::RefPtr<Inode> inode)
{
PageTable::current().lock();
size_t page_count = BAN::Math::div_round_up<size_t>(inode->size(), PAGE_SIZE);
vaddr_t vaddr = PageTable::current().get_free_contiguous_pages(page_count, (vaddr_t)g_kernel_end);
auto virtual_range = BAN::UniqPtr<VirtualRange>::adopt(
VirtualRange::create(
PageTable::current(),
vaddr, page_count * PAGE_SIZE,
PageTable::Flags::ReadWrite | PageTable::Flags::Present
)
);
PageTable::current().unlock();
BAN::Vector<uint8_t> buffer;
TRY(buffer.resize(inode->size()));
TRY(inode->read(0, (void*)vaddr, inode->size()));
TRY(inode->read(0, buffer.data(), inode->size()));
ELF* elf_ptr = new ELF(BAN::move(virtual_range), inode->size());
ELF* elf_ptr = new ELF(BAN::move(buffer));
if (elf_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM);

View File

@ -57,16 +57,16 @@ namespace LibELF
bool is_x86_64() const;
private:
#ifdef __is_kernel
ELF(BAN::UniqPtr<Kernel::VirtualRange>&& storage, size_t size)
: m_storage(BAN::move(storage))
, m_data((const uint8_t*)m_storage->vaddr(), size)
{}
#else
//#ifdef __is_kernel
// ELF(BAN::UniqPtr<Kernel::VirtualRange>&& storage, size_t size)
// : m_storage(BAN::move(storage))
// , m_data((const uint8_t*)m_storage->vaddr(), size)
// {}
//#else
ELF(BAN::Vector<uint8_t>&& data)
: m_data(BAN::move(data))
{}
#endif
//#endif
BAN::ErrorOr<void> load();
bool parse_elf64_file_header(const Elf64FileHeader&);
@ -78,12 +78,12 @@ namespace LibELF
bool parse_elf32_section_header(const Elf32SectionHeader&);
private:
#ifdef __is_kernel
BAN::UniqPtr<Kernel::VirtualRange> m_storage;
BAN::Span<const uint8_t> m_data;
#else
//#ifdef __is_kernel
// BAN::UniqPtr<Kernel::VirtualRange> m_storage;
// BAN::Span<const uint8_t> m_data;
//#else
const BAN::Vector<uint8_t> m_data;
#endif
//#endif
};
}