CoreDump.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Types.h>
  9. #include <LibC/sys/arch/i386/regs.h>
  10. namespace ELF::Core {
  11. struct [[gnu::packed]] NotesEntryHeader {
  12. enum Type : u8 {
  13. Null = 0, // Terminates segment
  14. ProcessInfo,
  15. ThreadInfo,
  16. MemoryRegionInfo,
  17. Metadata,
  18. };
  19. Type type;
  20. };
  21. struct [[gnu::packed]] NotesEntry {
  22. NotesEntryHeader header;
  23. char data[];
  24. };
  25. struct [[gnu::packed]] ProcessInfo {
  26. NotesEntryHeader header;
  27. // Information is stored as JSON blob to allow arbitrary
  28. // number and length of strings/objects/arrays.
  29. //
  30. // Keys:
  31. // - "pid" (int)
  32. // - "termination_signal" (u8)
  33. // - "executable_path" (String)
  34. // - "arguments" (Vector<String>)
  35. // - "environment" (Vector<String>)
  36. char json_data[]; // Null terminated
  37. };
  38. struct [[gnu::packed]] ThreadInfo {
  39. NotesEntryHeader header;
  40. int tid;
  41. PtraceRegisters regs;
  42. };
  43. struct [[gnu::packed]] MemoryRegionInfo {
  44. NotesEntryHeader header;
  45. uint32_t region_start;
  46. uint32_t region_end;
  47. uint16_t program_header_index;
  48. char region_name[]; // Null terminated
  49. String object_name() const
  50. {
  51. StringView memory_region_name { region_name };
  52. if (memory_region_name.contains("Loader.so"))
  53. return "Loader.so";
  54. auto maybe_colon_index = memory_region_name.find(':');
  55. if (!maybe_colon_index.has_value())
  56. return {};
  57. return memory_region_name.substring_view(0, *maybe_colon_index).to_string();
  58. }
  59. };
  60. struct [[gnu::packed]] Metadata {
  61. NotesEntryHeader header;
  62. // Arbitrary metadata, set via SC_set_coredump_metadata.
  63. // Limited to 16 entries and 16 KiB keys/values by the kernel.
  64. //
  65. // Well-known keys:
  66. // - "assertion": Used by LibC's __assertion_failed() to store assertion info
  67. // - "pledge_violation": Used by the Kernel's REQUIRE_PROMISE() to store pledge violation info
  68. char json_data[]; // Null terminated
  69. };
  70. }