LibELF: Move AuxiliaryValue into the ELF namespace

This commit is contained in:
Andreas Kling 2020-12-25 14:48:30 +01:00
parent 6c9a6bea1e
commit 40e9edd798
Notes: sideshowbarker 2024-07-19 00:36:49 +09:00
8 changed files with 40 additions and 39 deletions

View File

@ -89,30 +89,30 @@ Emulator::Emulator(const String& executable_path, const Vector<String>& argument
setup_signal_trampoline();
}
Vector<AuxiliaryValue> Emulator::generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, String executable_path, int executable_fd) const
Vector<ELF::AuxiliaryValue> Emulator::generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, String executable_path, int executable_fd) const
{
// FIXME: This is not fully compatible with the auxiliary vector the kernel generates, this is just the bare
// minimum to get the loader going.
Vector<AuxiliaryValue> auxv;
Vector<ELF::AuxiliaryValue> auxv;
// PHDR/EXECFD
// PH*
auxv.append({ AuxiliaryValue::PageSize, PAGE_SIZE });
auxv.append({ AuxiliaryValue::BaseAddress, (void*)load_base });
auxv.append({ ELF::AuxiliaryValue::PageSize, PAGE_SIZE });
auxv.append({ ELF::AuxiliaryValue::BaseAddress, (void*)load_base });
auxv.append({ AuxiliaryValue::Entry, (void*)entry_eip });
auxv.append({ ELF::AuxiliaryValue::Entry, (void*)entry_eip });
// FIXME: Don't hard code this? We might support other platforms later.. (e.g. x86_64)
auxv.append({ AuxiliaryValue::Platform, "i386" });
auxv.append({ ELF::AuxiliaryValue::Platform, "i386" });
auxv.append({ AuxiliaryValue::ExecFilename, executable_path });
auxv.append({ ELF::AuxiliaryValue::ExecFilename, executable_path });
auxv.append({ AuxiliaryValue::ExecFileDescriptor, executable_fd });
auxv.append({ ELF::AuxiliaryValue::ExecFileDescriptor, executable_fd });
auxv.append({ AuxiliaryValue::Null, 0L });
auxv.append({ ELF::AuxiliaryValue::Null, 0L });
return auxv;
}
void Emulator::setup_stack(Vector<AuxiliaryValue> aux_vector)
void Emulator::setup_stack(Vector<ELF::AuxiliaryValue> aux_vector)
{
auto stack_region = make<SimpleRegion>(stack_location, stack_size);
stack_region->set_stack(true);

View File

@ -76,8 +76,8 @@ private:
OwnPtr<MallocTracer> m_malloc_tracer;
void setup_stack(Vector<AuxiliaryValue>);
Vector<AuxiliaryValue> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, String executable_path, int executable_fd) const;
void setup_stack(Vector<ELF::AuxiliaryValue>);
Vector<ELF::AuxiliaryValue> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, String executable_path, int executable_fd) const;
void register_signal_handlers();
void setup_signal_trampoline();

View File

@ -534,7 +534,7 @@ private:
ssize_t do_write(FileDescription&, const UserOrKernelBuffer&, size_t);
KResultOr<NonnullRefPtr<FileDescription>> find_elf_interpreter_for_executable(const String& path, char (&first_page)[PAGE_SIZE], int nread, size_t file_size);
Vector<AuxiliaryValue> generate_auxiliary_vector() const;
Vector<ELF::AuxiliaryValue> generate_auxiliary_vector() const;
int alloc_fd(int first_candidate_fd = 0);
void disown_all_shared_buffers();

View File

