2020-11-06 11:09:51 +03:00
|
|
|
/*
|
2021-04-28 23:46:44 +03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-11-06 11:09:51 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-06 11:09:51 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-11-11 23:02:39 +03:00
|
|
|
|
2020-11-06 11:09:51 +03:00
|
|
|
#include <AK/Types.h>
|
2023-04-29 21:37:40 +03:00
|
|
|
#include <sys/arch/regs.h>
|
2020-11-06 11:09:51 +03:00
|
|
|
|
2022-02-16 00:13:41 +03:00
|
|
|
#ifndef KERNEL
|
2022-12-04 21:02:33 +03:00
|
|
|
# include <AK/DeprecatedString.h>
|
2022-02-16 00:13:41 +03:00
|
|
|
#endif
|
|
|
|
|
2020-11-06 11:09:51 +03:00
|
|
|
namespace ELF::Core {
|
|
|
|
|
2020-12-31 00:44:54 +03:00
|
|
|
struct [[gnu::packed]] NotesEntryHeader {
|
2020-11-06 11:09:51 +03:00
|
|
|
enum Type : u8 {
|
|
|
|
Null = 0, // Terminates segment
|
2020-12-30 15:18:32 +03:00
|
|
|
ProcessInfo,
|
2020-11-06 11:09:51 +03:00
|
|
|
ThreadInfo,
|
|
|
|
MemoryRegionInfo,
|
2020-12-30 17:06:33 +03:00
|
|
|
Metadata,
|
2020-11-06 11:09:51 +03:00
|
|
|
};
|
|
|
|
Type type;
|
2020-11-11 23:02:39 +03:00
|
|
|
};
|
|
|
|
|
2020-12-31 00:44:54 +03:00
|
|
|
struct [[gnu::packed]] NotesEntry {
|
2020-11-11 23:02:39 +03:00
|
|
|
NotesEntryHeader header;
|
2020-11-06 11:09:51 +03:00
|
|
|
char data[];
|
|
|
|
};
|
|
|
|
|
2020-12-31 00:44:54 +03:00
|
|
|
struct [[gnu::packed]] ProcessInfo {
|
2020-12-30 15:18:32 +03:00
|
|
|
NotesEntryHeader header;
|
2021-01-14 01:59:22 +03:00
|
|
|
// Information is stored as JSON blob to allow arbitrary
|
|
|
|
// number and length of strings/objects/arrays.
|
|
|
|
//
|
|
|
|
// Keys:
|
|
|
|
// - "pid" (int)
|
|
|
|
// - "termination_signal" (u8)
|
2022-12-04 21:02:33 +03:00
|
|
|
// - "executable_path" (DeprecatedString)
|
|
|
|
// - "arguments" (Vector<DeprecatedString>)
|
|
|
|
// - "environment" (Vector<DeprecatedString>)
|
2021-01-14 01:59:22 +03:00
|
|
|
char json_data[]; // Null terminated
|
2020-12-30 15:18:32 +03:00
|
|
|
};
|
|
|
|
|
2020-12-31 00:44:54 +03:00
|
|
|
struct [[gnu::packed]] ThreadInfo {
|
2020-11-11 23:02:39 +03:00
|
|
|
NotesEntryHeader header;
|
2020-11-06 11:09:51 +03:00
|
|
|
int tid;
|
|
|
|
PtraceRegisters regs;
|
|
|
|
};
|
|
|
|
|
2020-12-31 00:44:54 +03:00
|
|
|
struct [[gnu::packed]] MemoryRegionInfo {
|
2020-11-11 23:02:39 +03:00
|
|
|
NotesEntryHeader header;
|
2021-07-22 01:47:30 +03:00
|
|
|
uint64_t region_start;
|
|
|
|
uint64_t region_end;
|
2020-11-06 11:09:51 +03:00
|
|
|
uint16_t program_header_index;
|
2020-11-11 23:02:39 +03:00
|
|
|
char region_name[]; // Null terminated
|
2020-12-29 15:02:36 +03:00
|
|
|
|
2022-02-16 00:13:41 +03:00
|
|
|
#ifndef KERNEL
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString object_name() const
|
2020-12-29 15:02:36 +03:00
|
|
|
{
|
2022-07-11 20:32:29 +03:00
|
|
|
StringView memory_region_name { region_name, strlen(region_name) };
|
|
|
|
if (memory_region_name.contains("Loader.so"sv))
|
|
|
|
return "Loader.so"sv;
|
2021-07-01 19:12:21 +03:00
|
|
|
auto maybe_colon_index = memory_region_name.find(':');
|
|
|
|
if (!maybe_colon_index.has_value())
|
2020-12-29 15:02:36 +03:00
|
|
|
return {};
|
2022-12-06 04:12:49 +03:00
|
|
|
return memory_region_name.substring_view(0, *maybe_colon_index).to_deprecated_string();
|
2020-12-29 15:02:36 +03:00
|
|
|
}
|
2022-02-16 00:13:41 +03:00
|
|
|
#endif
|
2020-11-06 11:09:51 +03:00
|
|
|
};
|
|
|
|
|
2020-12-31 00:44:54 +03:00
|
|
|
struct [[gnu::packed]] Metadata {
|
2020-12-30 17:06:33 +03:00
|
|
|
NotesEntryHeader header;
|
2021-01-14 01:59:22 +03:00
|
|
|
// Arbitrary metadata, set via SC_set_coredump_metadata.
|
|
|
|
// Limited to 16 entries and 16 KiB keys/values by the kernel.
|
|
|
|
//
|
|
|
|
// Well-known keys:
|
|
|
|
// - "assertion": Used by LibC's __assertion_failed() to store assertion info
|
2021-12-29 11:10:17 +03:00
|
|
|
// - "pledge_violation": Used by the Kernel's require_promise() to store pledge violation info
|
2020-12-30 17:06:33 +03:00
|
|
|
char json_data[]; // Null terminated
|
|
|
|
};
|
|
|
|
|
2020-11-06 11:09:51 +03:00
|
|
|
}
|