1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 16:47:42 +00:00

LibELF: Refactor coredump notes section structures

This commit is contained in:
Itamar 2020-11-11 22:02:39 +02:00 committed by Andreas Kling
parent f12e13e81c
commit 349c6780ce
3 changed files with 17 additions and 12 deletions

View file

@ -198,14 +198,12 @@ ByteBuffer CoreDump::create_notes_threads_data() const
m_process.for_each_thread([&](Thread& thread) { m_process.for_each_thread([&](Thread& thread) {
ByteBuffer entry_buff; ByteBuffer entry_buff;
ELF::Core::NotesEntry entry {};
entry.type = ELF::Core::NotesEntry::Type::ThreadInfo;
ELF::Core::ThreadInfo info {}; ELF::Core::ThreadInfo info {};
info.header.type = ELF::Core::NotesEntryHeader::Type::ThreadInfo;
info.tid = thread.tid().value(); info.tid = thread.tid().value();
Ptrace::copy_kernel_registers_into_ptrace_registers(info.regs, thread.get_register_dump_from_stack()); Ptrace::copy_kernel_registers_into_ptrace_registers(info.regs, thread.get_register_dump_from_stack());
entry_buff.append((void*)&entry, sizeof(entry));
entry_buff.append((void*)&info, sizeof(info)); entry_buff.append((void*)&info, sizeof(info));
threads_data += entry_buff; threads_data += entry_buff;
@ -219,16 +217,15 @@ ByteBuffer CoreDump::create_notes_regions_data() const
{ {
ByteBuffer regions_data; ByteBuffer regions_data;
for (size_t region_index = 0; region_index < m_process.m_regions.size(); ++region_index) { for (size_t region_index = 0; region_index < m_process.m_regions.size(); ++region_index) {
ELF::Core::NotesEntry entry {};
entry.type = ELF::Core::NotesEntry::Type::MemoryRegionInfo;
ByteBuffer memory_region_info_buffer; ByteBuffer memory_region_info_buffer;
ELF::Core::MemoryRegionInfo info {}; ELF::Core::MemoryRegionInfo info {};
info.header.type = ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo;
auto& region = m_process.m_regions[region_index]; auto& region = m_process.m_regions[region_index];
info.region_start = reinterpret_cast<uint32_t>(region.vaddr().as_ptr()); info.region_start = reinterpret_cast<uint32_t>(region.vaddr().as_ptr());
info.region_end = reinterpret_cast<uint32_t>(region.vaddr().as_ptr() + region.size()); info.region_end = reinterpret_cast<uint32_t>(region.vaddr().as_ptr() + region.size());
info.region_start = info.program_header_index; info.program_header_index = region_index;
memory_region_info_buffer.append((void*)&info, sizeof(info)); memory_region_info_buffer.append((void*)&info, sizeof(info));
@ -237,7 +234,6 @@ ByteBuffer CoreDump::create_notes_regions_data() const
name = String::empty(); name = String::empty();
memory_region_info_buffer.append(name.characters(), name.length() + 1); memory_region_info_buffer.append(name.characters(), name.length() + 1);
regions_data.append((void*)&entry, sizeof(entry));
regions_data += memory_region_info_buffer; regions_data += memory_region_info_buffer;
} }
return regions_data; return regions_data;
@ -250,8 +246,8 @@ ByteBuffer CoreDump::create_notes_segment_data() const
notes_buffer += create_notes_threads_data(); notes_buffer += create_notes_threads_data();
notes_buffer += create_notes_regions_data(); notes_buffer += create_notes_regions_data();
ELF::Core::NotesEntry null_entry {}; ELF::Core::NotesEntryHeader null_entry {};
null_entry.type = ELF::Core::NotesEntry::Type::Null; null_entry.type = ELF::Core::NotesEntryHeader::Type::Null;
notes_buffer.append(&null_entry, sizeof(null_entry)); notes_buffer.append(&null_entry, sizeof(null_entry));
return notes_buffer; return notes_buffer;

View file

@ -26,6 +26,7 @@
*/ */
#pragma once #pragma once
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <Kernel/Forward.h> #include <Kernel/Forward.h>

View file

@ -25,12 +25,13 @@
*/ */
#pragma once #pragma once
#include <AK/Types.h> #include <AK/Types.h>
#include <LibC/sys/arch/i386/regs.h> #include <LibC/sys/arch/i386/regs.h>
namespace ELF::Core { namespace ELF::Core {
struct [[gnu::packed]] NotesEntry struct [[gnu::packed]] NotesEntryHeader
{ {
enum Type : u8 { enum Type : u8 {
Null = 0, // Terminates segment Null = 0, // Terminates segment
@ -38,21 +39,28 @@ struct [[gnu::packed]] NotesEntry
MemoryRegionInfo, MemoryRegionInfo,
}; };
Type type; Type type;
};
struct [[gnu::packed]] NotesEntry
{
NotesEntryHeader header;
char data[]; char data[];
}; };
struct [[gnu::packed]] ThreadInfo struct [[gnu::packed]] ThreadInfo
{ {
NotesEntryHeader header;
int tid; int tid;
PtraceRegisters regs; PtraceRegisters regs;
}; };
struct [[gnu::packed]] MemoryRegionInfo struct [[gnu::packed]] MemoryRegionInfo
{ {
uint32_t region_start {}; NotesEntryHeader header;
uint32_t region_start;
uint32_t region_end; uint32_t region_end;
uint16_t program_header_index; uint16_t program_header_index;
char file_name[]; char region_name[]; // Null terminated
}; };
} }