From f1382cf0e7180cd31505ee89e774cc93bde6211e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 6 Oct 2019 13:51:31 -0400 Subject: [PATCH] core: Remove Core::CurrentProcess() This only encourages the use of the global system instance (which will be phased out long-term). Instead, we use the direct system function call directly to remove the appealing but discouraged short-hand. --- src/core/core.h | 4 ---- src/core/file_sys/savedata_factory.cpp | 5 +++-- src/core/gdbstub/gdbstub.cpp | 3 ++- src/core/hle/kernel/handle_table.cpp | 2 +- src/core/memory.cpp | 10 +++++----- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/core/core.h b/src/core/core.h index fecfdb959..97944c366 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -359,8 +359,4 @@ private: static System s_instance; }; -inline Kernel::Process* CurrentProcess() { - return System::GetInstance().CurrentProcess(); -} - } // namespace Core diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index f77cc02ac..fc8755c78 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -127,8 +127,9 @@ std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType typ u128 user_id, u64 save_id) { // According to switchbrew, if a save is of type SaveData and the title id field is 0, it should // be interpreted as the title id of the current process. - if (type == SaveDataType::SaveData && title_id == 0) - title_id = Core::CurrentProcess()->GetTitleID(); + if (type == SaveDataType::SaveData && title_id == 0) { + title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); + } std::string out = GetSaveDataSpaceIdPath(space); diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index afa812598..db51d722f 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -641,7 +641,8 @@ static void HandleQuery() { strlen("Xfer:features:read:target.xml:")) == 0) { SendReply(target_xml); } else if (strncmp(query, "Offsets", strlen("Offsets")) == 0) { - const VAddr base_address = Core::CurrentProcess()->VMManager().GetCodeRegionBaseAddress(); + const VAddr base_address = + Core::System::GetInstance().CurrentProcess()->VMManager().GetCodeRegionBaseAddress(); std::string buffer = fmt::format("TextSeg={:0x}", base_address); SendReply(buffer.c_str()); } else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) { diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index bdfaa977f..2cc5d536b 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -103,7 +103,7 @@ SharedPtr HandleTable::GetGeneric(Handle handle) const { if (handle == CurrentThread) { return GetCurrentThread(); } else if (handle == CurrentProcess) { - return Core::CurrentProcess(); + return Core::System::GetInstance().CurrentProcess(); } if (!IsValid(handle)) { diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 9e030789d..fa49f3dd0 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -146,7 +146,7 @@ static u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) { * using a VMA from the current process. */ static u8* GetPointerFromVMA(VAddr vaddr) { - return GetPointerFromVMA(*Core::CurrentProcess(), vaddr); + return GetPointerFromVMA(*Core::System::GetInstance().CurrentProcess(), vaddr); } template @@ -226,7 +226,7 @@ bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { } bool IsValidVirtualAddress(const VAddr vaddr) { - return IsValidVirtualAddress(*Core::CurrentProcess(), vaddr); + return IsValidVirtualAddress(*Core::System::GetInstance().CurrentProcess(), vaddr); } bool IsKernelVirtualAddress(const VAddr vaddr) { @@ -387,7 +387,7 @@ void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_ } void ReadBlock(const VAddr src_addr, void* dest_buffer, const std::size_t size) { - ReadBlock(*Core::CurrentProcess(), src_addr, dest_buffer, size); + ReadBlock(*Core::System::GetInstance().CurrentProcess(), src_addr, dest_buffer, size); } void Write8(const VAddr addr, const u8 data) { @@ -450,7 +450,7 @@ void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const voi } void WriteBlock(const VAddr dest_addr, const void* src_buffer, const std::size_t size) { - WriteBlock(*Core::CurrentProcess(), dest_addr, src_buffer, size); + WriteBlock(*Core::System::GetInstance().CurrentProcess(), dest_addr, src_buffer, size); } void ZeroBlock(const Kernel::Process& process, const VAddr dest_addr, const std::size_t size) { @@ -539,7 +539,7 @@ void CopyBlock(const Kernel::Process& process, VAddr dest_addr, VAddr src_addr, } void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size) { - CopyBlock(*Core::CurrentProcess(), dest_addr, src_addr, size); + CopyBlock(*Core::System::GetInstance().CurrentProcess(), dest_addr, src_addr, size); } } // namespace Memory