code_set.h 2.2 KB

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