code_set.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <cstddef>
  5. #include "common/common_types.h"
  6. #include "core/hle/kernel/physical_memory.h"
  7. namespace Kernel {
  8. /**
  9. * Represents executable data that may be loaded into a kernel process.
  10. *
  11. * A code set consists of three basic segments:
  12. * - A code (AKA text) segment,
  13. * - A read-only data segment (rodata)
  14. * - A data segment
  15. *
  16. * The code segment is the portion of the object file that contains
  17. * executable instructions.
  18. *
  19. * The read-only data segment in the portion of the object file that
  20. * contains (as one would expect) read-only data, such as fixed constant
  21. * values and data structures.
  22. *
  23. * The data segment is similar to the read-only data segment -- it contains
  24. * variables and data structures that have predefined values, however,
  25. * entities within this segment can be modified.
  26. */
  27. struct CodeSet final {
  28. /// A single segment within a code set.
  29. struct Segment final {
  30. /// The byte offset that this segment is located at.
  31. std::size_t offset = 0;
  32. /// The address to map this segment to.
  33. VAddr addr = 0;
  34. /// The size of this segment in bytes.
  35. u32 size = 0;
  36. };
  37. explicit CodeSet();
  38. ~CodeSet();
  39. CodeSet(const CodeSet&) = delete;
  40. CodeSet& operator=(const CodeSet&) = delete;
  41. CodeSet(CodeSet&&) = default;
  42. CodeSet& operator=(CodeSet&&) = default;
  43. Segment& CodeSegment() {
  44. return segments[0];
  45. }
  46. const Segment& CodeSegment() const {
  47. return segments[0];
  48. }
  49. Segment& RODataSegment() {
  50. return segments[1];
  51. }
  52. const Segment& RODataSegment() const {
  53. return segments[1];
  54. }
  55. Segment& DataSegment() {
  56. return segments[2];
  57. }
  58. const Segment& DataSegment() const {
  59. return segments[2];
  60. }
  61. /// The overall data that backs this code set.
  62. Kernel::PhysicalMemory memory;
  63. /// The segments that comprise this code set.
  64. std::array<Segment, 3> segments;
  65. /// The entry point address for this code set.
  66. VAddr entrypoint = 0;
  67. };
  68. } // namespace Kernel