mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:27:43 +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
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue