mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
4aec3f4ef9
The LibELF validate_program_headers method tried to do too many things at once, and as a result, we had an awkward return type from it. To be able to simplify it, we no longer allow passing a StringBuilder* but instead we require to pass an Optional<Elf_Phdr> by reference so it could be filled with actual ELF program header that corresponds to an INTERP header if such found. As a result, we ensure that only certain implementations that actually care about the ELF interpreter path will actually try to load it on their own and if they fail, they can have better diagnostics for an invalid INTERP header. This change also fixes a bug that on which we failed to execute an ELF program if the INTERP header is located outside the first 4KiB page of the ELF file, as the kernel previously didn't have support for looking beyond that for that header.
17 lines
541 B
C++
17 lines
541 B
C++
/*
|
|
* Copyright (c) 2020, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/StringBuilder.h>
|
|
#include <LibELF/ELFABI.h>
|
|
|
|
namespace ELF {
|
|
|
|
bool validate_elf_header(Elf_Ehdr const& elf_header, size_t file_size, bool verbose = true);
|
|
bool validate_program_headers(Elf_Ehdr const& elf_header, size_t file_size, ReadonlyBytes buffer, Optional<Elf_Phdr>& interpreter_path_header_index, Optional<size_t>* requested_stack_size = nullptr, bool verbose = true);
|
|
|
|
} // end namespace ELF
|