[boot] Go back to loading symbol table in boot

The symbol table needs to be passed to the panic handler very early in
the kernel, loading it in init is far less useful. Return it to the boot
directory and remove it from the initrd.
This commit is contained in:
Justin C. Miller
2023-02-04 00:00:59 -08:00
parent 86d458fc6c
commit aba45b9b67
11 changed files with 50 additions and 79 deletions

View File

@@ -2,12 +2,13 @@
#include <stddef.h>
#include <stdint.h>
#include <util/counted.h>
#include <util/pointers.h>
namespace elf {
struct file_header;
struct program_header;
struct segment_header;
struct section_header;
template <typename T>
@@ -37,9 +38,8 @@ class file
{
public:
/// Constructor: Create an elf object out of ELF data in memory
/// \arg data The ELF data to read
/// \arg size Size of the ELF data, in bytes
file(const void *data, size_t size);
/// \arg data A const_buffer pointing at the ELF data
file(util::const_buffer data);
/// Check the validity of the ELF data
/// \returns true for valid ELF data
@@ -51,25 +51,24 @@ public:
/// Get the base address of the program in memory
inline uintptr_t base() const {
return reinterpret_cast<uintptr_t>(m_data);
return reinterpret_cast<uintptr_t>(m_data.pointer);
}
/// Get the ELF program headers
inline const subheaders<program_header> & programs() const { return m_programs; }
/// Get the ELF segment headers
inline const subheaders<segment_header> & segments() const { return m_segments; }
/// Get the ELF section headers
inline const subheaders<section_header> & sections() const { return m_sections; }
inline const file_header * header() const {
return reinterpret_cast<const file_header *>(m_data);
return reinterpret_cast<const file_header *>(m_data.pointer);
}
private:
subheaders<program_header> m_programs;
subheaders<segment_header> m_segments;
subheaders<section_header> m_sections;
const void *m_data;
size_t m_size;
util::const_buffer m_data;
};
}

View File

@@ -63,7 +63,7 @@ enum class segment_flags : uint32_t
};
is_bitfield(segment_flags);
struct program_header
struct segment_header
{
segment_type type;
segment_flags flags;

View File

@@ -5,25 +5,24 @@ static const uint32_t expected_magic = 0x464c457f; // "\x7f" "ELF"
namespace elf {
inline const file_header * fh(const void *data) { return reinterpret_cast<const file_header*>(data); }
inline const file_header * fh(util::const_buffer data) { return reinterpret_cast<const file_header*>(data.pointer); }
template <typename T>
const T *convert(const void *data, size_t offset) {
return reinterpret_cast<const T*>(util::offset_pointer(data, offset));
const T *convert(util::const_buffer data, size_t offset) {
return reinterpret_cast<const T*>(util::offset_pointer(data.pointer, offset));
}
file::file(const void *data, size_t size) :
m_programs(convert<program_header>(data, fh(data)->ph_offset), fh(data)->ph_entsize, fh(data)->ph_num),
file::file(util::const_buffer data) :
m_segments(convert<segment_header>(data, fh(data)->ph_offset), fh(data)->ph_entsize, fh(data)->ph_num),
m_sections(convert<section_header>(data, fh(data)->sh_offset), fh(data)->sh_entsize, fh(data)->sh_num),
m_data(data),
m_size(size)
m_data(data)
{
}
bool
file::valid() const
{
if (m_size < sizeof(file_header))
if (m_data.count < sizeof(file_header))
return false;
const file_header *fheader = header();