code_set.h 2.2 KB

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