mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
Everywhere: Replace ElfW(type)
macro usage with Elf_type
This works around a `clang-format-17` bug which caused certain usages to be misformatted and fail to compile. Fixes #8315
This commit is contained in:
parent
2151e6c8b4
commit
45d81dceed
Notes:
sideshowbarker
2024-07-17 00:25:35 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/45d81dceed Pull-request: https://github.com/SerenityOS/serenity/pull/22106 Issue: https://github.com/SerenityOS/serenity/issues/8315
20 changed files with 129 additions and 127 deletions
|
@ -99,11 +99,11 @@ extern "C" [[noreturn]] void init()
|
|||
|
||||
u8* kernel_image = (u8*)(FlatPtr)kernel_module->start;
|
||||
// copy the ELF header and program headers because we might end up overwriting them
|
||||
ElfW(Ehdr) kernel_elf_header = *(ElfW(Ehdr)*)kernel_image;
|
||||
ElfW(Phdr) kernel_program_headers[16];
|
||||
Elf_Ehdr kernel_elf_header = *(Elf_Ehdr*)kernel_image;
|
||||
Elf_Phdr kernel_program_headers[16];
|
||||
if (kernel_elf_header.e_phnum > array_size(kernel_program_headers))
|
||||
halt();
|
||||
__builtin_memcpy(kernel_program_headers, kernel_image + kernel_elf_header.e_phoff, sizeof(ElfW(Phdr)) * kernel_elf_header.e_phnum);
|
||||
__builtin_memcpy(kernel_program_headers, kernel_image + kernel_elf_header.e_phoff, sizeof(Elf_Phdr) * kernel_elf_header.e_phnum);
|
||||
|
||||
FlatPtr kernel_physical_base = 0x200000;
|
||||
FlatPtr default_kernel_load_base = KERNEL_MAPPING_BASE + 0x200000;
|
||||
|
|
|
@ -205,7 +205,7 @@ static ErrorOr<RequiredLoadRange> get_required_load_range(OpenFileDescription& p
|
|||
return range;
|
||||
}
|
||||
|
||||
static ErrorOr<FlatPtr> get_load_offset(const ElfW(Ehdr) & main_program_header, OpenFileDescription& main_program_description, OpenFileDescription* interpreter_description)
|
||||
static ErrorOr<FlatPtr> get_load_offset(Elf_Ehdr const& main_program_header, OpenFileDescription& main_program_description, OpenFileDescription* interpreter_description)
|
||||
{
|
||||
constexpr FlatPtr load_range_start = 0x08000000;
|
||||
constexpr FlatPtr load_range_size = 65536 * PAGE_SIZE; // 2**16 * PAGE_SIZE = 256MB
|
||||
|
@ -421,7 +421,7 @@ static ErrorOr<LoadResult> load_elf_object(Memory::AddressSpace& new_space, Open
|
|||
|
||||
ErrorOr<LoadResult>
|
||||
Process::load(Memory::AddressSpace& new_space, NonnullRefPtr<OpenFileDescription> main_program_description,
|
||||
RefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header, Optional<size_t> minimum_stack_size)
|
||||
RefPtr<OpenFileDescription> interpreter_description, Elf_Ehdr const& main_program_header, Optional<size_t> minimum_stack_size)
|
||||
{
|
||||
auto load_offset = TRY(get_load_offset(main_program_header, main_program_description, interpreter_description));
|
||||
|
||||
|
@ -463,7 +463,7 @@ void Process::clear_signal_handlers_for_exec()
|
|||
}
|
||||
|
||||
ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment,
|
||||
RefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header, Optional<size_t> minimum_stack_size)
|
||||
RefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, Elf_Ehdr const& main_program_header, Optional<size_t> minimum_stack_size)
|
||||
{
|
||||
VERIFY(is_user_process());
|
||||
VERIFY(!Processor::in_critical());
|
||||
|
@ -800,7 +800,7 @@ static ErrorOr<Vector<NonnullOwnPtr<KString>>> find_shebang_interpreter_for_exec
|
|||
return ENOEXEC;
|
||||
}
|
||||
|
||||
ErrorOr<RefPtr<OpenFileDescription>> Process::find_elf_interpreter_for_executable(StringView path, ElfW(Ehdr) const& main_executable_header, size_t main_executable_header_size, size_t file_size, Optional<size_t>& minimum_stack_size)
|
||||
ErrorOr<RefPtr<OpenFileDescription>> Process::find_elf_interpreter_for_executable(StringView path, Elf_Ehdr const& main_executable_header, size_t main_executable_header_size, size_t file_size, Optional<size_t>& minimum_stack_size)
|
||||
{
|
||||
// Not using ErrorOr here because we'll want to do the same thing in userspace in the RTLD
|
||||
StringBuilder interpreter_path_builder;
|
||||
|
@ -822,17 +822,17 @@ ErrorOr<RefPtr<OpenFileDescription>> Process::find_elf_interpreter_for_executabl
|
|||
|
||||
// Validate the program interpreter as a valid elf binary.
|
||||
// If your program interpreter is a #! file or something, it's time to stop playing games :)
|
||||
if (interp_metadata.size < (int)sizeof(ElfW(Ehdr)))
|
||||
if (interp_metadata.size < (int)sizeof(Elf_Ehdr))
|
||||
return ENOEXEC;
|
||||
|
||||
char first_page[PAGE_SIZE] = {};
|
||||
auto first_page_buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&first_page);
|
||||
auto nread = TRY(interpreter_description->read(first_page_buffer, sizeof(first_page)));
|
||||
|
||||
if (nread < sizeof(ElfW(Ehdr)))
|
||||
if (nread < sizeof(Elf_Ehdr))
|
||||
return ENOEXEC;
|
||||
|
||||
auto* elf_header = (ElfW(Ehdr)*)first_page;
|
||||
auto* elf_header = (Elf_Ehdr*)first_page;
|
||||
if (!ELF::validate_elf_header(*elf_header, interp_metadata.size)) {
|
||||
dbgln("exec({}): Interpreter ({}) has invalid ELF header", path, interpreter_path);
|
||||
return ENOEXEC;
|
||||
|
@ -914,9 +914,9 @@ ErrorOr<void> Process::exec(NonnullOwnPtr<KString> path, Vector<NonnullOwnPtr<KS
|
|||
|
||||
// #2) ELF32 for i386
|
||||
|
||||
if (nread < sizeof(ElfW(Ehdr)))
|
||||
if (nread < sizeof(Elf_Ehdr))
|
||||
return ENOEXEC;
|
||||
auto const* main_program_header = (ElfW(Ehdr)*)first_page;
|
||||
auto const* main_program_header = (Elf_Ehdr*)first_page;
|
||||
|
||||
if (!ELF::validate_elf_header(*main_program_header, metadata.size)) {
|
||||
dbgln("exec({}): File has invalid ELF header", path);
|
||||
|
|
|
@ -56,7 +56,7 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab
|
|||
auto const& inode_vm = static_cast<Memory::InodeVMObject const&>(region.vmobject());
|
||||
auto const& inode = inode_vm.inode();
|
||||
|
||||
ElfW(Ehdr) header;
|
||||
Elf_Ehdr header;
|
||||
auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&header);
|
||||
auto result = inode.read_bytes(0, sizeof(header), buffer, nullptr);
|
||||
if (result.is_error() || result.value() != sizeof(header))
|
||||
|
|
|
@ -115,7 +115,7 @@ ErrorOr<NonnullRefPtr<OpenFileDescription>> Coredump::try_create_target_file(Pro
|
|||
|
||||
ErrorOr<void> Coredump::write_elf_header()
|
||||
{
|
||||
ElfW(Ehdr) elf_file_header;
|
||||
Elf_Ehdr elf_file_header;
|
||||
elf_file_header.e_ident[EI_MAG0] = 0x7f;
|
||||
elf_file_header.e_ident[EI_MAG1] = 'E';
|
||||
elf_file_header.e_ident[EI_MAG2] = 'L';
|
||||
|
@ -147,24 +147,24 @@ ErrorOr<void> Coredump::write_elf_header()
|
|||
#endif
|
||||
elf_file_header.e_version = 1;
|
||||
elf_file_header.e_entry = 0;
|
||||
elf_file_header.e_phoff = sizeof(ElfW(Ehdr));
|
||||
elf_file_header.e_phoff = sizeof(Elf_Ehdr);
|
||||
elf_file_header.e_shoff = 0;
|
||||
elf_file_header.e_flags = 0;
|
||||
elf_file_header.e_ehsize = sizeof(ElfW(Ehdr));
|
||||
elf_file_header.e_shentsize = sizeof(ElfW(Shdr));
|
||||
elf_file_header.e_phentsize = sizeof(ElfW(Phdr));
|
||||
elf_file_header.e_ehsize = sizeof(Elf_Ehdr);
|
||||
elf_file_header.e_shentsize = sizeof(Elf_Shdr);
|
||||
elf_file_header.e_phentsize = sizeof(Elf_Phdr);
|
||||
elf_file_header.e_phnum = m_num_program_headers;
|
||||
elf_file_header.e_shnum = 0;
|
||||
elf_file_header.e_shstrndx = SHN_UNDEF;
|
||||
|
||||
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(&elf_file_header)), sizeof(ElfW(Ehdr))));
|
||||
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(&elf_file_header)), sizeof(Elf_Ehdr)));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Coredump::write_program_headers(size_t notes_size)
|
||||
{
|
||||
size_t offset = sizeof(ElfW(Ehdr)) + m_num_program_headers * sizeof(ElfW(Phdr));
|
||||
size_t offset = sizeof(Elf_Ehdr) + m_num_program_headers * sizeof(Elf_Phdr);
|
||||
for (auto& region : m_regions) {
|
||||
#if !INCLUDE_USERSPACE_HEAP_MEMORY_IN_COREDUMPS
|
||||
if (region.looks_like_userspace_heap_region())
|
||||
|
@ -174,7 +174,7 @@ ErrorOr<void> Coredump::write_program_headers(size_t notes_size)
|
|||
if (region.access() == Memory::Region::Access::None)
|
||||
continue;
|
||||
|
||||
ElfW(Phdr) phdr {};
|
||||
Elf_Phdr phdr {};
|
||||
|
||||
phdr.p_type = PT_LOAD;
|
||||
phdr.p_offset = offset;
|
||||
|
@ -193,10 +193,10 @@ ErrorOr<void> Coredump::write_program_headers(size_t notes_size)
|
|||
|
||||
offset += phdr.p_filesz;
|
||||
|
||||
[[maybe_unused]] auto rc = m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(&phdr)), sizeof(ElfW(Phdr)));
|
||||
[[maybe_unused]] auto rc = m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(&phdr)), sizeof(Elf_Phdr));
|
||||
}
|
||||
|
||||
ElfW(Phdr) notes_pheader {};
|
||||
Elf_Phdr notes_pheader {};
|
||||
notes_pheader.p_type = PT_NOTE;
|
||||
notes_pheader.p_offset = offset;
|
||||
notes_pheader.p_vaddr = 0;
|
||||
|
@ -206,7 +206,7 @@ ErrorOr<void> Coredump::write_program_headers(size_t notes_size)
|
|||
notes_pheader.p_align = 0;
|
||||
notes_pheader.p_flags = 0;
|
||||
|
||||
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(¬es_pheader)), sizeof(ElfW(Phdr))));
|
||||
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(¬es_pheader)), sizeof(Elf_Phdr)));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -503,7 +503,7 @@ public:
|
|||
|
||||
ErrorOr<void> exec(NonnullOwnPtr<KString> path, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth = 0);
|
||||
|
||||
ErrorOr<LoadResult> load(Memory::AddressSpace& new_space, NonnullRefPtr<OpenFileDescription> main_program_description, RefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header, Optional<size_t> minimum_stack_size = {});
|
||||
ErrorOr<LoadResult> load(Memory::AddressSpace& new_space, NonnullRefPtr<OpenFileDescription> main_program_description, RefPtr<OpenFileDescription> interpreter_description, Elf_Ehdr const& main_program_header, Optional<size_t> minimum_stack_size = {});
|
||||
|
||||
void terminate_due_to_signal(u8 signal);
|
||||
ErrorOr<void> send_signal(u8 signal, Process* sender);
|
||||
|
@ -664,12 +664,12 @@ private:
|
|||
bool create_perf_events_buffer_if_needed();
|
||||
void delete_perf_events_buffer();
|
||||
|
||||
ErrorOr<void> do_exec(NonnullRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, RefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header, Optional<size_t> minimum_stack_size = {});
|
||||
ErrorOr<void> do_exec(NonnullRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, RefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, Elf_Ehdr const& main_program_header, Optional<size_t> minimum_stack_size = {});
|
||||
ErrorOr<FlatPtr> do_write(OpenFileDescription&, UserOrKernelBuffer const&, size_t, Optional<off_t> = {});
|
||||
|
||||
ErrorOr<FlatPtr> do_statvfs(FileSystem const& path, Custody const*, statvfs* buf);
|
||||
|
||||
ErrorOr<RefPtr<OpenFileDescription>> find_elf_interpreter_for_executable(StringView path, ElfW(Ehdr) const& main_executable_header, size_t main_executable_header_size, size_t file_size, Optional<size_t>& minimum_stack_size);
|
||||
ErrorOr<RefPtr<OpenFileDescription>> find_elf_interpreter_for_executable(StringView path, Elf_Ehdr const& main_executable_header, size_t main_executable_header_size, size_t file_size, Optional<size_t>& minimum_stack_size);
|
||||
|
||||
ErrorOr<void> do_kill(Process&, int signal);
|
||||
ErrorOr<void> do_killpg(ProcessGroupID pgrp, int signal);
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
__BEGIN_DECLS
|
||||
|
||||
struct dl_phdr_info {
|
||||
ElfW(Addr) dlpi_addr;
|
||||
Elf_Addr dlpi_addr;
|
||||
char const* dlpi_name;
|
||||
const ElfW(Phdr) * dlpi_phdr;
|
||||
ElfW(Half) dlpi_phnum;
|
||||
Elf_Phdr const* dlpi_phdr;
|
||||
Elf_Half dlpi_phnum;
|
||||
};
|
||||
|
||||
int dl_iterate_phdr(int (*callback)(struct dl_phdr_info* info, size_t size, void* data), void* data);
|
||||
|
|
|
@ -244,7 +244,7 @@ static int __dl_iterate_phdr(DlIteratePhdrCallbackFunction callback, void* data)
|
|||
for (auto& it : s_global_objects) {
|
||||
auto& object = it.value;
|
||||
auto info = dl_phdr_info {
|
||||
.dlpi_addr = (ElfW(Addr))object->base_address().as_ptr(),
|
||||
.dlpi_addr = (Elf_Addr)object->base_address().as_ptr(),
|
||||
.dlpi_name = object->filepath().characters(),
|
||||
.dlpi_phdr = object->program_headers(),
|
||||
.dlpi_phnum = object->program_header_count()
|
||||
|
|
|
@ -55,7 +55,7 @@ Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(i
|
|||
|
||||
VERIFY(stat.st_size >= 0);
|
||||
auto size = static_cast<size_t>(stat.st_size);
|
||||
if (size < sizeof(ElfW(Ehdr)))
|
||||
if (size < sizeof(Elf_Ehdr))
|
||||
return DlErrorMessage { DeprecatedString::formatted("File {} has invalid ELF header", filepath) };
|
||||
|
||||
DeprecatedString file_mmap_name = DeprecatedString::formatted("ELF_DYN: {}", filepath);
|
||||
|
@ -132,7 +132,7 @@ bool DynamicLoader::validate()
|
|||
if (!image().is_valid())
|
||||
return false;
|
||||
|
||||
auto* elf_header = (ElfW(Ehdr)*)m_file_data;
|
||||
auto* elf_header = (Elf_Ehdr*)m_file_data;
|
||||
if (!validate_elf_header(*elf_header, m_file_size))
|
||||
return false;
|
||||
auto result_or_error = validate_program_headers(*elf_header, m_file_size, { m_file_data, m_file_size });
|
||||
|
|
|
@ -98,7 +98,7 @@ private:
|
|||
|
||||
class ProgramHeaderRegion {
|
||||
public:
|
||||
void set_program_header(const ElfW(Phdr) & header) { m_program_header = header; }
|
||||
void set_program_header(Elf_Phdr const& header) { m_program_header = header; }
|
||||
|
||||
// Information from ELF Program header
|
||||
u32 type() const { return m_program_header.p_type; }
|
||||
|
@ -117,7 +117,7 @@ private:
|
|||
bool is_relro() const { return type() == PT_GNU_RELRO; }
|
||||
|
||||
private:
|
||||
ElfW(Phdr) m_program_header; // Explicitly a copy of the PHDR in the image
|
||||
Elf_Phdr m_program_header; // Explicitly a copy of the PHDR in the image
|
||||
};
|
||||
|
||||
// Stage 1
|
||||
|
|
|
@ -21,7 +21,7 @@ DynamicObject::DynamicObject(DeprecatedString const& filepath, VirtualAddress ba
|
|||
, m_base_address(base_address)
|
||||
, m_dynamic_address(dynamic_section_address)
|
||||
{
|
||||
auto* header = (ElfW(Ehdr)*)base_address.as_ptr();
|
||||
auto* header = (Elf_Ehdr*)base_address.as_ptr();
|
||||
auto* const phdrs = program_headers();
|
||||
|
||||
// Calculate the base address using the PT_LOAD element with the lowest `p_vaddr` (which is the first element)
|
||||
|
@ -200,7 +200,7 @@ void DynamicObject::parse()
|
|||
// TODO: FIXME, this shouldn't be hardcoded
|
||||
// The reason we need this here is that for some reason, when there only PLT relocations, the compiler
|
||||
// doesn't insert a 'PLTRELSZ' entry to the dynamic section
|
||||
m_size_of_relocation_entry = sizeof(ElfW(Rel));
|
||||
m_size_of_relocation_entry = sizeof(Elf_Rel);
|
||||
}
|
||||
|
||||
// Whether or not RELASZ (stored in m_size_of_relocation_table) only refers to non-PLT entries is not clearly specified.
|
||||
|
@ -226,21 +226,21 @@ DynamicObject::Relocation DynamicObject::RelocationSection::relocation(unsigned
|
|||
{
|
||||
VERIFY(index < entry_count());
|
||||
unsigned offset_in_section = index * entry_size();
|
||||
auto relocation_address = (ElfW(Rela)*)address().offset(offset_in_section).as_ptr();
|
||||
auto relocation_address = (Elf_Rela*)address().offset(offset_in_section).as_ptr();
|
||||
return Relocation(m_dynamic, *relocation_address, offset_in_section, m_addend_used);
|
||||
}
|
||||
|
||||
DynamicObject::Relocation DynamicObject::RelocationSection::relocation_at_offset(unsigned offset) const
|
||||
{
|
||||
VERIFY(offset <= (m_section_size_bytes - m_entry_size));
|
||||
auto relocation_address = (ElfW(Rela)*)address().offset(offset).as_ptr();
|
||||
auto relocation_address = (Elf_Rela*)address().offset(offset).as_ptr();
|
||||
return Relocation(m_dynamic, *relocation_address, offset, m_addend_used);
|
||||
}
|
||||
|
||||
DynamicObject::Symbol DynamicObject::symbol(unsigned index) const
|
||||
{
|
||||
auto symbol_section = Section(*this, m_symbol_table_offset, (m_symbol_count * m_size_of_symbol_table_entry), m_size_of_symbol_table_entry, "DT_SYMTAB"sv);
|
||||
auto symbol_entry = (ElfW(Sym)*)symbol_section.address().offset(index * symbol_section.entry_size()).as_ptr();
|
||||
auto symbol_entry = (Elf_Sym*)symbol_section.address().offset(index * symbol_section.entry_size()).as_ptr();
|
||||
return Symbol(*this, index, *symbol_entry);
|
||||
}
|
||||
|
||||
|
@ -279,16 +279,16 @@ DynamicObject::Section DynamicObject::relr_relocation_section() const
|
|||
return Section(*this, m_relr_relocation_table_offset, m_size_of_relr_relocation_table, m_size_of_relr_relocations_entry, "DT_RELR"sv);
|
||||
}
|
||||
|
||||
ElfW(Half) DynamicObject::program_header_count() const
|
||||
Elf_Half DynamicObject::program_header_count() const
|
||||
{
|
||||
auto* header = (const ElfW(Ehdr)*)m_base_address.as_ptr();
|
||||
auto* header = (Elf_Ehdr const*)m_base_address.as_ptr();
|
||||
return header->e_phnum;
|
||||
}
|
||||
|
||||
const ElfW(Phdr) * DynamicObject::program_headers() const
|
||||
Elf_Phdr const* DynamicObject::program_headers() const
|
||||
{
|
||||
auto* header = (const ElfW(Ehdr)*)m_base_address.as_ptr();
|
||||
return (const ElfW(Phdr)*)(m_base_address.as_ptr() + header->e_phoff);
|
||||
auto* header = (Elf_Ehdr const*)m_base_address.as_ptr();
|
||||
return (Elf_Phdr const*)(m_base_address.as_ptr() + header->e_phoff);
|
||||
}
|
||||
|
||||
auto DynamicObject::HashSection::lookup_sysv_symbol(StringView name, u32 hash_value) const -> Optional<Symbol>
|
||||
|
@ -323,12 +323,12 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(StringView name, u32 hash_val
|
|||
|
||||
u32 const* hash_table_begin = (u32*)address().as_ptr();
|
||||
|
||||
const size_t num_buckets = hash_table_begin[0];
|
||||
const size_t num_omitted_symbols = hash_table_begin[1];
|
||||
const u32 num_maskwords = hash_table_begin[2];
|
||||
size_t const num_buckets = hash_table_begin[0];
|
||||
size_t const num_omitted_symbols = hash_table_begin[1];
|
||||
u32 const num_maskwords = hash_table_begin[2];
|
||||
// This works because num_maskwords is required to be a power of 2
|
||||
const u32 num_maskwords_bitmask = num_maskwords - 1;
|
||||
const u32 shift2 = hash_table_begin[3];
|
||||
u32 const num_maskwords_bitmask = num_maskwords - 1;
|
||||
u32 const shift2 = hash_table_begin[3];
|
||||
|
||||
BloomWord const* bloom_words = (BloomWord const*)&hash_table_begin[4];
|
||||
u32 const* const buckets = (u32 const*)&bloom_words[num_maskwords];
|
||||
|
@ -336,7 +336,7 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(StringView name, u32 hash_val
|
|||
|
||||
BloomWord hash1 = hash_value;
|
||||
BloomWord hash2 = hash1 >> shift2;
|
||||
const BloomWord bitmask = ((BloomWord)1 << (hash1 % bloom_word_size)) | ((BloomWord)1 << (hash2 % bloom_word_size));
|
||||
BloomWord const bitmask = ((BloomWord)1 << (hash1 % bloom_word_size)) | ((BloomWord)1 << (hash2 % bloom_word_size));
|
||||
|
||||
if ((bloom_words[(hash1 / bloom_word_size) & num_maskwords_bitmask] & bitmask) != bitmask)
|
||||
return {};
|
||||
|
@ -361,13 +361,13 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(StringView name, u32 hash_val
|
|||
return {};
|
||||
}
|
||||
|
||||
StringView DynamicObject::symbol_string_table_string(ElfW(Word) index) const
|
||||
StringView DynamicObject::symbol_string_table_string(Elf_Word index) const
|
||||
{
|
||||
auto const* symbol_string_table_ptr = reinterpret_cast<char const*>(base_address().offset(m_string_table_offset + index).as_ptr());
|
||||
return StringView { symbol_string_table_ptr, strlen(symbol_string_table_ptr) };
|
||||
}
|
||||
|
||||
char const* DynamicObject::raw_symbol_string_table_string(ElfW(Word) index) const
|
||||
char const* DynamicObject::raw_symbol_string_table_string(Elf_Word index) const
|
||||
{
|
||||
return (char const*)base_address().offset(m_string_table_offset + index).as_ptr();
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ DynamicObject::FinalizationFunction DynamicObject::fini_section_function() const
|
|||
return (FinalizationFunction)fini_section().address().as_ptr();
|
||||
}
|
||||
|
||||
char const* DynamicObject::name_for_dtag(ElfW(Sword) d_tag)
|
||||
char const* DynamicObject::name_for_dtag(Elf_Sword d_tag)
|
||||
{
|
||||
switch (d_tag) {
|
||||
case DT_NULL:
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ELF {
|
|||
class DynamicObject : public RefCounted<DynamicObject> {
|
||||
public:
|
||||
static NonnullRefPtr<DynamicObject> create(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
|
||||
static char const* name_for_dtag(ElfW(Sword) d_tag);
|
||||
static char const* name_for_dtag(Elf_Sword d_tag);
|
||||
|
||||
~DynamicObject();
|
||||
void dump() const;
|
||||
|
@ -35,24 +35,24 @@ public:
|
|||
|
||||
class DynamicEntry {
|
||||
public:
|
||||
explicit DynamicEntry(const ElfW(Dyn) & dyn)
|
||||
explicit DynamicEntry(Elf_Dyn const& dyn)
|
||||
: m_dyn(dyn)
|
||||
{
|
||||
}
|
||||
|
||||
~DynamicEntry() = default;
|
||||
|
||||
ElfW(Sword) tag() const { return m_dyn.d_tag; }
|
||||
ElfW(Addr) ptr() const { return m_dyn.d_un.d_ptr; }
|
||||
ElfW(Word) val() const { return m_dyn.d_un.d_val; }
|
||||
Elf_Sword tag() const { return m_dyn.d_tag; }
|
||||
Elf_Addr ptr() const { return m_dyn.d_un.d_ptr; }
|
||||
Elf_Word val() const { return m_dyn.d_un.d_val; }
|
||||
|
||||
private:
|
||||
const ElfW(Dyn) & m_dyn;
|
||||
Elf_Dyn const& m_dyn;
|
||||
};
|
||||
|
||||
class Symbol {
|
||||
public:
|
||||
Symbol(DynamicObject const& dynamic, unsigned index, const ElfW(Sym) & sym)
|
||||
Symbol(DynamicObject const& dynamic, unsigned index, Elf_Sym const& sym)
|
||||
: m_dynamic(dynamic)
|
||||
, m_sym(sym)
|
||||
, m_index(index)
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
|
||||
private:
|
||||
DynamicObject const& m_dynamic;
|
||||
const ElfW(Sym) & m_sym;
|
||||
Elf_Sym const& m_sym;
|
||||
unsigned const m_index;
|
||||
};
|
||||
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
|
||||
class Relocation {
|
||||
public:
|
||||
Relocation(DynamicObject const& dynamic, const ElfW(Rela) & rel, unsigned offset_in_section, bool addend_used)
|
||||
Relocation(DynamicObject const& dynamic, Elf_Rela const& rel, unsigned offset_in_section, bool addend_used)
|
||||
: m_dynamic(dynamic)
|
||||
, m_rel(rel)
|
||||
, m_offset_in_section(offset_in_section)
|
||||
|
@ -191,7 +191,7 @@ public:
|
|||
|
||||
private:
|
||||
DynamicObject const& m_dynamic;
|
||||
const ElfW(Rela) & m_rel;
|
||||
Elf_Rela const& m_rel;
|
||||
unsigned const m_offset_in_section;
|
||||
bool const m_addend_used;
|
||||
};
|
||||
|
@ -246,7 +246,7 @@ public:
|
|||
|
||||
typedef void (*InitializationFunction)();
|
||||
typedef void (*FinalizationFunction)();
|
||||
typedef ElfW(Addr) (*IfuncResolver)();
|
||||
typedef Elf_Addr (*IfuncResolver)();
|
||||
|
||||
bool has_init_section() const { return m_init_offset != 0; }
|
||||
bool has_init_array_section() const { return m_init_array_offset != 0; }
|
||||
|
@ -295,8 +295,8 @@ public:
|
|||
void set_tls_offset(FlatPtr offset) { m_tls_offset = offset; }
|
||||
void set_tls_size(FlatPtr size) { m_tls_size = size; }
|
||||
|
||||
ElfW(Half) program_header_count() const;
|
||||
const ElfW(Phdr) * program_headers() const;
|
||||
Elf_Half program_header_count() const;
|
||||
Elf_Phdr const* program_headers() const;
|
||||
|
||||
template<VoidFunction<StringView> F>
|
||||
void for_each_needed_library(F) const;
|
||||
|
@ -334,8 +334,8 @@ public:
|
|||
private:
|
||||
explicit DynamicObject(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
|
||||
|
||||
StringView symbol_string_table_string(ElfW(Word)) const;
|
||||
char const* raw_symbol_string_table_string(ElfW(Word)) const;
|
||||
StringView symbol_string_table_string(Elf_Word) const;
|
||||
char const* raw_symbol_string_table_string(Elf_Word) const;
|
||||
void parse();
|
||||
|
||||
DeprecatedString m_filepath;
|
||||
|
@ -363,7 +363,7 @@ private:
|
|||
FlatPtr m_symbol_table_offset { 0 };
|
||||
size_t m_size_of_symbol_table_entry { 0 };
|
||||
|
||||
ElfW(Sword) m_procedure_linkage_table_relocation_type { -1 };
|
||||
Elf_Sword m_procedure_linkage_table_relocation_type { -1 };
|
||||
FlatPtr m_plt_relocation_offset_location { 0 }; // offset of PLT relocations, at end of relocations
|
||||
size_t m_size_of_plt_relocation_entry_list { 0 };
|
||||
Optional<FlatPtr> m_procedure_linkage_table_offset;
|
||||
|
@ -383,14 +383,14 @@ private:
|
|||
bool m_is_pie { false };
|
||||
|
||||
// DT_FLAGS
|
||||
ElfW(Word) m_dt_flags { 0 };
|
||||
Elf_Word m_dt_flags { 0 };
|
||||
|
||||
bool m_has_soname { false };
|
||||
ElfW(Word) m_soname_index { 0 }; // Index into dynstr table for SONAME
|
||||
Elf_Word m_soname_index { 0 }; // Index into dynstr table for SONAME
|
||||
bool m_has_rpath { false };
|
||||
ElfW(Word) m_rpath_index { 0 }; // Index into dynstr table for RPATH
|
||||
Elf_Word m_rpath_index { 0 }; // Index into dynstr table for RPATH
|
||||
bool m_has_runpath { false };
|
||||
ElfW(Word) m_runpath_index { 0 }; // Index into dynstr table for RUNPATH
|
||||
Elf_Word m_runpath_index { 0 }; // Index into dynstr table for RUNPATH
|
||||
|
||||
Optional<FlatPtr> m_tls_offset;
|
||||
Optional<FlatPtr> m_tls_size;
|
||||
|
@ -428,7 +428,7 @@ inline void DynamicObject::for_each_relr_relocation(F f) const
|
|||
VERIFY(section.entry_size() == sizeof(FlatPtr));
|
||||
VERIFY(section.size() >= section.entry_size() * section.entry_count());
|
||||
|
||||
auto* entries = reinterpret_cast<ElfW(Relr)*>(section.address().get());
|
||||
auto* entries = reinterpret_cast<Elf_Relr*>(section.address().get());
|
||||
auto base = base_address().get();
|
||||
FlatPtr patch_addr = 0;
|
||||
for (unsigned i = 0; i < section.entry_count(); ++i) {
|
||||
|
@ -458,7 +458,7 @@ inline void DynamicObject::for_each_symbol(F func) const
|
|||
template<IteratorFunction<DynamicObject::DynamicEntry&> F>
|
||||
inline void DynamicObject::for_each_dynamic_entry(F func) const
|
||||
{
|
||||
auto* dyns = reinterpret_cast<const ElfW(Dyn)*>(m_dynamic_address.as_ptr());
|
||||
auto* dyns = reinterpret_cast<Elf_Dyn const*>(m_dynamic_address.as_ptr());
|
||||
for (unsigned i = 0;; ++i) {
|
||||
auto&& dyn = DynamicEntry(dyns[i]);
|
||||
if (dyn.tag() == DT_NULL)
|
||||
|
@ -483,7 +483,7 @@ inline void DynamicObject::for_each_needed_library(F func) const
|
|||
for_each_dynamic_entry([func, this](auto entry) {
|
||||
if (entry.tag() != DT_NEEDED)
|
||||
return;
|
||||
ElfW(Word) offset = entry.val();
|
||||
Elf_Word offset = entry.val();
|
||||
func(symbol_string_table_string(offset));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -761,6 +761,7 @@ struct elf_args {
|
|||
# define Elf_Sym Elf32_Sym
|
||||
# define Elf_Rel Elf32_Rel
|
||||
# define Elf_RelA Elf32_Rela
|
||||
# define Elf_Rela Elf32_Rela
|
||||
# define Elf_Relr Elf32_Relr
|
||||
# define Elf_Dyn Elf32_Dyn
|
||||
# define Elf_Half Elf32_Half
|
||||
|
@ -789,6 +790,7 @@ struct elf_args {
|
|||
# define Elf_Sym Elf64_Sym
|
||||
# define Elf_Rel Elf64_Rel
|
||||
# define Elf_RelA Elf64_Rela
|
||||
# define Elf_Rela Elf64_Rela
|
||||
# define Elf_Relr Elf64_Relr
|
||||
# define Elf_Dyn Elf64_Dyn
|
||||
# define Elf_Half Elf64_Half
|
||||
|
|
|
@ -121,7 +121,7 @@ unsigned Image::program_header_count() const
|
|||
|
||||
bool Image::parse()
|
||||
{
|
||||
if (m_size < sizeof(ElfW(Ehdr)) || !validate_elf_header(header(), m_size, m_verbose_logging)) {
|
||||
if (m_size < sizeof(Elf_Ehdr) || !validate_elf_header(header(), m_size, m_verbose_logging)) {
|
||||
if (m_verbose_logging)
|
||||
dbgln("ELF::Image::parse(): ELF Header not valid");
|
||||
m_valid = false;
|
||||
|
@ -198,31 +198,31 @@ char const* Image::raw_data(unsigned offset) const
|
|||
return reinterpret_cast<char const*>(m_buffer) + offset;
|
||||
}
|
||||
|
||||
const ElfW(Ehdr) & Image::header() const
|
||||
Elf_Ehdr const& Image::header() const
|
||||
{
|
||||
VERIFY(m_size >= sizeof(ElfW(Ehdr)));
|
||||
return *reinterpret_cast<const ElfW(Ehdr)*>(raw_data(0));
|
||||
VERIFY(m_size >= sizeof(Elf_Ehdr));
|
||||
return *reinterpret_cast<Elf_Ehdr const*>(raw_data(0));
|
||||
}
|
||||
|
||||
const ElfW(Phdr) & Image::program_header_internal(unsigned index) const
|
||||
Elf_Phdr const& Image::program_header_internal(unsigned index) const
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
VERIFY(index < header().e_phnum);
|
||||
return *reinterpret_cast<const ElfW(Phdr)*>(raw_data(header().e_phoff + (index * sizeof(ElfW(Phdr)))));
|
||||
return *reinterpret_cast<Elf_Phdr const*>(raw_data(header().e_phoff + (index * sizeof(Elf_Phdr))));
|
||||
}
|
||||
|
||||
const ElfW(Shdr) & Image::section_header(unsigned index) const
|
||||
Elf_Shdr const& Image::section_header(unsigned index) const
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
VERIFY(index < header().e_shnum);
|
||||
return *reinterpret_cast<const ElfW(Shdr)*>(raw_data(header().e_shoff + (index * header().e_shentsize)));
|
||||
return *reinterpret_cast<Elf_Shdr const*>(raw_data(header().e_shoff + (index * header().e_shentsize)));
|
||||
}
|
||||
|
||||
Image::Symbol Image::symbol(unsigned index) const
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
VERIFY(index < symbol_count());
|
||||
auto* raw_syms = reinterpret_cast<const ElfW(Sym)*>(raw_data(section(m_symbol_table_section_index).offset()));
|
||||
auto* raw_syms = reinterpret_cast<Elf_Sym const*>(raw_data(section(m_symbol_table_section_index).offset()));
|
||||
return Symbol(*this, index, raw_syms[index]);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ Image::ProgramHeader Image::program_header(unsigned index) const
|
|||
Image::Relocation Image::RelocationSection::relocation(unsigned index) const
|
||||
{
|
||||
VERIFY(index < relocation_count());
|
||||
auto* rels = reinterpret_cast<const ElfW(Rel)*>(m_image.raw_data(offset()));
|
||||
auto* rels = reinterpret_cast<Elf_Rel const*>(m_image.raw_data(offset()));
|
||||
return Relocation(m_image, rels[index]);
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ Optional<Image::Section> Image::lookup_section(StringView name) const
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<StringView> Image::object_file_type_to_string(ElfW(Half) type)
|
||||
Optional<StringView> Image::object_file_type_to_string(Elf_Half type)
|
||||
{
|
||||
switch (type) {
|
||||
case ET_NONE:
|
||||
|
@ -290,7 +290,7 @@ Optional<StringView> Image::object_file_type_to_string(ElfW(Half) type)
|
|||
}
|
||||
}
|
||||
|
||||
Optional<StringView> Image::object_machine_type_to_string(ElfW(Half) type)
|
||||
Optional<StringView> Image::object_machine_type_to_string(Elf_Half type)
|
||||
{
|
||||
switch (type) {
|
||||
case ET_NONE:
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
class Symbol {
|
||||
public:
|
||||
Symbol(Image const& image, unsigned index, const ElfW(Sym) & sym)
|
||||
Symbol(Image const& image, unsigned index, Elf_Sym const& sym)
|
||||
: m_image(image)
|
||||
, m_sym(sym)
|
||||
, m_index(index)
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
|
||||
private:
|
||||
Image const& m_image;
|
||||
const ElfW(Sym) & m_sym;
|
||||
Elf_Sym const& m_sym;
|
||||
unsigned const m_index;
|
||||
};
|
||||
|
||||
|
@ -98,11 +98,11 @@ public:
|
|||
bool is_writable() const { return flags() & PF_W; }
|
||||
bool is_executable() const { return flags() & PF_X; }
|
||||
char const* raw_data() const { return m_image.raw_data(m_program_header.p_offset); }
|
||||
ElfW(Phdr) raw_header() const { return m_program_header; }
|
||||
Elf_Phdr raw_header() const { return m_program_header; }
|
||||
|
||||
private:
|
||||
Image const& m_image;
|
||||
const ElfW(Phdr) & m_program_header;
|
||||
Elf_Phdr const& m_program_header;
|
||||
unsigned m_program_header_index { 0 };
|
||||
};
|
||||
|
||||
|
@ -133,7 +133,7 @@ public:
|
|||
protected:
|
||||
friend class RelocationSection;
|
||||
Image const& m_image;
|
||||
const ElfW(Shdr) & m_section_header;
|
||||
Elf_Shdr const& m_section_header;
|
||||
unsigned m_section_index;
|
||||
};
|
||||
|
||||
|
@ -152,7 +152,7 @@ public:
|
|||
|
||||
class Relocation {
|
||||
public:
|
||||
Relocation(Image const& image, const ElfW(Rel) & rel)
|
||||
Relocation(Image const& image, Elf_Rel const& rel)
|
||||
: m_image(image)
|
||||
, m_rel(rel)
|
||||
{
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
|
||||
private:
|
||||
Image const& m_image;
|
||||
const ElfW(Rel) & m_rel;
|
||||
Elf_Rel const& m_rel;
|
||||
};
|
||||
|
||||
unsigned symbol_count() const;
|
||||
|
@ -214,8 +214,8 @@ public:
|
|||
FlatPtr base_address() const { return (FlatPtr)m_buffer; }
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
static Optional<StringView> object_file_type_to_string(ElfW(Half) type);
|
||||
static Optional<StringView> object_machine_type_to_string(ElfW(Half) type);
|
||||
static Optional<StringView> object_file_type_to_string(Elf_Half type);
|
||||
static Optional<StringView> object_machine_type_to_string(Elf_Half type);
|
||||
static Optional<StringView> object_abi_type_to_string(Elf_Byte type);
|
||||
|
||||
bool has_symbols() const { return symbol_count(); }
|
||||
|
@ -227,9 +227,9 @@ public:
|
|||
|
||||
private:
|
||||
char const* raw_data(unsigned offset) const;
|
||||
const ElfW(Ehdr) & header() const;
|
||||
const ElfW(Shdr) & section_header(unsigned) const;
|
||||
const ElfW(Phdr) & program_header_internal(unsigned) const;
|
||||
Elf_Ehdr const& header() const;
|
||||
Elf_Shdr const& section_header(unsigned) const;
|
||||
Elf_Phdr const& program_header_internal(unsigned) const;
|
||||
StringView table_string(unsigned offset) const;
|
||||
StringView section_header_table_string(unsigned offset) const;
|
||||
StringView section_index_to_string(unsigned index) const;
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace ELF {
|
|||
bool perform_relative_relocations(FlatPtr base_address)
|
||||
{
|
||||
|
||||
ElfW(Ehdr)* header = (ElfW(Ehdr)*)(base_address);
|
||||
ElfW(Phdr)* pheader = (ElfW(Phdr)*)(base_address + header->e_phoff);
|
||||
Elf_Ehdr* header = (Elf_Ehdr*)(base_address);
|
||||
Elf_Phdr* pheader = (Elf_Phdr*)(base_address + header->e_phoff);
|
||||
FlatPtr dynamic_section_addr = 0;
|
||||
for (size_t i = 0; i < (size_t)header->e_phnum; ++i, ++pheader) {
|
||||
if (pheader->p_type != PT_DYNAMIC)
|
||||
|
@ -30,7 +30,7 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
FlatPtr relr_relocation_section_addr = 0;
|
||||
size_t relr_relocation_table_size = 0;
|
||||
bool use_addend = false;
|
||||
auto* dyns = reinterpret_cast<const ElfW(Dyn)*>(dynamic_section_addr);
|
||||
auto* dyns = reinterpret_cast<Elf_Dyn const*>(dynamic_section_addr);
|
||||
for (unsigned i = 0;; ++i) {
|
||||
auto& dyn = dyns[i];
|
||||
if (dyn.d_tag == DT_NULL)
|
||||
|
@ -58,7 +58,7 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
|
||||
for (unsigned i = 0; i < relocation_count; ++i) {
|
||||
size_t offset_in_section = i * relocation_entry_size;
|
||||
auto* relocation = (ElfW(Rela)*)(relocation_section_addr + offset_in_section);
|
||||
auto* relocation = (Elf_Rela*)(relocation_section_addr + offset_in_section);
|
||||
VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE || ELF64_R_TYPE(relocation->r_info) == R_AARCH64_RELATIVE);
|
||||
auto* patch_address = (FlatPtr*)(base_address + relocation->r_offset);
|
||||
FlatPtr relocated_address;
|
||||
|
@ -78,7 +78,7 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
__builtin_memcpy(patch_ptr, &relocated_address, sizeof(FlatPtr));
|
||||
};
|
||||
|
||||
auto* entries = reinterpret_cast<ElfW(Relr)*>(relr_relocation_section_addr);
|
||||
auto* entries = reinterpret_cast<Elf_Relr*>(relr_relocation_section_addr);
|
||||
FlatPtr* patch_ptr = nullptr;
|
||||
|
||||
for (unsigned i = 0; i < relr_relocation_table_size / sizeof(FlatPtr); ++i) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
namespace ELF {
|
||||
|
||||
bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool verbose)
|
||||
bool validate_elf_header(Elf_Ehdr const& elf_header, size_t file_size, bool verbose)
|
||||
{
|
||||
if (!IS_ELF(elf_header)) {
|
||||
if (verbose)
|
||||
|
@ -80,9 +80,9 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
|
|||
return false;
|
||||
}
|
||||
|
||||
if (sizeof(ElfW(Ehdr)) != elf_header.e_ehsize) {
|
||||
if (sizeof(Elf_Ehdr) != elf_header.e_ehsize) {
|
||||
if (verbose)
|
||||
dbgln("File has incorrect ELF header size..? ({}), expected ({})!", elf_header.e_ehsize, sizeof(ElfW(Ehdr)));
|
||||
dbgln("File has incorrect ELF header size..? ({}), expected ({})!", elf_header.e_ehsize, sizeof(Elf_Ehdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -134,15 +134,15 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
|
|||
}
|
||||
}
|
||||
|
||||
if (0 != elf_header.e_phnum && sizeof(ElfW(Phdr)) != elf_header.e_phentsize) {
|
||||
if (0 != elf_header.e_phnum && sizeof(Elf_Phdr) != elf_header.e_phentsize) {
|
||||
if (verbose)
|
||||
dbgln("File has incorrect program header size..? ({}), expected ({}).", elf_header.e_phentsize, sizeof(ElfW(Phdr)));
|
||||
dbgln("File has incorrect program header size..? ({}), expected ({}).", elf_header.e_phentsize, sizeof(Elf_Phdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sizeof(ElfW(Shdr)) != elf_header.e_shentsize) {
|
||||
if (sizeof(Elf_Shdr) != elf_header.e_shentsize) {
|
||||
if (verbose)
|
||||
dbgln("File has incorrect section header size..? ({}), expected ({}).", elf_header.e_shentsize, sizeof(ElfW(Shdr)));
|
||||
dbgln("File has incorrect section header size..? ({}), expected ({}).", elf_header.e_shentsize, sizeof(Elf_Shdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
|
|||
return true;
|
||||
}
|
||||
|
||||
ErrorOr<bool> validate_program_headers(ElfW(Ehdr) const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder, Optional<size_t>* requested_stack_size, bool verbose)
|
||||
ErrorOr<bool> validate_program_headers(Elf_Ehdr const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder, Optional<size_t>* requested_stack_size, bool verbose)
|
||||
{
|
||||
Checked<size_t> total_size_of_program_headers = elf_header.e_phnum;
|
||||
total_size_of_program_headers *= elf_header.e_phentsize;
|
||||
|
@ -226,7 +226,7 @@ ErrorOr<bool> validate_program_headers(ElfW(Ehdr) const& elf_header, size_t file
|
|||
}
|
||||
|
||||
size_t num_program_headers = elf_header.e_phnum;
|
||||
auto program_header_begin = (const ElfW(Phdr)*)buffer.offset(elf_header.e_phoff);
|
||||
auto program_header_begin = (Elf_Phdr const*)buffer.offset(elf_header.e_phoff);
|
||||
|
||||
for (size_t header_index = 0; header_index < num_program_headers; ++header_index) {
|
||||
auto& program_header = program_header_begin[header_index];
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace ELF {
|
||||
|
||||
bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool verbose = true);
|
||||
ErrorOr<bool> validate_program_headers(ElfW(Ehdr) const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder = nullptr, Optional<size_t>* requested_stack_size = nullptr, bool verbose = true);
|
||||
bool validate_elf_header(Elf_Ehdr const& elf_header, size_t file_size, bool verbose = true);
|
||||
ErrorOr<bool> validate_program_headers(Elf_Ehdr const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder = nullptr, Optional<size_t>* requested_stack_size = nullptr, bool verbose = true);
|
||||
|
||||
} // end namespace ELF
|
||||
|
|
|
@ -129,12 +129,12 @@ static ErrorOr<Optional<String>> elf_details(StringView description, StringView
|
|||
return OptionalNone {};
|
||||
|
||||
StringBuilder interpreter_path_builder;
|
||||
auto result_or_error = ELF::validate_program_headers(*(const ElfW(Ehdr)*)elf_data.data(), elf_data.size(), elf_data, &interpreter_path_builder);
|
||||
auto result_or_error = ELF::validate_program_headers(*(Elf_Ehdr const*)elf_data.data(), elf_data.size(), elf_data, &interpreter_path_builder);
|
||||
if (result_or_error.is_error() || !result_or_error.value())
|
||||
return OptionalNone {};
|
||||
auto interpreter_path = interpreter_path_builder.string_view();
|
||||
|
||||
auto& header = *reinterpret_cast<const ElfW(Ehdr)*>(elf_data.data());
|
||||
auto& header = *reinterpret_cast<Elf_Ehdr const*>(elf_data.data());
|
||||
|
||||
auto bitness = header.e_ident[EI_CLASS] == ELFCLASS64 ? "64" : "32";
|
||||
auto byteorder = header.e_ident[EI_DATA] == ELFDATA2LSB ? "LSB" : "MSB";
|
||||
|
|
|
@ -110,7 +110,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
StringBuilder interpreter_path_builder;
|
||||
auto result_or_error = ELF::validate_program_headers(*(const ElfW(Ehdr)*)elf_image_data.data(), elf_image_data.size(), elf_image_data, &interpreter_path_builder);
|
||||
auto result_or_error = ELF::validate_program_headers(*(Elf_Ehdr const*)elf_image_data.data(), elf_image_data.size(), elf_image_data, &interpreter_path_builder);
|
||||
if (result_or_error.is_error() || !result_or_error.value()) {
|
||||
warnln("Invalid ELF headers");
|
||||
return -1;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char const* object_program_header_type_to_string(ElfW(Word) type)
|
||||
static char const* object_program_header_type_to_string(Elf_Word type)
|
||||
{
|
||||
switch (type) {
|
||||
case PT_NULL:
|
||||
|
@ -66,7 +66,7 @@ static char const* object_program_header_type_to_string(ElfW(Word) type)
|
|||
}
|
||||
}
|
||||
|
||||
static char const* object_section_header_type_to_string(ElfW(Word) type)
|
||||
static char const* object_section_header_type_to_string(Elf_Word type)
|
||||
{
|
||||
switch (type) {
|
||||
case SHT_NULL:
|
||||
|
@ -138,7 +138,7 @@ static char const* object_section_header_type_to_string(ElfW(Word) type)
|
|||
}
|
||||
}
|
||||
|
||||
static char const* object_symbol_type_to_string(ElfW(Word) type)
|
||||
static char const* object_symbol_type_to_string(Elf_Word type)
|
||||
{
|
||||
switch (type) {
|
||||
case STT_NOTYPE:
|
||||
|
@ -164,7 +164,7 @@ static char const* object_symbol_type_to_string(ElfW(Word) type)
|
|||
}
|
||||
}
|
||||
|
||||
static char const* object_symbol_binding_to_string(ElfW(Word) type)
|
||||
static char const* object_symbol_binding_to_string(Elf_Word type)
|
||||
{
|
||||
switch (type) {
|
||||
case STB_LOCAL:
|
||||
|
@ -184,7 +184,7 @@ static char const* object_symbol_binding_to_string(ElfW(Word) type)
|
|||
}
|
||||
}
|
||||
|
||||
static char const* object_relocation_type_to_string(ElfW(Half) machine, ElfW(Word) type)
|
||||
static char const* object_relocation_type_to_string(Elf_Half machine, Elf_Word type)
|
||||
{
|
||||
#define ENUMERATE_RELOCATION(name) \
|
||||
case name: \
|
||||
|
@ -280,14 +280,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
StringBuilder interpreter_path_builder;
|
||||
auto result_or_error = ELF::validate_program_headers(*(const ElfW(Ehdr)*)elf_image_data.data(), elf_image_data.size(), elf_image_data, &interpreter_path_builder);
|
||||
auto result_or_error = ELF::validate_program_headers(*(Elf_Ehdr const*)elf_image_data.data(), elf_image_data.size(), elf_image_data, &interpreter_path_builder);
|
||||
if (result_or_error.is_error() || !result_or_error.value()) {
|
||||
warnln("Invalid ELF headers");
|
||||
return -1;
|
||||
}
|
||||
auto interpreter_path = interpreter_path_builder.string_view();
|
||||
|
||||
auto& header = *reinterpret_cast<const ElfW(Ehdr)*>(elf_image_data.data());
|
||||
auto& header = *reinterpret_cast<Elf_Ehdr const*>(elf_image_data.data());
|
||||
|
||||
RefPtr<ELF::DynamicObject> object = nullptr;
|
||||
|
||||
|
|
Loading…
Reference in a new issue