@ -424,41 +424,41 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
return 0;
}
Vector<AuxiliaryValue> Process::generate_auxiliary_vector() const
Vector<ELF::AuxiliaryValue> Process::generate_auxiliary_vector() const
{
Vector<AuxiliaryValue> auxv;
Vector<ELF::AuxiliaryValue> auxv;
// PHDR/EXECFD
// PH*
auxv.append({ AuxiliaryValue::PageSize, PAGE_SIZE });
auxv.append({ AuxiliaryValue::BaseAddress, (void*)m_load_base });
auxv.append({ ELF::AuxiliaryValue::PageSize, PAGE_SIZE });
auxv.append({ ELF::AuxiliaryValue::BaseAddress, (void*)m_load_base });
auxv.append({ AuxiliaryValue::Entry, (void*)m_entry_eip });
auxv.append({ ELF::AuxiliaryValue::Entry, (void*)m_entry_eip });
// NOTELF
auxv.append({ AuxiliaryValue::Uid, (long)m_uid });
auxv.append({ AuxiliaryValue::EUid, (long)m_euid });
auxv.append({ AuxiliaryValue::Gid, (long)m_gid });
auxv.append({ AuxiliaryValue::EGid, (long)m_egid });
auxv.append({ ELF::AuxiliaryValue::Uid, (long)m_uid });
auxv.append({ ELF::AuxiliaryValue::EUid, (long)m_euid });
auxv.append({ ELF::AuxiliaryValue::Gid, (long)m_gid });
auxv.append({ ELF::AuxiliaryValue::EGid, (long)m_egid });
// FIXME: Don't hard code this? We might support other platforms later.. (e.g. x86_64)
auxv.append({ AuxiliaryValue::Platform, "i386" });
auxv.append({ ELF::AuxiliaryValue::Platform, "i386" });
// FIXME: This is platform specific
auxv.append({ AuxiliaryValue::HwCap, (long)CPUID(1).edx() });
auxv.append({ ELF::AuxiliaryValue::HwCap, (long)CPUID(1).edx() });
auxv.append({ AuxiliaryValue::ClockTick, (long)TimeManagement::the().ticks_per_second() });
auxv.append({ ELF::AuxiliaryValue::ClockTick, (long)TimeManagement::the().ticks_per_second() });
// FIXME: Also take into account things like extended filesystem permissions? That's what linux does...
auxv.append({ AuxiliaryValue::Secure, ((m_uid != m_euid) || (m_gid != m_egid)) ? 1 : 0 });
auxv.append({ ELF::AuxiliaryValue::Secure, ((m_uid != m_euid) || (m_gid != m_egid)) ? 1 : 0 });
char random_bytes[16] {};
get_fast_random_bytes((u8*)random_bytes, sizeof(random_bytes));
auxv.append({ AuxiliaryValue::Random, String(random_bytes, sizeof(random_bytes)) });
auxv.append({ ELF::AuxiliaryValue::Random, String(random_bytes, sizeof(random_bytes)) });
auxv.append({ AuxiliaryValue::ExecFilename, m_executable->absolute_path() });
auxv.append({ ELF::AuxiliaryValue::ExecFilename, m_executable->absolute_path() });
auxv.append({ AuxiliaryValue::ExecFileDescriptor, m_main_program_fd });
auxv.append({ ELF::AuxiliaryValue::ExecFileDescriptor, m_main_program_fd });
auxv.append({ AuxiliaryValue::Null, 0L });
auxv.append({ ELF::AuxiliaryValue::Null, 0L });
return auxv;
}

View File

@ -855,7 +855,7 @@ RegisterState& Thread::get_register_dump_from_stack()
return *(RegisterState*)(kernel_stack_top() - sizeof(RegisterState));
}
KResultOr<u32> Thread::make_userspace_stack_for_main_thread(Vector<String> arguments, Vector<String> environment, Vector<AuxiliaryValue> auxiliary_values)
KResultOr<u32> Thread::make_userspace_stack_for_main_thread(Vector<String> arguments, Vector<String> environment, Vector<ELF::AuxiliaryValue> auxiliary_values)
{
auto* region = m_process->allocate_region(VirtualAddress(), default_userspace_stack_size, "Stack (Main thread)", PROT_READ | PROT_WRITE, false);
if (!region)

View File

@ -975,7 +975,7 @@ public:
void set_default_signal_dispositions();
bool push_value_on_stack(FlatPtr);
KResultOr<u32> make_userspace_stack_for_main_thread(Vector<String> arguments, Vector<String> environment, Vector<AuxiliaryValue>);
KResultOr<u32> make_userspace_stack_for_main_thread(Vector<String> arguments, Vector<String> environment, Vector<ELF::AuxiliaryValue>);
KResult make_thread_specific_region(Badge<Process>);

View File

@ -26,6 +26,9 @@
#pragma once
#include <AK/String.h>
#include <AK/Types.h>
/* Auxiliary Vector types, from Intel386 ABI ver 1.0 section 2.3.3 */
typedef struct
{
@ -63,9 +66,7 @@ typedef struct
#define AT_EXE_BASE 32 /* a_ptr holds base address where main program was loaded into memory */
#define AT_EXE_SIZE 33 /* a_val holds the size of the main program in memory */
#ifdef __cplusplus
# include <AK/String.h>
# include <AK/Types.h>
namespace ELF {
struct AuxiliaryValue {
enum Type {
@ -117,4 +118,4 @@ struct AuxiliaryValue {
String optional_string;
};
#endif /* __cplusplus */
}

View File

@ -84,7 +84,7 @@ static void perform_self_relocations(auxv_t* auxvp)
FlatPtr base_address = 0;
bool found_base_address = false;
for (; auxvp->a_type != AT_NULL; ++auxvp) {
if (auxvp->a_type == AuxiliaryValue::BaseAddress) {
if (auxvp->a_type == ELF::AuxiliaryValue::BaseAddress) {
base_address = auxvp->a_un.a_val;
found_base_address = true;
}
@ -255,10 +255,10 @@ static FlatPtr loader_main(auxv_t* auxvp)
int main_program_fd = -1;
String main_program_name;
for (; auxvp->a_type != AT_NULL; ++auxvp) {
if (auxvp->a_type == AuxiliaryValue::ExecFileDescriptor) {
if (auxvp->a_type == ELF::AuxiliaryValue::ExecFileDescriptor) {
main_program_fd = auxvp->a_un.a_val;
}
if (auxvp->a_type == AuxiliaryValue::ExecFilename) {
if (auxvp->a_type == ELF::AuxiliaryValue::ExecFilename) {
main_program_name = (const char*)auxvp->a_un.a_ptr;
}
}