diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-25 15:44:07 +0200 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-26 02:37:03 +0200 |
commit | 8cf0e4a5e4f7c0c3455e619fe105f9d270dfd3fe (patch) | |
tree | 6d5dc4663dff54dbeef41dd920e2a2c5b3955045 | |
parent | a6f0ab358ad68bd4350d31423c379d4a8c198dce (diff) | |
download | serenity-8cf0e4a5e4f7c0c3455e619fe105f9d270dfd3fe.zip |
Kernel: Eliminate allocations from generate_auxiliary_vector
-rw-r--r-- | Kernel/Syscalls/execve.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 189a6746ba..4a67aee041 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -40,7 +40,8 @@ struct LoadResult { WeakPtr<Memory::Region> stack_region; }; -static Vector<ELF::AuxiliaryValue> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, UserID uid, UserID euid, GroupID gid, GroupID egid, StringView executable_path, Optional<Process::ScopedDescriptionAllocation> const& main_program_fd_allocation); +static constexpr size_t auxiliary_vector_size = 15; +static Array<ELF::AuxiliaryValue, auxiliary_vector_size> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, UserID uid, UserID euid, GroupID gid, GroupID egid, StringView executable_path, Optional<Process::ScopedDescriptionAllocation> const& main_program_fd_allocation); static bool validate_stack_size(NonnullOwnPtrVector<KString> const& arguments, NonnullOwnPtrVector<KString>& environment) { @@ -69,7 +70,7 @@ static bool validate_stack_size(NonnullOwnPtrVector<KString> const& arguments, N } static ErrorOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Memory::Region& region, NonnullOwnPtrVector<KString> const& arguments, - NonnullOwnPtrVector<KString> const& environment, Vector<ELF::AuxiliaryValue> auxiliary_values) + NonnullOwnPtrVector<KString> const& environment, Array<ELF::AuxiliaryValue, auxiliary_vector_size> auxiliary_values) { FlatPtr new_sp = region.range().end().get(); @@ -637,39 +638,38 @@ ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_d return {}; } -static Vector<ELF::AuxiliaryValue> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, UserID uid, UserID euid, GroupID gid, GroupID egid, StringView executable_path, Optional<Process::ScopedDescriptionAllocation> const& main_program_fd_allocation) +static Array<ELF::AuxiliaryValue, auxiliary_vector_size> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, UserID uid, UserID euid, GroupID gid, GroupID egid, StringView executable_path, Optional<Process::ScopedDescriptionAllocation> const& main_program_fd_allocation) { - Vector<ELF::AuxiliaryValue> auxv; - // PHDR/EXECFD - // PH* - auxv.append({ ELF::AuxiliaryValue::PageSize, PAGE_SIZE }); - auxv.append({ ELF::AuxiliaryValue::BaseAddress, (void*)load_base }); + return { { + // PHDR/EXECFD + // PH* + { ELF::AuxiliaryValue::PageSize, PAGE_SIZE }, + { ELF::AuxiliaryValue::BaseAddress, (void*)load_base }, - auxv.append({ ELF::AuxiliaryValue::Entry, (void*)entry_eip }); - // NOTELF - auxv.append({ ELF::AuxiliaryValue::Uid, (long)uid.value() }); - auxv.append({ ELF::AuxiliaryValue::EUid, (long)euid.value() }); - auxv.append({ ELF::AuxiliaryValue::Gid, (long)gid.value() }); - auxv.append({ ELF::AuxiliaryValue::EGid, (long)egid.value() }); + { ELF::AuxiliaryValue::Entry, (void*)entry_eip }, + // NOTELF + { ELF::AuxiliaryValue::Uid, (long)uid.value() }, + { ELF::AuxiliaryValue::EUid, (long)euid.value() }, + { ELF::AuxiliaryValue::Gid, (long)gid.value() }, + { ELF::AuxiliaryValue::EGid, (long)egid.value() }, - auxv.append({ ELF::AuxiliaryValue::Platform, Processor::platform_string() }); - // FIXME: This is platform specific - auxv.append({ ELF::AuxiliaryValue::HwCap, (long)CPUID(1).edx() }); + { ELF::AuxiliaryValue::Platform, Processor::platform_string() }, + // FIXME: This is platform specific + { ELF::AuxiliaryValue::HwCap, (long)CPUID(1).edx() }, - auxv.append({ ELF::AuxiliaryValue::ClockTick, (long)TimeManagement::the().ticks_per_second() }); + { 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({ ELF::AuxiliaryValue::Secure, ((uid != euid) || (gid != egid)) ? 1 : 0 }); + // FIXME: Also take into account things like extended filesystem permissions? That's what linux does... + { ELF::AuxiliaryValue::Secure, ((uid != euid) || (gid != egid)) ? 1 : 0 }, - auxv.append({ ELF::AuxiliaryValue::Random, nullptr }); + { ELF::AuxiliaryValue::Random, nullptr }, - auxv.append({ ELF::AuxiliaryValue::ExecFilename, executable_path }); + { ELF::AuxiliaryValue::ExecFilename, executable_path }, - if (main_program_fd_allocation.has_value()) - auxv.append({ ELF::AuxiliaryValue::ExecFileDescriptor, main_program_fd_allocation->fd }); + main_program_fd_allocation.has_value() ? ELF::AuxiliaryValue { ELF::AuxiliaryValue::ExecFileDescriptor, main_program_fd_allocation->fd } : ELF::AuxiliaryValue { ELF::AuxiliaryValue::Ignore, 0L }, - auxv.append({ ELF::AuxiliaryValue::Null, 0L }); - return auxv; + { ELF::AuxiliaryValue::Null, 0L }, + } }; } static ErrorOr<NonnullOwnPtrVector<KString>> find_shebang_interpreter_for_executable(char const first_page[], size_t nread) |