mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 01:04:38 +03:00
LibELF: Refactor coredump notes section structures
This commit is contained in:
parent
f12e13e81c
commit
349c6780ce
Notes:
sideshowbarker
2024-07-19 00:50:59 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/349c6780ce8 Pull-request: https://github.com/SerenityOS/serenity/pull/3738 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
@ -198,14 +198,12 @@ ByteBuffer CoreDump::create_notes_threads_data() const
|
||||
|
||||
m_process.for_each_thread([&](Thread& thread) {
|
||||
ByteBuffer entry_buff;
|
||||
ELF::Core::NotesEntry entry {};
|
||||
entry.type = ELF::Core::NotesEntry::Type::ThreadInfo;
|
||||
|
||||
ELF::Core::ThreadInfo info {};
|
||||
info.header.type = ELF::Core::NotesEntryHeader::Type::ThreadInfo;
|
||||
info.tid = thread.tid().value();
|
||||
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));
|
||||
|
||||
threads_data += entry_buff;
|
||||
@ -219,16 +217,15 @@ ByteBuffer CoreDump::create_notes_regions_data() const
|
||||
{
|
||||
ByteBuffer regions_data;
|
||||
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;
|
||||
ELF::Core::MemoryRegionInfo info {};
|
||||
info.header.type = ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo;
|
||||
|
||||
auto& region = m_process.m_regions[region_index];
|
||||
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_start = info.program_header_index;
|
||||
info.program_header_index = region_index;
|
||||
|
||||
memory_region_info_buffer.append((void*)&info, sizeof(info));
|
||||
|
||||
@ -237,7 +234,6 @@ ByteBuffer CoreDump::create_notes_regions_data() const
|
||||
name = String::empty();
|
||||
memory_region_info_buffer.append(name.characters(), name.length() + 1);
|
||||
|
||||
regions_data.append((void*)&entry, sizeof(entry));
|
||||
regions_data += memory_region_info_buffer;
|
||||
}
|
||||
return regions_data;
|
||||
@ -250,8 +246,8 @@ ByteBuffer CoreDump::create_notes_segment_data() const
|
||||
notes_buffer += create_notes_threads_data();
|
||||
notes_buffer += create_notes_regions_data();
|
||||
|
||||
ELF::Core::NotesEntry null_entry {};
|
||||
null_entry.type = ELF::Core::NotesEntry::Type::Null;
|
||||
ELF::Core::NotesEntryHeader null_entry {};
|
||||
null_entry.type = ELF::Core::NotesEntryHeader::Type::Null;
|
||||
notes_buffer.append(&null_entry, sizeof(null_entry));
|
||||
|
||||
return notes_buffer;
|
||||
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Kernel/Forward.h>
|
||||
|
@ -25,12 +25,13 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <LibC/sys/arch/i386/regs.h>
|
||||
|
||||
namespace ELF::Core {
|
||||
|
||||
struct [[gnu::packed]] NotesEntry
|
||||
struct [[gnu::packed]] NotesEntryHeader
|
||||
{
|
||||
enum Type : u8 {
|
||||
Null = 0, // Terminates segment
|
||||
@ -38,21 +39,28 @@ struct [[gnu::packed]] NotesEntry
|
||||
MemoryRegionInfo,
|
||||
};
|
||||
Type type;
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] NotesEntry
|
||||
{
|
||||
NotesEntryHeader header;
|
||||
char data[];
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] ThreadInfo
|
||||
{
|
||||
NotesEntryHeader header;
|
||||
int tid;
|
||||
PtraceRegisters regs;
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] MemoryRegionInfo
|
||||
{
|
||||
uint32_t region_start {};
|
||||
NotesEntryHeader header;
|
||||
uint32_t region_start;
|
||||
uint32_t region_end;
|
||||
uint16_t program_header_index;
|
||||
char file_name[];
|
||||
char region_name[]; // Null terminated
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user