diff options
| author | 2018-03-14 19:33:27 -0400 | |
|---|---|---|
| committer | 2018-03-14 19:33:27 -0400 | |
| commit | cde9386e0fd9677e1a89a8dc81ea9cd65fa22c50 (patch) | |
| tree | 6330442e1dacc0d850ce09c35dcee7ddd3a2bc9d /src | |
| parent | Merge pull request #213 from Hexagon12/dynarmic-default (diff) | |
| parent | core: Move process creation out of global state. (diff) | |
| download | yuzu-cde9386e0fd9677e1a89a8dc81ea9cd65fa22c50.tar.gz yuzu-cde9386e0fd9677e1a89a8dc81ea9cd65fa22c50.tar.xz yuzu-cde9386e0fd9677e1a89a8dc81ea9cd65fa22c50.zip | |
Merge pull request #236 from bunnei/refactor-process-creation
core: Move process creation out of global state.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.cpp | 3 | ||||
| -rw-r--r-- | src/core/core.cpp | 4 | ||||
| -rw-r--r-- | src/core/core.h | 11 | ||||
| -rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/handle_table.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 38 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/ns/pl_u.cpp | 9 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 3 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 1 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 5 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 5 | ||||
| -rw-r--r-- | src/core/memory.cpp | 30 | ||||
| -rw-r--r-- | src/tests/core/arm/arm_test_common.cpp | 4 | ||||
| -rw-r--r-- | src/tests/core/memory/memory.cpp | 8 |
22 files changed, 87 insertions, 72 deletions
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index e7f6bf8c2..4da07b177 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <dynarmic/A64/config.h> | 8 | #include <dynarmic/A64/config.h> |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "core/arm/dynarmic/arm_dynarmic.h" | 10 | #include "core/arm/dynarmic/arm_dynarmic.h" |
| 11 | #include "core/core.h" | ||
| 11 | #include "core/core_timing.h" | 12 | #include "core/core_timing.h" |
| 12 | #include "core/hle/kernel/memory.h" | 13 | #include "core/hle/kernel/memory.h" |
| 13 | #include "core/hle/kernel/svc.h" | 14 | #include "core/hle/kernel/svc.h" |
| @@ -106,7 +107,7 @@ public: | |||
| 106 | }; | 107 | }; |
| 107 | 108 | ||
| 108 | std::unique_ptr<Dynarmic::A64::Jit> MakeJit(const std::unique_ptr<ARM_Dynarmic_Callbacks>& cb) { | 109 | std::unique_ptr<Dynarmic::A64::Jit> MakeJit(const std::unique_ptr<ARM_Dynarmic_Callbacks>& cb) { |
| 109 | const auto page_table = Kernel::g_current_process->vm_manager.page_table.pointers.data(); | 110 | const auto page_table = Core::CurrentProcess()->vm_manager.page_table.pointers.data(); |
| 110 | 111 | ||
| 111 | Dynarmic::A64::UserConfig config; | 112 | Dynarmic::A64::UserConfig config; |
| 112 | config.callbacks = cb.get(); | 113 | config.callbacks = cb.get(); |
diff --git a/src/core/core.cpp b/src/core/core.cpp index 4fb035556..ac6cb9e6e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -100,7 +100,7 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file | |||
| 100 | return init_result; | 100 | return init_result; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | const Loader::ResultStatus load_result{app_loader->Load(Kernel::g_current_process)}; | 103 | const Loader::ResultStatus load_result{app_loader->Load(current_process)}; |
| 104 | if (Loader::ResultStatus::Success != load_result) { | 104 | if (Loader::ResultStatus::Success != load_result) { |
| 105 | LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); | 105 | LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); |
| 106 | System::Shutdown(); | 106 | System::Shutdown(); |
| @@ -141,6 +141,8 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { | |||
| 141 | 141 | ||
| 142 | CoreTiming::Init(); | 142 | CoreTiming::Init(); |
| 143 | 143 | ||
| 144 | current_process = Kernel::Process::Create("main"); | ||
| 145 | |||
| 144 | switch (Settings::values.cpu_core) { | 146 | switch (Settings::values.cpu_core) { |
| 145 | case Settings::CpuCore::Unicorn: | 147 | case Settings::CpuCore::Unicorn: |
| 146 | cpu_core = std::make_shared<ARM_Unicorn>(); | 148 | cpu_core = std::make_shared<ARM_Unicorn>(); |
diff --git a/src/core/core.h b/src/core/core.h index ada23b347..635109b21 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "core/hle/kernel/kernel.h" | ||
| 10 | #include "core/hle/kernel/scheduler.h" | 11 | #include "core/hle/kernel/scheduler.h" |
| 11 | #include "core/loader/loader.h" | 12 | #include "core/loader/loader.h" |
| 12 | #include "core/memory.h" | 13 | #include "core/memory.h" |
| @@ -112,6 +113,10 @@ public: | |||
| 112 | return *scheduler; | 113 | return *scheduler; |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 116 | Kernel::SharedPtr<Kernel::Process>& CurrentProcess() { | ||
| 117 | return current_process; | ||
| 118 | } | ||
| 119 | |||
| 115 | PerfStats perf_stats; | 120 | PerfStats perf_stats; |
| 116 | FrameLimiter frame_limiter; | 121 | FrameLimiter frame_limiter; |
| 117 | 122 | ||
| @@ -149,6 +154,8 @@ private: | |||
| 149 | std::unique_ptr<Kernel::Scheduler> scheduler; | 154 | std::unique_ptr<Kernel::Scheduler> scheduler; |
| 150 | std::unique_ptr<Tegra::GPU> gpu_core; | 155 | std::unique_ptr<Tegra::GPU> gpu_core; |
| 151 | 156 | ||
| 157 | Kernel::SharedPtr<Kernel::Process> current_process; | ||
| 158 | |||
| 152 | /// When true, signals that a reschedule should happen | 159 | /// When true, signals that a reschedule should happen |
| 153 | bool reschedule_pending{}; | 160 | bool reschedule_pending{}; |
| 154 | 161 | ||
| @@ -169,4 +176,8 @@ inline TelemetrySession& Telemetry() { | |||
| 169 | return System::GetInstance().TelemetrySession(); | 176 | return System::GetInstance().TelemetrySession(); |
| 170 | } | 177 | } |
| 171 | 178 | ||
| 179 | inline Kernel::SharedPtr<Kernel::Process>& CurrentProcess() { | ||
| 180 | return System::GetInstance().CurrentProcess(); | ||
| 181 | } | ||
| 182 | |||
| 172 | } // namespace Core | 183 | } // namespace Core |
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index c3329ce52..14868fed2 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | #include "core/core.h" | ||
| 10 | #include "core/file_sys/disk_filesystem.h" | 11 | #include "core/file_sys/disk_filesystem.h" |
| 11 | #include "core/file_sys/savedata_factory.h" | 12 | #include "core/file_sys/savedata_factory.h" |
| 12 | #include "core/hle/kernel/process.h" | 13 | #include "core/hle/kernel/process.h" |
| @@ -46,7 +47,7 @@ ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) c | |||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | std::string SaveData_Factory::GetFullPath() const { | 49 | std::string SaveData_Factory::GetFullPath() const { |
| 49 | u64 title_id = Kernel::g_current_process->program_id; | 50 | u64 title_id = Core::CurrentProcess()->program_id; |
| 50 | // TODO(Subv): Somehow obtain this value. | 51 | // TODO(Subv): Somehow obtain this value. |
| 51 | u32 user = 0; | 52 | u32 user = 0; |
| 52 | return Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X/", nand_directory.c_str(), title_id, | 53 | return Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X/", nand_directory.c_str(), title_id, |
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 3beb55753..822449cd5 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <utility> | 5 | #include <utility> |
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/core.h" | ||
| 8 | #include "core/hle/kernel/errors.h" | 9 | #include "core/hle/kernel/errors.h" |
| 9 | #include "core/hle/kernel/handle_table.h" | 10 | #include "core/hle/kernel/handle_table.h" |
| 10 | #include "core/hle/kernel/kernel.h" | 11 | #include "core/hle/kernel/kernel.h" |
| @@ -77,7 +78,7 @@ SharedPtr<Object> HandleTable::GetGeneric(Handle handle) const { | |||
| 77 | if (handle == CurrentThread) { | 78 | if (handle == CurrentThread) { |
| 78 | return GetCurrentThread(); | 79 | return GetCurrentThread(); |
| 79 | } else if (handle == CurrentProcess) { | 80 | } else if (handle == CurrentProcess) { |
| 80 | return g_current_process; | 81 | return Core::CurrentProcess(); |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | if (!IsValid(handle)) { | 84 | if (!IsValid(handle)) { |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index b0c3f4ae1..b325b879b 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -41,7 +41,6 @@ void Shutdown() { | |||
| 41 | g_object_address_table.Clear(); | 41 | g_object_address_table.Clear(); |
| 42 | 42 | ||
| 43 | Kernel::ThreadingShutdown(); | 43 | Kernel::ThreadingShutdown(); |
| 44 | g_current_process = nullptr; | ||
| 45 | 44 | ||
| 46 | Kernel::TimersShutdown(); | 45 | Kernel::TimersShutdown(); |
| 47 | Kernel::ResourceLimitsShutdown(); | 46 | Kernel::ResourceLimitsShutdown(); |
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index bb6dc28d7..9ca2374ea 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -31,14 +31,14 @@ CodeSet::~CodeSet() {} | |||
| 31 | 31 | ||
| 32 | u32 Process::next_process_id; | 32 | u32 Process::next_process_id; |
| 33 | 33 | ||
| 34 | SharedPtr<Process> Process::Create(std::string&& name, u64 program_id) { | 34 | SharedPtr<Process> Process::Create(std::string&& name) { |
| 35 | SharedPtr<Process> process(new Process); | 35 | SharedPtr<Process> process(new Process); |
| 36 | 36 | ||
| 37 | process->name = std::move(name); | 37 | process->name = std::move(name); |
| 38 | process->flags.raw = 0; | 38 | process->flags.raw = 0; |
| 39 | process->flags.memory_region.Assign(MemoryRegion::APPLICATION); | 39 | process->flags.memory_region.Assign(MemoryRegion::APPLICATION); |
| 40 | process->status = ProcessStatus::Created; | 40 | process->status = ProcessStatus::Created; |
| 41 | process->program_id = program_id; | 41 | process->program_id = 0; |
| 42 | 42 | ||
| 43 | process_list.push_back(process); | 43 | process_list.push_back(process); |
| 44 | return process; | 44 | return process; |
| @@ -319,5 +319,4 @@ SharedPtr<Process> GetProcessById(u32 process_id) { | |||
| 319 | return *itr; | 319 | return *itr; |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | SharedPtr<Process> g_current_process; | ||
| 323 | } // namespace Kernel | 322 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 1de12efd3..68e77a4d1 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -95,7 +95,7 @@ private: | |||
| 95 | 95 | ||
| 96 | class Process final : public Object { | 96 | class Process final : public Object { |
| 97 | public: | 97 | public: |
| 98 | static SharedPtr<Process> Create(std::string&& name, u64 program_id); | 98 | static SharedPtr<Process> Create(std::string&& name); |
| 99 | 99 | ||
| 100 | std::string GetTypeName() const override { | 100 | std::string GetTypeName() const override { |
| 101 | return "Process"; | 101 | return "Process"; |
| @@ -203,5 +203,4 @@ void ClearProcessList(); | |||
| 203 | /// Retrieves a process from the current list of processes. | 203 | /// Retrieves a process from the current list of processes. |
| 204 | SharedPtr<Process> GetProcessById(u32 process_id); | 204 | SharedPtr<Process> GetProcessById(u32 process_id); |
| 205 | 205 | ||
| 206 | extern SharedPtr<Process> g_current_process; | ||
| 207 | } // namespace Kernel | 206 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 235068b22..921f27efb 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "core/core.h" | ||
| 5 | #include "core/core_timing.h" | 6 | #include "core/core_timing.h" |
| 6 | #include "core/hle/kernel/process.h" | 7 | #include "core/hle/kernel/process.h" |
| 7 | #include "core/hle/kernel/scheduler.h" | 8 | #include "core/hle/kernel/scheduler.h" |
| @@ -67,7 +68,7 @@ void Scheduler::SwitchContext(Thread* new_thread) { | |||
| 67 | // Cancel any outstanding wakeup events for this thread | 68 | // Cancel any outstanding wakeup events for this thread |
| 68 | new_thread->CancelWakeupTimer(); | 69 | new_thread->CancelWakeupTimer(); |
| 69 | 70 | ||
| 70 | auto previous_process = Kernel::g_current_process; | 71 | auto previous_process = Core::CurrentProcess(); |
| 71 | 72 | ||
| 72 | current_thread = new_thread; | 73 | current_thread = new_thread; |
| 73 | 74 | ||
| @@ -75,8 +76,8 @@ void Scheduler::SwitchContext(Thread* new_thread) { | |||
| 75 | new_thread->status = THREADSTATUS_RUNNING; | 76 | new_thread->status = THREADSTATUS_RUNNING; |
| 76 | 77 | ||
| 77 | if (previous_process != current_thread->owner_process) { | 78 | if (previous_process != current_thread->owner_process) { |
| 78 | Kernel::g_current_process = current_thread->owner_process; | 79 | Core::CurrentProcess() = current_thread->owner_process; |
| 79 | SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table); | 80 | SetCurrentPageTable(&Core::CurrentProcess()->vm_manager.page_table); |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 82 | cpu_core->LoadContext(new_thread->context); | 83 | cpu_core->LoadContext(new_thread->context); |
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 5f31cf19b..9b4a0ef0a 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <tuple> | 5 | #include <tuple> |
| 6 | 6 | ||
| 7 | #include "core/core.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | 8 | #include "core/hle/ipc_helpers.h" |
| 8 | #include "core/hle/kernel/client_port.h" | 9 | #include "core/hle/kernel/client_port.h" |
| 9 | #include "core/hle/kernel/client_session.h" | 10 | #include "core/hle/kernel/client_session.h" |
| @@ -91,7 +92,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) { | |||
| 91 | 92 | ||
| 92 | Kernel::HLERequestContext context(this); | 93 | Kernel::HLERequestContext context(this); |
| 93 | u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); | 94 | u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); |
| 94 | context.PopulateFromIncomingCommandBuffer(cmd_buf, *Kernel::g_current_process, | 95 | context.PopulateFromIncomingCommandBuffer(cmd_buf, *Core::CurrentProcess(), |
| 95 | Kernel::g_handle_table); | 96 | Kernel::g_handle_table); |
| 96 | 97 | ||
| 97 | ResultCode result = RESULT_SUCCESS; | 98 | ResultCode result = RESULT_SUCCESS; |
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index d4505061e..4d6cd7462 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "core/core.h" | ||
| 7 | #include "core/hle/kernel/errors.h" | 8 | #include "core/hle/kernel/errors.h" |
| 8 | #include "core/hle/kernel/memory.h" | 9 | #include "core/hle/kernel/memory.h" |
| 9 | #include "core/hle/kernel/shared_memory.h" | 10 | #include "core/hle/kernel/shared_memory.h" |
| @@ -51,8 +52,8 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u | |||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | // Refresh the address mappings for the current process. | 54 | // Refresh the address mappings for the current process. |
| 54 | if (Kernel::g_current_process != nullptr) { | 55 | if (Core::CurrentProcess() != nullptr) { |
| 55 | Kernel::g_current_process->vm_manager.RefreshMemoryBlockMappings(linheap_memory.get()); | 56 | Core::CurrentProcess()->vm_manager.RefreshMemoryBlockMappings(linheap_memory.get()); |
| 56 | } | 57 | } |
| 57 | } else { | 58 | } else { |
| 58 | auto& vm_manager = shared_memory->owner_process->vm_manager; | 59 | auto& vm_manager = shared_memory->owner_process->vm_manager; |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 1ab8cbd88..207583320 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/microprofile.h" | 9 | #include "common/microprofile.h" |
| 10 | #include "common/string_util.h" | 10 | #include "common/string_util.h" |
| 11 | #include "core/core.h" | ||
| 11 | #include "core/core_timing.h" | 12 | #include "core/core_timing.h" |
| 12 | #include "core/hle/kernel/client_port.h" | 13 | #include "core/hle/kernel/client_port.h" |
| 13 | #include "core/hle/kernel/client_session.h" | 14 | #include "core/hle/kernel/client_session.h" |
| @@ -31,7 +32,7 @@ namespace Kernel { | |||
| 31 | /// Set the process heap to a given Size. It can both extend and shrink the heap. | 32 | /// Set the process heap to a given Size. It can both extend and shrink the heap. |
| 32 | static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { | 33 | static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { |
| 33 | LOG_TRACE(Kernel_SVC, "called, heap_size=0x%llx", heap_size); | 34 | LOG_TRACE(Kernel_SVC, "called, heap_size=0x%llx", heap_size); |
| 34 | auto& process = *g_current_process; | 35 | auto& process = *Core::CurrentProcess(); |
| 35 | CASCADE_RESULT(*heap_addr, | 36 | CASCADE_RESULT(*heap_addr, |
| 36 | process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite)); | 37 | process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite)); |
| 37 | return RESULT_SUCCESS; | 38 | return RESULT_SUCCESS; |
| @@ -46,14 +47,14 @@ static ResultCode SetMemoryAttribute(VAddr addr, u64 size, u32 state0, u32 state | |||
| 46 | static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | 47 | static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { |
| 47 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, | 48 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, |
| 48 | src_addr, size); | 49 | src_addr, size); |
| 49 | return g_current_process->MirrorMemory(dst_addr, src_addr, size); | 50 | return Core::CurrentProcess()->MirrorMemory(dst_addr, src_addr, size); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | /// Unmaps a region that was previously mapped with svcMapMemory | 53 | /// Unmaps a region that was previously mapped with svcMapMemory |
| 53 | static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | 54 | static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { |
| 54 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, | 55 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, |
| 55 | src_addr, size); | 56 | src_addr, size); |
| 56 | return g_current_process->UnmapMemory(dst_addr, src_addr, size); | 57 | return Core::CurrentProcess()->UnmapMemory(dst_addr, src_addr, size); |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | /// Connect to an OS service given the port name, returns the handle to the port to out | 60 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| @@ -306,14 +307,14 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 306 | LOG_TRACE(Kernel_SVC, "called info_id=0x%X, info_sub_id=0x%X, handle=0x%08X", info_id, | 307 | LOG_TRACE(Kernel_SVC, "called info_id=0x%X, info_sub_id=0x%X, handle=0x%08X", info_id, |
| 307 | info_sub_id, handle); | 308 | info_sub_id, handle); |
| 308 | 309 | ||
| 309 | auto& vm_manager = g_current_process->vm_manager; | 310 | auto& vm_manager = Core::CurrentProcess()->vm_manager; |
| 310 | 311 | ||
| 311 | switch (static_cast<GetInfoType>(info_id)) { | 312 | switch (static_cast<GetInfoType>(info_id)) { |
| 312 | case GetInfoType::AllowedCpuIdBitmask: | 313 | case GetInfoType::AllowedCpuIdBitmask: |
| 313 | *result = g_current_process->allowed_processor_mask; | 314 | *result = Core::CurrentProcess()->allowed_processor_mask; |
| 314 | break; | 315 | break; |
| 315 | case GetInfoType::AllowedThreadPrioBitmask: | 316 | case GetInfoType::AllowedThreadPrioBitmask: |
| 316 | *result = g_current_process->allowed_thread_priority_mask; | 317 | *result = Core::CurrentProcess()->allowed_thread_priority_mask; |
| 317 | break; | 318 | break; |
| 318 | case GetInfoType::MapRegionBaseAddr: | 319 | case GetInfoType::MapRegionBaseAddr: |
| 319 | *result = vm_manager.GetMapRegionBaseAddr(); | 320 | *result = vm_manager.GetMapRegionBaseAddr(); |
| @@ -352,7 +353,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 352 | *result = vm_manager.GetNewMapRegionSize(); | 353 | *result = vm_manager.GetNewMapRegionSize(); |
| 353 | break; | 354 | break; |
| 354 | case GetInfoType::IsVirtualAddressMemoryEnabled: | 355 | case GetInfoType::IsVirtualAddressMemoryEnabled: |
| 355 | *result = g_current_process->is_virtual_address_memory_enabled; | 356 | *result = Core::CurrentProcess()->is_virtual_address_memory_enabled; |
| 356 | break; | 357 | break; |
| 357 | case GetInfoType::TitleId: | 358 | case GetInfoType::TitleId: |
| 358 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query titleid, returned 0"); | 359 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query titleid, returned 0"); |
| @@ -392,7 +393,7 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { | |||
| 392 | 393 | ||
| 393 | // Note: The kernel uses the current process's resource limit instead of | 394 | // Note: The kernel uses the current process's resource limit instead of |
| 394 | // the one from the thread owner's resource limit. | 395 | // the one from the thread owner's resource limit. |
| 395 | SharedPtr<ResourceLimit>& resource_limit = g_current_process->resource_limit; | 396 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; |
| 396 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { | 397 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { |
| 397 | return ERR_NOT_AUTHORIZED; | 398 | return ERR_NOT_AUTHORIZED; |
| 398 | } | 399 | } |
| @@ -435,7 +436,7 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 435 | case MemoryPermission::WriteExecute: | 436 | case MemoryPermission::WriteExecute: |
| 436 | case MemoryPermission::ReadWriteExecute: | 437 | case MemoryPermission::ReadWriteExecute: |
| 437 | case MemoryPermission::DontCare: | 438 | case MemoryPermission::DontCare: |
| 438 | return shared_memory->Map(g_current_process.get(), addr, permissions_type, | 439 | return shared_memory->Map(Core::CurrentProcess().get(), addr, permissions_type, |
| 439 | MemoryPermission::DontCare); | 440 | MemoryPermission::DontCare); |
| 440 | default: | 441 | default: |
| 441 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); | 442 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); |
| @@ -451,7 +452,7 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 451 | 452 | ||
| 452 | SharedPtr<SharedMemory> shared_memory = g_handle_table.Get<SharedMemory>(shared_memory_handle); | 453 | SharedPtr<SharedMemory> shared_memory = g_handle_table.Get<SharedMemory>(shared_memory_handle); |
| 453 | 454 | ||
| 454 | return shared_memory->Unmap(g_current_process.get(), addr); | 455 | return shared_memory->Unmap(Core::CurrentProcess().get(), addr); |
| 455 | } | 456 | } |
| 456 | 457 | ||
| 457 | /// Query process memory | 458 | /// Query process memory |
| @@ -463,7 +464,7 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i | |||
| 463 | } | 464 | } |
| 464 | auto vma = process->vm_manager.FindVMA(addr); | 465 | auto vma = process->vm_manager.FindVMA(addr); |
| 465 | memory_info->attributes = 0; | 466 | memory_info->attributes = 0; |
| 466 | if (vma == g_current_process->vm_manager.vma_map.end()) { | 467 | if (vma == Core::CurrentProcess()->vm_manager.vma_map.end()) { |
| 467 | memory_info->base_address = 0; | 468 | memory_info->base_address = 0; |
| 468 | memory_info->permission = static_cast<u32>(VMAPermission::None); | 469 | memory_info->permission = static_cast<u32>(VMAPermission::None); |
| 469 | memory_info->size = 0; | 470 | memory_info->size = 0; |
| @@ -487,16 +488,17 @@ static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, VAdd | |||
| 487 | 488 | ||
| 488 | /// Exits the current process | 489 | /// Exits the current process |
| 489 | static void ExitProcess() { | 490 | static void ExitProcess() { |
| 490 | LOG_INFO(Kernel_SVC, "Process %u exiting", g_current_process->process_id); | 491 | LOG_INFO(Kernel_SVC, "Process %u exiting", Core::CurrentProcess()->process_id); |
| 491 | 492 | ||
| 492 | ASSERT_MSG(g_current_process->status == ProcessStatus::Running, "Process has already exited"); | 493 | ASSERT_MSG(Core::CurrentProcess()->status == ProcessStatus::Running, |
| 494 | "Process has already exited"); | ||
| 493 | 495 | ||
| 494 | g_current_process->status = ProcessStatus::Exited; | 496 | Core::CurrentProcess()->status = ProcessStatus::Exited; |
| 495 | 497 | ||
| 496 | // Stop all the process threads that are currently waiting for objects. | 498 | // Stop all the process threads that are currently waiting for objects. |
| 497 | auto& thread_list = Core::System::GetInstance().Scheduler().GetThreadList(); | 499 | auto& thread_list = Core::System::GetInstance().Scheduler().GetThreadList(); |
| 498 | for (auto& thread : thread_list) { | 500 | for (auto& thread : thread_list) { |
| 499 | if (thread->owner_process != g_current_process) | 501 | if (thread->owner_process != Core::CurrentProcess()) |
| 500 | continue; | 502 | continue; |
| 501 | 503 | ||
| 502 | if (thread == GetCurrentThread()) | 504 | if (thread == GetCurrentThread()) |
| @@ -525,14 +527,14 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 525 | return ERR_OUT_OF_RANGE; | 527 | return ERR_OUT_OF_RANGE; |
| 526 | } | 528 | } |
| 527 | 529 | ||
| 528 | SharedPtr<ResourceLimit>& resource_limit = g_current_process->resource_limit; | 530 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; |
| 529 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { | 531 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { |
| 530 | return ERR_NOT_AUTHORIZED; | 532 | return ERR_NOT_AUTHORIZED; |
| 531 | } | 533 | } |
| 532 | 534 | ||
| 533 | if (processor_id == THREADPROCESSORID_DEFAULT) { | 535 | if (processor_id == THREADPROCESSORID_DEFAULT) { |
| 534 | // Set the target CPU to the one specified in the process' exheader. | 536 | // Set the target CPU to the one specified in the process' exheader. |
| 535 | processor_id = g_current_process->ideal_processor; | 537 | processor_id = Core::CurrentProcess()->ideal_processor; |
| 536 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); | 538 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); |
| 537 | } | 539 | } |
| 538 | 540 | ||
| @@ -554,7 +556,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 554 | 556 | ||
| 555 | CASCADE_RESULT(SharedPtr<Thread> thread, | 557 | CASCADE_RESULT(SharedPtr<Thread> thread, |
| 556 | Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, | 558 | Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, |
| 557 | g_current_process)); | 559 | Core::CurrentProcess())); |
| 558 | CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread)); | 560 | CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread)); |
| 559 | *out_handle = thread->guest_handle; | 561 | *out_handle = thread->guest_handle; |
| 560 | 562 | ||
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 25828777e..2394620eb 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -94,7 +94,7 @@ void Thread::Stop() { | |||
| 94 | u64 tls_page = (tls_address - Memory::TLS_AREA_VADDR) / Memory::PAGE_SIZE; | 94 | u64 tls_page = (tls_address - Memory::TLS_AREA_VADDR) / Memory::PAGE_SIZE; |
| 95 | u64 tls_slot = | 95 | u64 tls_slot = |
| 96 | ((tls_address - Memory::TLS_AREA_VADDR) % Memory::PAGE_SIZE) / Memory::TLS_ENTRY_SIZE; | 96 | ((tls_address - Memory::TLS_AREA_VADDR) % Memory::PAGE_SIZE) / Memory::TLS_ENTRY_SIZE; |
| 97 | Kernel::g_current_process->tls_slots[tls_page].reset(tls_slot); | 97 | Core::CurrentProcess()->tls_slots[tls_page].reset(tls_slot); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | void WaitCurrentThread_Sleep() { | 100 | void WaitCurrentThread_Sleep() { |
| @@ -353,7 +353,7 @@ void Thread::BoostPriority(u32 priority) { | |||
| 353 | SharedPtr<Thread> SetupMainThread(VAddr entry_point, u32 priority, | 353 | SharedPtr<Thread> SetupMainThread(VAddr entry_point, u32 priority, |
| 354 | SharedPtr<Process> owner_process) { | 354 | SharedPtr<Process> owner_process) { |
| 355 | // Setup page table so we can write to memory | 355 | // Setup page table so we can write to memory |
| 356 | SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table); | 356 | SetCurrentPageTable(&Core::CurrentProcess()->vm_manager.page_table); |
| 357 | 357 | ||
| 358 | // Initialize new "main" thread | 358 | // Initialize new "main" thread |
| 359 | auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, | 359 | auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, |
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index cc9d03a7c..695e295ca 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/common_paths.h" | 5 | #include "common/common_paths.h" |
| 6 | #include "common/file_util.h" | 6 | #include "common/file_util.h" |
| 7 | #include "core/core.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | 8 | #include "core/hle/ipc_helpers.h" |
| 8 | #include "core/hle/service/ns/pl_u.h" | 9 | #include "core/hle/service/ns/pl_u.h" |
| 9 | 10 | ||
| @@ -90,13 +91,13 @@ void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { | |||
| 90 | // dump. In the future, we need to replace this with a more robust solution. | 91 | // dump. In the future, we need to replace this with a more robust solution. |
| 91 | 92 | ||
| 92 | // Map backing memory for the font data | 93 | // Map backing memory for the font data |
| 93 | Kernel::g_current_process->vm_manager.MapMemoryBlock(SHARED_FONT_MEM_VADDR, shared_font, 0, | 94 | Core::CurrentProcess()->vm_manager.MapMemoryBlock(SHARED_FONT_MEM_VADDR, shared_font, 0, |
| 94 | SHARED_FONT_MEM_SIZE, | 95 | SHARED_FONT_MEM_SIZE, |
| 95 | Kernel::MemoryState::Shared); | 96 | Kernel::MemoryState::Shared); |
| 96 | 97 | ||
| 97 | // Create shared font memory object | 98 | // Create shared font memory object |
| 98 | shared_font_mem = Kernel::SharedMemory::Create( | 99 | shared_font_mem = Kernel::SharedMemory::Create( |
| 99 | Kernel::g_current_process, SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, | 100 | Core::CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, |
| 100 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, | 101 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, |
| 101 | "PL_U:shared_font_mem"); | 102 | "PL_U:shared_font_mem"); |
| 102 | } | 103 | } |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 78380475c..8818b0f0f 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | #include "core/core.h" | ||
| 10 | #include "core/hle/ipc.h" | 11 | #include "core/hle/ipc.h" |
| 11 | #include "core/hle/ipc_helpers.h" | 12 | #include "core/hle/ipc_helpers.h" |
| 12 | #include "core/hle/kernel/client_port.h" | 13 | #include "core/hle/kernel/client_port.h" |
| @@ -152,8 +153,7 @@ ResultCode ServiceFrameworkBase::HandleSyncRequest(Kernel::HLERequestContext& co | |||
| 152 | } | 153 | } |
| 153 | 154 | ||
| 154 | u32* cmd_buf = (u32*)Memory::GetPointer(Kernel::GetCurrentThread()->GetTLSAddress()); | 155 | u32* cmd_buf = (u32*)Memory::GetPointer(Kernel::GetCurrentThread()->GetTLSAddress()); |
| 155 | context.WriteToOutgoingCommandBuffer(cmd_buf, *Kernel::g_current_process, | 156 | context.WriteToOutgoingCommandBuffer(cmd_buf, *Core::CurrentProcess(), Kernel::g_handle_table); |
| 156 | Kernel::g_handle_table); | ||
| 157 | 157 | ||
| 158 | return RESULT_SUCCESS; | 158 | return RESULT_SUCCESS; |
| 159 | } | 159 | } |
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 459d127c2..aa09ed323 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -119,8 +119,6 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 119 | } | 119 | } |
| 120 | metadata.Print(); | 120 | metadata.Print(); |
| 121 | 121 | ||
| 122 | process = Kernel::Process::Create("main", metadata.GetTitleID()); | ||
| 123 | |||
| 124 | // Load NSO modules | 122 | // Load NSO modules |
| 125 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 123 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 126 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | 124 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", |
| @@ -135,6 +133,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 135 | } | 133 | } |
| 136 | } | 134 | } |
| 137 | 135 | ||
| 136 | process->program_id = metadata.GetTitleID(); | ||
| 138 | process->svc_access_mask.set(); | 137 | process->svc_access_mask.set(); |
| 139 | process->address_mappings = default_address_mappings; | 138 | process->address_mappings = default_address_mappings; |
| 140 | process->resource_limit = | 139 | process->resource_limit = |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index cdd41f237..164d52258 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -406,7 +406,6 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 406 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); | 406 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); |
| 407 | codeset->name = filename; | 407 | codeset->name = filename; |
| 408 | 408 | ||
| 409 | process = Kernel::Process::Create("main", 0); | ||
| 410 | process->LoadModule(codeset, codeset->entrypoint); | 409 | process->LoadModule(codeset, codeset->entrypoint); |
| 411 | process->svc_access_mask.set(); | 410 | process->svc_access_mask.set(); |
| 412 | process->address_mappings = default_address_mappings; | 411 | process->address_mappings = default_address_mappings; |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index c557b66dc..0dc06ccea 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 11 | #include "core/core.h" | ||
| 11 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 12 | #include "core/hle/kernel/resource_limit.h" | 13 | #include "core/hle/kernel/resource_limit.h" |
| 13 | #include "core/loader/nro.h" | 14 | #include "core/loader/nro.h" |
| @@ -112,7 +113,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | |||
| 112 | // Load codeset for current process | 113 | // Load codeset for current process |
| 113 | codeset->name = path; | 114 | codeset->name = path; |
| 114 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 115 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
| 115 | Kernel::g_current_process->LoadModule(codeset, load_base); | 116 | Core::CurrentProcess()->LoadModule(codeset, load_base); |
| 116 | 117 | ||
| 117 | return true; | 118 | return true; |
| 118 | } | 119 | } |
| @@ -125,8 +126,6 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 125 | return ResultStatus::Error; | 126 | return ResultStatus::Error; |
| 126 | } | 127 | } |
| 127 | 128 | ||
| 128 | process = Kernel::Process::Create("main", 0); | ||
| 129 | |||
| 130 | // Load NRO | 129 | // Load NRO |
| 131 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; | 130 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 132 | 131 | ||
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 00b5d1d49..c0eeb95d3 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/core.h" | ||
| 12 | #include "core/hle/kernel/process.h" | 13 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/kernel/resource_limit.h" | 14 | #include "core/hle/kernel/resource_limit.h" |
| 14 | #include "core/loader/nso.h" | 15 | #include "core/loader/nso.h" |
| @@ -142,7 +143,7 @@ VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { | |||
| 142 | // Load codeset for current process | 143 | // Load codeset for current process |
| 143 | codeset->name = path; | 144 | codeset->name = path; |
| 144 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 145 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
| 145 | Kernel::g_current_process->LoadModule(codeset, load_base); | 146 | Core::CurrentProcess()->LoadModule(codeset, load_base); |
| 146 | 147 | ||
| 147 | return load_base + image_size; | 148 | return load_base + image_size; |
| 148 | } | 149 | } |
| @@ -155,8 +156,6 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 155 | return ResultStatus::Error; | 156 | return ResultStatus::Error; |
| 156 | } | 157 | } |
| 157 | 158 | ||
| 158 | process = Kernel::Process::Create("main", 0); | ||
| 159 | |||
| 160 | // Load module | 159 | // Load module |
| 161 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); | 160 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); |
| 162 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(), | 161 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(), |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index ce62666d7..4e34d8334 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -109,7 +109,7 @@ static std::set<MemoryHookPointer> GetSpecialHandlers(const PageTable& page_tabl | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static std::set<MemoryHookPointer> GetSpecialHandlers(VAddr vaddr, u64 size) { | 111 | static std::set<MemoryHookPointer> GetSpecialHandlers(VAddr vaddr, u64 size) { |
| 112 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 112 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 113 | return GetSpecialHandlers(page_table, vaddr, size); | 113 | return GetSpecialHandlers(page_table, vaddr, size); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| @@ -202,7 +202,7 @@ bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { | |||
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | bool IsValidVirtualAddress(const VAddr vaddr) { | 204 | bool IsValidVirtualAddress(const VAddr vaddr) { |
| 205 | return IsValidVirtualAddress(*Kernel::g_current_process, vaddr); | 205 | return IsValidVirtualAddress(*Core::CurrentProcess(), vaddr); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | bool IsValidPhysicalAddress(const PAddr paddr) { | 208 | bool IsValidPhysicalAddress(const PAddr paddr) { |
| @@ -364,7 +364,7 @@ void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_ | |||
| 364 | } | 364 | } |
| 365 | 365 | ||
| 366 | void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { | 366 | void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { |
| 367 | ReadBlock(*Kernel::g_current_process, src_addr, dest_buffer, size); | 367 | ReadBlock(*Core::CurrentProcess(), src_addr, dest_buffer, size); |
| 368 | } | 368 | } |
| 369 | 369 | ||
| 370 | void Write8(const VAddr addr, const u8 data) { | 370 | void Write8(const VAddr addr, const u8 data) { |
| @@ -435,11 +435,11 @@ void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const voi | |||
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size) { | 437 | void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size) { |
| 438 | WriteBlock(*Kernel::g_current_process, dest_addr, src_buffer, size); | 438 | WriteBlock(*Core::CurrentProcess(), dest_addr, src_buffer, size); |
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | void ZeroBlock(const VAddr dest_addr, const size_t size) { | 441 | void ZeroBlock(const VAddr dest_addr, const size_t size) { |
| 442 | const auto& process = *Kernel::g_current_process; | 442 | const auto& process = *Core::CurrentProcess(); |
| 443 | 443 | ||
| 444 | size_t remaining_size = size; | 444 | size_t remaining_size = size; |
| 445 | size_t page_index = dest_addr >> PAGE_BITS; | 445 | size_t page_index = dest_addr >> PAGE_BITS; |
| @@ -480,7 +480,7 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) { | |||
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { | 482 | void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { |
| 483 | const auto& process = *Kernel::g_current_process; | 483 | const auto& process = *Core::CurrentProcess(); |
| 484 | 484 | ||
| 485 | size_t remaining_size = size; | 485 | size_t remaining_size = size; |
| 486 | size_t page_index = src_addr >> PAGE_BITS; | 486 | size_t page_index = src_addr >> PAGE_BITS; |
| @@ -526,7 +526,7 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { | |||
| 526 | 526 | ||
| 527 | template <> | 527 | template <> |
| 528 | boost::optional<u8> ReadSpecial<u8>(VAddr addr) { | 528 | boost::optional<u8> ReadSpecial<u8>(VAddr addr) { |
| 529 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 529 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 530 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u8))) | 530 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u8))) |
| 531 | if (auto result = handler->Read8(addr)) | 531 | if (auto result = handler->Read8(addr)) |
| 532 | return *result; | 532 | return *result; |
| @@ -535,7 +535,7 @@ boost::optional<u8> ReadSpecial<u8>(VAddr addr) { | |||
| 535 | 535 | ||
| 536 | template <> | 536 | template <> |
| 537 | boost::optional<u16> ReadSpecial<u16>(VAddr addr) { | 537 | boost::optional<u16> ReadSpecial<u16>(VAddr addr) { |
| 538 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 538 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 539 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u16))) | 539 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u16))) |
| 540 | if (auto result = handler->Read16(addr)) | 540 | if (auto result = handler->Read16(addr)) |
| 541 | return *result; | 541 | return *result; |
| @@ -544,7 +544,7 @@ boost::optional<u16> ReadSpecial<u16>(VAddr addr) { | |||
| 544 | 544 | ||
| 545 | template <> | 545 | template <> |
| 546 | boost::optional<u32> ReadSpecial<u32>(VAddr addr) { | 546 | boost::optional<u32> ReadSpecial<u32>(VAddr addr) { |
| 547 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 547 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 548 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u32))) | 548 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u32))) |
| 549 | if (auto result = handler->Read32(addr)) | 549 | if (auto result = handler->Read32(addr)) |
| 550 | return *result; | 550 | return *result; |
| @@ -553,7 +553,7 @@ boost::optional<u32> ReadSpecial<u32>(VAddr addr) { | |||
| 553 | 553 | ||
| 554 | template <> | 554 | template <> |
| 555 | boost::optional<u64> ReadSpecial<u64>(VAddr addr) { | 555 | boost::optional<u64> ReadSpecial<u64>(VAddr addr) { |
| 556 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 556 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 557 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u64))) | 557 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u64))) |
| 558 | if (auto result = handler->Read64(addr)) | 558 | if (auto result = handler->Read64(addr)) |
| 559 | return *result; | 559 | return *result; |
| @@ -562,7 +562,7 @@ boost::optional<u64> ReadSpecial<u64>(VAddr addr) { | |||
| 562 | 562 | ||
| 563 | template <> | 563 | template <> |
| 564 | bool WriteSpecial<u8>(VAddr addr, const u8 data) { | 564 | bool WriteSpecial<u8>(VAddr addr, const u8 data) { |
| 565 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 565 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 566 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u8))) | 566 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u8))) |
| 567 | if (handler->Write8(addr, data)) | 567 | if (handler->Write8(addr, data)) |
| 568 | return true; | 568 | return true; |
| @@ -571,7 +571,7 @@ bool WriteSpecial<u8>(VAddr addr, const u8 data) { | |||
| 571 | 571 | ||
| 572 | template <> | 572 | template <> |
| 573 | bool WriteSpecial<u16>(VAddr addr, const u16 data) { | 573 | bool WriteSpecial<u16>(VAddr addr, const u16 data) { |
| 574 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 574 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 575 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u16))) | 575 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u16))) |
| 576 | if (handler->Write16(addr, data)) | 576 | if (handler->Write16(addr, data)) |
| 577 | return true; | 577 | return true; |
| @@ -580,7 +580,7 @@ bool WriteSpecial<u16>(VAddr addr, const u16 data) { | |||
| 580 | 580 | ||
| 581 | template <> | 581 | template <> |
| 582 | bool WriteSpecial<u32>(VAddr addr, const u32 data) { | 582 | bool WriteSpecial<u32>(VAddr addr, const u32 data) { |
| 583 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 583 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 584 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u32))) | 584 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u32))) |
| 585 | if (handler->Write32(addr, data)) | 585 | if (handler->Write32(addr, data)) |
| 586 | return true; | 586 | return true; |
| @@ -589,7 +589,7 @@ bool WriteSpecial<u32>(VAddr addr, const u32 data) { | |||
| 589 | 589 | ||
| 590 | template <> | 590 | template <> |
| 591 | bool WriteSpecial<u64>(VAddr addr, const u64 data) { | 591 | bool WriteSpecial<u64>(VAddr addr, const u64 data) { |
| 592 | const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; | 592 | const PageTable& page_table = Core::CurrentProcess()->vm_manager.page_table; |
| 593 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u64))) | 593 | for (const auto& handler : GetSpecialHandlers(page_table, addr, sizeof(u64))) |
| 594 | if (handler->Write64(addr, data)) | 594 | if (handler->Write64(addr, data)) |
| 595 | return true; | 595 | return true; |
| @@ -632,7 +632,7 @@ boost::optional<VAddr> PhysicalToVirtualAddress(const PAddr addr) { | |||
| 632 | } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { | 632 | } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { |
| 633 | return addr - VRAM_PADDR + VRAM_VADDR; | 633 | return addr - VRAM_PADDR + VRAM_VADDR; |
| 634 | } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { | 634 | } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { |
| 635 | return addr - FCRAM_PADDR + Kernel::g_current_process->GetLinearHeapAreaAddress(); | 635 | return addr - FCRAM_PADDR + Core::CurrentProcess()->GetLinearHeapAreaAddress(); |
| 636 | } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) { | 636 | } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) { |
| 637 | return addr - DSP_RAM_PADDR + DSP_RAM_VADDR; | 637 | return addr - DSP_RAM_PADDR + DSP_RAM_VADDR; |
| 638 | } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) { | 638 | } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) { |
diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp index 9296e1e94..7f9f27e19 100644 --- a/src/tests/core/arm/arm_test_common.cpp +++ b/src/tests/core/arm/arm_test_common.cpp | |||
| @@ -15,8 +15,8 @@ static Memory::PageTable* page_table = nullptr; | |||
| 15 | TestEnvironment::TestEnvironment(bool mutable_memory_) | 15 | TestEnvironment::TestEnvironment(bool mutable_memory_) |
| 16 | : mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) { | 16 | : mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) { |
| 17 | 17 | ||
| 18 | Kernel::g_current_process = Kernel::Process::Create("", 0); | 18 | Core::CurrentProcess() = Kernel::Process::Create(""); |
| 19 | page_table = &Kernel::g_current_process->vm_manager.page_table; | 19 | page_table = &Core::CurrentProcess()->vm_manager.page_table; |
| 20 | 20 | ||
| 21 | page_table->pointers.fill(nullptr); | 21 | page_table->pointers.fill(nullptr); |
| 22 | page_table->special_regions.clear(); | 22 | page_table->special_regions.clear(); |
diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp index 0e0a43dcb..165496a54 100644 --- a/src/tests/core/memory/memory.cpp +++ b/src/tests/core/memory/memory.cpp | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { | 10 | TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { |
| 11 | SECTION("these regions should not be mapped on an empty process") { | 11 | SECTION("these regions should not be mapped on an empty process") { |
| 12 | auto process = Kernel::Process::Create("", 0); | 12 | auto process = Kernel::Process::Create(""); |
| 13 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false); | 13 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false); |
| 14 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false); | 14 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false); |
| 15 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false); | 15 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false); |
| @@ -20,14 +20,14 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { | 22 | SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { |
| 23 | auto process = Kernel::Process::Create("", 0); | 23 | auto process = Kernel::Process::Create(""); |
| 24 | Kernel::MapSharedPages(process->vm_manager); | 24 | Kernel::MapSharedPages(process->vm_manager); |
| 25 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); | 25 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); |
| 26 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); | 26 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | SECTION("special regions should be valid after mapping them") { | 29 | SECTION("special regions should be valid after mapping them") { |
| 30 | auto process = Kernel::Process::Create("", 0); | 30 | auto process = Kernel::Process::Create(""); |
| 31 | SECTION("VRAM") { | 31 | SECTION("VRAM") { |
| 32 | Kernel::HandleSpecialMapping(process->vm_manager, | 32 | Kernel::HandleSpecialMapping(process->vm_manager, |
| 33 | {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); | 33 | {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); |
| @@ -48,7 +48,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | SECTION("Unmapping a VAddr should make it invalid") { | 50 | SECTION("Unmapping a VAddr should make it invalid") { |
| 51 | auto process = Kernel::Process::Create("", 0); | 51 | auto process = Kernel::Process::Create(""); |
| 52 | Kernel::MapSharedPages(process->vm_manager); | 52 | Kernel::MapSharedPages(process->vm_manager); |
| 53 | process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); | 53 | process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); |
| 54 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); | 54 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); |