process.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <bitset>
  6. #include <boost/container/static_vector.hpp>
  7. #include "common/bit_field.h"
  8. #include "common/common_types.h"
  9. #include "core/hle/kernel/kernel.h"
  10. #include "core/hle/result.h"
  11. namespace Kernel {
  12. struct AddressMapping {
  13. // Address and size must be page-aligned
  14. VAddr address;
  15. u32 size;
  16. bool writable;
  17. bool unk_flag;
  18. };
  19. enum class MemoryRegion : u16 {
  20. APPLICATION = 1,
  21. SYSTEM = 2,
  22. BASE = 3,
  23. };
  24. union ProcessFlags {
  25. u16 raw;
  26. BitField< 0, 1, u16> allow_debug; ///< Allows other processes to attach to and debug this process.
  27. BitField< 1, 1, u16> force_debug; ///< Allows this process to attach to processes even if they don't have allow_debug set.
  28. BitField< 2, 1, u16> allow_nonalphanum;
  29. BitField< 3, 1, u16> shared_page_writable; ///< Shared page is mapped with write permissions.
  30. BitField< 4, 1, u16> privileged_priority; ///< Can use priority levels higher than 24.
  31. BitField< 5, 1, u16> allow_main_args;
  32. BitField< 6, 1, u16> shared_device_mem;
  33. BitField< 7, 1, u16> runnable_on_sleep;
  34. BitField< 8, 4, MemoryRegion> memory_region; ///< Default region for memory allocations for this process
  35. BitField<12, 1, u16> loaded_high; ///< Application loaded high (not at 0x00100000).
  36. };
  37. class ResourceLimit;
  38. class Process final : public Object {
  39. public:
  40. static SharedPtr<Process> Create(std::string name, u64 program_id);
  41. std::string GetTypeName() const override { return "Process"; }
  42. std::string GetName() const override { return name; }
  43. static const HandleType HANDLE_TYPE = HandleType::Process;
  44. HandleType GetHandleType() const override { return HANDLE_TYPE; }
  45. static u32 next_process_id;
  46. /// Name of the process
  47. std::string name;
  48. /// Title ID corresponding to the process
  49. u64 program_id;
  50. /// Resource limit descriptor for this process
  51. SharedPtr<ResourceLimit> resource_limit;
  52. /// The process may only call SVCs which have the corresponding bit set.
  53. std::bitset<0x80> svc_access_mask;
  54. /// Maximum size of the handle table for the process.
  55. unsigned int handle_table_size = 0x200;
  56. /// Special memory ranges mapped into this processes address space. This is used to give
  57. /// processes access to specific I/O regions and device memory.
  58. boost::container::static_vector<AddressMapping, 8> address_mappings;
  59. ProcessFlags flags;
  60. /// The id of this process
  61. u32 process_id = next_process_id++;
  62. /// Bitmask of the used TLS slots
  63. std::bitset<300> used_tls_slots;
  64. /**
  65. * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
  66. * to this process.
  67. */
  68. void ParseKernelCaps(const u32* kernel_caps, size_t len);
  69. /**
  70. * Applies address space changes and launches the process main thread.
  71. */
  72. void Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size);
  73. private:
  74. Process();
  75. ~Process() override;
  76. };
  77. extern SharedPtr<Process> g_current_process;
  78. }