diff options
Diffstat (limited to '')
34 files changed, 147 insertions, 128 deletions
diff --git a/src/core/hle/kernel/k_client_port.cpp b/src/core/hle/kernel/k_client_port.cpp index 2ec623a58..9a540987b 100644 --- a/src/core/hle/kernel/k_client_port.cpp +++ b/src/core/hle/kernel/k_client_port.cpp | |||
| @@ -60,6 +60,7 @@ bool KClientPort::IsSignaled() const { | |||
| 60 | 60 | ||
| 61 | Result KClientPort::CreateSession(KClientSession** out) { | 61 | Result KClientPort::CreateSession(KClientSession** out) { |
| 62 | // Reserve a new session from the resource limit. | 62 | // Reserve a new session from the resource limit. |
| 63 | //! FIXME: we are reserving this from the wrong resource limit! | ||
| 63 | KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(), | 64 | KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(), |
| 64 | LimitableResource::SessionCountMax); | 65 | LimitableResource::SessionCountMax); |
| 65 | R_UNLESS(session_reservation.Succeeded(), ResultLimitReached); | 66 | R_UNLESS(session_reservation.Succeeded(), ResultLimitReached); |
diff --git a/src/core/hle/kernel/k_code_memory.cpp b/src/core/hle/kernel/k_code_memory.cpp index 884eba001..6c44a9e99 100644 --- a/src/core/hle/kernel/k_code_memory.cpp +++ b/src/core/hle/kernel/k_code_memory.cpp | |||
| @@ -21,7 +21,7 @@ KCodeMemory::KCodeMemory(KernelCore& kernel_) | |||
| 21 | 21 | ||
| 22 | Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, size_t size) { | 22 | Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, size_t size) { |
| 23 | // Set members. | 23 | // Set members. |
| 24 | m_owner = kernel.CurrentProcess(); | 24 | m_owner = GetCurrentProcessPointer(kernel); |
| 25 | 25 | ||
| 26 | // Get the owner page table. | 26 | // Get the owner page table. |
| 27 | auto& page_table = m_owner->PageTable(); | 27 | auto& page_table = m_owner->PageTable(); |
| @@ -74,7 +74,7 @@ Result KCodeMemory::Map(VAddr address, size_t size) { | |||
| 74 | R_UNLESS(!m_is_mapped, ResultInvalidState); | 74 | R_UNLESS(!m_is_mapped, ResultInvalidState); |
| 75 | 75 | ||
| 76 | // Map the memory. | 76 | // Map the memory. |
| 77 | R_TRY(kernel.CurrentProcess()->PageTable().MapPageGroup( | 77 | R_TRY(GetCurrentProcess(kernel).PageTable().MapPageGroup( |
| 78 | address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite)); | 78 | address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite)); |
| 79 | 79 | ||
| 80 | // Mark ourselves as mapped. | 80 | // Mark ourselves as mapped. |
| @@ -91,8 +91,8 @@ Result KCodeMemory::Unmap(VAddr address, size_t size) { | |||
| 91 | KScopedLightLock lk(m_lock); | 91 | KScopedLightLock lk(m_lock); |
| 92 | 92 | ||
| 93 | // Unmap the memory. | 93 | // Unmap the memory. |
| 94 | R_TRY(kernel.CurrentProcess()->PageTable().UnmapPageGroup(address, *m_page_group, | 94 | R_TRY(GetCurrentProcess(kernel).PageTable().UnmapPageGroup(address, *m_page_group, |
| 95 | KMemoryState::CodeOut)); | 95 | KMemoryState::CodeOut)); |
| 96 | 96 | ||
| 97 | // Mark ourselves as unmapped. | 97 | // Mark ourselves as unmapped. |
| 98 | m_is_mapped = false; | 98 | m_is_mapped = false; |
diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cpp index 0c6b20db3..3f0be1c3f 100644 --- a/src/core/hle/kernel/k_condition_variable.cpp +++ b/src/core/hle/kernel/k_condition_variable.cpp | |||
| @@ -164,8 +164,8 @@ Result KConditionVariable::WaitForAddress(Handle handle, VAddr addr, u32 value) | |||
| 164 | R_SUCCEED_IF(test_tag != (handle | Svc::HandleWaitMask)); | 164 | R_SUCCEED_IF(test_tag != (handle | Svc::HandleWaitMask)); |
| 165 | 165 | ||
| 166 | // Get the lock owner thread. | 166 | // Get the lock owner thread. |
| 167 | owner_thread = kernel.CurrentProcess() | 167 | owner_thread = GetCurrentProcess(kernel) |
| 168 | ->GetHandleTable() | 168 | .GetHandleTable() |
| 169 | .GetObjectWithoutPseudoHandle<KThread>(handle) | 169 | .GetObjectWithoutPseudoHandle<KThread>(handle) |
| 170 | .ReleasePointerUnsafe(); | 170 | .ReleasePointerUnsafe(); |
| 171 | R_UNLESS(owner_thread != nullptr, ResultInvalidHandle); | 171 | R_UNLESS(owner_thread != nullptr, ResultInvalidHandle); |
| @@ -213,8 +213,8 @@ void KConditionVariable::SignalImpl(KThread* thread) { | |||
| 213 | thread->EndWait(ResultSuccess); | 213 | thread->EndWait(ResultSuccess); |
| 214 | } else { | 214 | } else { |
| 215 | // Get the previous owner. | 215 | // Get the previous owner. |
| 216 | KThread* owner_thread = kernel.CurrentProcess() | 216 | KThread* owner_thread = GetCurrentProcess(kernel) |
| 217 | ->GetHandleTable() | 217 | .GetHandleTable() |
| 218 | .GetObjectWithoutPseudoHandle<KThread>( | 218 | .GetObjectWithoutPseudoHandle<KThread>( |
| 219 | static_cast<Handle>(prev_tag & ~Svc::HandleWaitMask)) | 219 | static_cast<Handle>(prev_tag & ~Svc::HandleWaitMask)) |
| 220 | .ReleasePointerUnsafe(); | 220 | .ReleasePointerUnsafe(); |
diff --git a/src/core/hle/kernel/k_handle_table.h b/src/core/hle/kernel/k_handle_table.h index 37a24e7d9..1bf68e6b0 100644 --- a/src/core/hle/kernel/k_handle_table.h +++ b/src/core/hle/kernel/k_handle_table.h | |||
| @@ -90,7 +90,7 @@ public: | |||
| 90 | // Handle pseudo-handles. | 90 | // Handle pseudo-handles. |
| 91 | if constexpr (std::derived_from<KProcess, T>) { | 91 | if constexpr (std::derived_from<KProcess, T>) { |
| 92 | if (handle == Svc::PseudoHandle::CurrentProcess) { | 92 | if (handle == Svc::PseudoHandle::CurrentProcess) { |
| 93 | auto* const cur_process = m_kernel.CurrentProcess(); | 93 | auto* const cur_process = GetCurrentProcessPointer(m_kernel); |
| 94 | ASSERT(cur_process != nullptr); | 94 | ASSERT(cur_process != nullptr); |
| 95 | return cur_process; | 95 | return cur_process; |
| 96 | } | 96 | } |
diff --git a/src/core/hle/kernel/k_interrupt_manager.cpp b/src/core/hle/kernel/k_interrupt_manager.cpp index 4a6b60d26..fe6a20168 100644 --- a/src/core/hle/kernel/k_interrupt_manager.cpp +++ b/src/core/hle/kernel/k_interrupt_manager.cpp | |||
| @@ -16,7 +16,7 @@ void HandleInterrupt(KernelCore& kernel, s32 core_id) { | |||
| 16 | 16 | ||
| 17 | auto& current_thread = GetCurrentThread(kernel); | 17 | auto& current_thread = GetCurrentThread(kernel); |
| 18 | 18 | ||
| 19 | if (auto* process = kernel.CurrentProcess(); process) { | 19 | if (auto* process = GetCurrentProcessPointer(kernel); process) { |
| 20 | // If the user disable count is set, we may need to pin the current thread. | 20 | // If the user disable count is set, we may need to pin the current thread. |
| 21 | if (current_thread.GetUserDisableCount() && !process->GetPinnedThread(core_id)) { | 21 | if (current_thread.GetUserDisableCount() && !process->GetPinnedThread(core_id)) { |
| 22 | KScopedSchedulerLock sl{kernel}; | 22 | KScopedSchedulerLock sl{kernel}; |
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp index d6676904b..d6c214237 100644 --- a/src/core/hle/kernel/k_scheduler.cpp +++ b/src/core/hle/kernel/k_scheduler.cpp | |||
| @@ -328,7 +328,7 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) { | |||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | void KScheduler::SwitchThread(KThread* next_thread) { | 330 | void KScheduler::SwitchThread(KThread* next_thread) { |
| 331 | KProcess* const cur_process = kernel.CurrentProcess(); | 331 | KProcess* const cur_process = GetCurrentProcessPointer(kernel); |
| 332 | KThread* const cur_thread = GetCurrentThreadPointer(kernel); | 332 | KThread* const cur_thread = GetCurrentThreadPointer(kernel); |
| 333 | 333 | ||
| 334 | // We never want to schedule a null thread, so use the idle thread if we don't have a next. | 334 | // We never want to schedule a null thread, so use the idle thread if we don't have a next. |
| @@ -689,11 +689,11 @@ void KScheduler::RotateScheduledQueue(KernelCore& kernel, s32 core_id, s32 prior | |||
| 689 | void KScheduler::YieldWithoutCoreMigration(KernelCore& kernel) { | 689 | void KScheduler::YieldWithoutCoreMigration(KernelCore& kernel) { |
| 690 | // Validate preconditions. | 690 | // Validate preconditions. |
| 691 | ASSERT(CanSchedule(kernel)); | 691 | ASSERT(CanSchedule(kernel)); |
| 692 | ASSERT(kernel.CurrentProcess() != nullptr); | 692 | ASSERT(GetCurrentProcessPointer(kernel) != nullptr); |
| 693 | 693 | ||
| 694 | // Get the current thread and process. | 694 | // Get the current thread and process. |
| 695 | KThread& cur_thread = GetCurrentThread(kernel); | 695 | KThread& cur_thread = GetCurrentThread(kernel); |
| 696 | KProcess& cur_process = *kernel.CurrentProcess(); | 696 | KProcess& cur_process = GetCurrentProcess(kernel); |
| 697 | 697 | ||
| 698 | // If the thread's yield count matches, there's nothing for us to do. | 698 | // If the thread's yield count matches, there's nothing for us to do. |
| 699 | if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { | 699 | if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { |
| @@ -728,11 +728,11 @@ void KScheduler::YieldWithoutCoreMigration(KernelCore& kernel) { | |||
| 728 | void KScheduler::YieldWithCoreMigration(KernelCore& kernel) { | 728 | void KScheduler::YieldWithCoreMigration(KernelCore& kernel) { |
| 729 | // Validate preconditions. | 729 | // Validate preconditions. |
| 730 | ASSERT(CanSchedule(kernel)); | 730 | ASSERT(CanSchedule(kernel)); |
| 731 | ASSERT(kernel.CurrentProcess() != nullptr); | 731 | ASSERT(GetCurrentProcessPointer(kernel) != nullptr); |
| 732 | 732 | ||
| 733 | // Get the current thread and process. | 733 | // Get the current thread and process. |
| 734 | KThread& cur_thread = GetCurrentThread(kernel); | 734 | KThread& cur_thread = GetCurrentThread(kernel); |
| 735 | KProcess& cur_process = *kernel.CurrentProcess(); | 735 | KProcess& cur_process = GetCurrentProcess(kernel); |
| 736 | 736 | ||
| 737 | // If the thread's yield count matches, there's nothing for us to do. | 737 | // If the thread's yield count matches, there's nothing for us to do. |
| 738 | if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { | 738 | if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { |
| @@ -816,11 +816,11 @@ void KScheduler::YieldWithCoreMigration(KernelCore& kernel) { | |||
| 816 | void KScheduler::YieldToAnyThread(KernelCore& kernel) { | 816 | void KScheduler::YieldToAnyThread(KernelCore& kernel) { |
| 817 | // Validate preconditions. | 817 | // Validate preconditions. |
| 818 | ASSERT(CanSchedule(kernel)); | 818 | ASSERT(CanSchedule(kernel)); |
| 819 | ASSERT(kernel.CurrentProcess() != nullptr); | 819 | ASSERT(GetCurrentProcessPointer(kernel) != nullptr); |
| 820 | 820 | ||
| 821 | // Get the current thread and process. | 821 | // Get the current thread and process. |
| 822 | KThread& cur_thread = GetCurrentThread(kernel); | 822 | KThread& cur_thread = GetCurrentThread(kernel); |
| 823 | KProcess& cur_process = *kernel.CurrentProcess(); | 823 | KProcess& cur_process = GetCurrentProcess(kernel); |
| 824 | 824 | ||
| 825 | // If the thread's yield count matches, there's nothing for us to do. | 825 | // If the thread's yield count matches, there's nothing for us to do. |
| 826 | if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { | 826 | if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { |
diff --git a/src/core/hle/kernel/k_session.cpp b/src/core/hle/kernel/k_session.cpp index b6f6fe9d9..819f39f12 100644 --- a/src/core/hle/kernel/k_session.cpp +++ b/src/core/hle/kernel/k_session.cpp | |||
| @@ -33,6 +33,7 @@ void KSession::Initialize(KClientPort* port_, const std::string& name_) { | |||
| 33 | name = name_; | 33 | name = name_; |
| 34 | 34 | ||
| 35 | // Set our owner process. | 35 | // Set our owner process. |
| 36 | //! FIXME: this is the wrong process! | ||
| 36 | process = kernel.CurrentProcess(); | 37 | process = kernel.CurrentProcess(); |
| 37 | process->Open(); | 38 | process->Open(); |
| 38 | 39 | ||
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 84ff3c64b..2d3da9d66 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -1266,6 +1266,14 @@ KThread& GetCurrentThread(KernelCore& kernel) { | |||
| 1266 | return *GetCurrentThreadPointer(kernel); | 1266 | return *GetCurrentThreadPointer(kernel); |
| 1267 | } | 1267 | } |
| 1268 | 1268 | ||
| 1269 | KProcess* GetCurrentProcessPointer(KernelCore& kernel) { | ||
| 1270 | return GetCurrentThread(kernel).GetOwnerProcess(); | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | KProcess& GetCurrentProcess(KernelCore& kernel) { | ||
| 1274 | return *GetCurrentProcessPointer(kernel); | ||
| 1275 | } | ||
| 1276 | |||
| 1269 | s32 GetCurrentCoreId(KernelCore& kernel) { | 1277 | s32 GetCurrentCoreId(KernelCore& kernel) { |
| 1270 | return GetCurrentThread(kernel).GetCurrentCore(); | 1278 | return GetCurrentThread(kernel).GetCurrentCore(); |
| 1271 | } | 1279 | } |
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index 8b8dc51be..ca82ce3b6 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h | |||
| @@ -110,6 +110,8 @@ enum class StepState : u32 { | |||
| 110 | void SetCurrentThread(KernelCore& kernel, KThread* thread); | 110 | void SetCurrentThread(KernelCore& kernel, KThread* thread); |
| 111 | [[nodiscard]] KThread* GetCurrentThreadPointer(KernelCore& kernel); | 111 | [[nodiscard]] KThread* GetCurrentThreadPointer(KernelCore& kernel); |
| 112 | [[nodiscard]] KThread& GetCurrentThread(KernelCore& kernel); | 112 | [[nodiscard]] KThread& GetCurrentThread(KernelCore& kernel); |
| 113 | [[nodiscard]] KProcess* GetCurrentProcessPointer(KernelCore& kernel); | ||
| 114 | [[nodiscard]] KProcess& GetCurrentProcess(KernelCore& kernel); | ||
| 113 | [[nodiscard]] s32 GetCurrentCoreId(KernelCore& kernel); | 115 | [[nodiscard]] s32 GetCurrentCoreId(KernelCore& kernel); |
| 114 | 116 | ||
| 115 | class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KWorkerTask>, | 117 | class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KWorkerTask>, |
diff --git a/src/core/hle/kernel/k_transfer_memory.cpp b/src/core/hle/kernel/k_transfer_memory.cpp index 9f34c2d46..faa5c73b5 100644 --- a/src/core/hle/kernel/k_transfer_memory.cpp +++ b/src/core/hle/kernel/k_transfer_memory.cpp | |||
| @@ -16,7 +16,7 @@ KTransferMemory::~KTransferMemory() = default; | |||
| 16 | Result KTransferMemory::Initialize(VAddr address_, std::size_t size_, | 16 | Result KTransferMemory::Initialize(VAddr address_, std::size_t size_, |
| 17 | Svc::MemoryPermission owner_perm_) { | 17 | Svc::MemoryPermission owner_perm_) { |
| 18 | // Set members. | 18 | // Set members. |
| 19 | owner = kernel.CurrentProcess(); | 19 | owner = GetCurrentProcessPointer(kernel); |
| 20 | 20 | ||
| 21 | // TODO(bunnei): Lock for transfer memory | 21 | // TODO(bunnei): Lock for transfer memory |
| 22 | 22 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 4ef57356e..1072da8cc 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -4426,7 +4426,7 @@ void Call(Core::System& system, u32 imm) { | |||
| 4426 | auto& kernel = system.Kernel(); | 4426 | auto& kernel = system.Kernel(); |
| 4427 | kernel.EnterSVCProfile(); | 4427 | kernel.EnterSVCProfile(); |
| 4428 | 4428 | ||
| 4429 | if (system.CurrentProcess()->Is64BitProcess()) { | 4429 | if (GetCurrentProcess(system.Kernel()).Is64BitProcess()) { |
| 4430 | Call64(system, imm); | 4430 | Call64(system, imm); |
| 4431 | } else { | 4431 | } else { |
| 4432 | Call32(system, imm); | 4432 | Call32(system, imm); |
diff --git a/src/core/hle/kernel/svc/svc_activity.cpp b/src/core/hle/kernel/svc/svc_activity.cpp index 1dcdb7a15..2e7b680d0 100644 --- a/src/core/hle/kernel/svc/svc_activity.cpp +++ b/src/core/hle/kernel/svc/svc_activity.cpp | |||
| @@ -23,11 +23,12 @@ Result SetThreadActivity(Core::System& system, Handle thread_handle, | |||
| 23 | 23 | ||
| 24 | // Get the thread from its handle. | 24 | // Get the thread from its handle. |
| 25 | KScopedAutoObject thread = | 25 | KScopedAutoObject thread = |
| 26 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); | 26 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle); |
| 27 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 27 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 28 | 28 | ||
| 29 | // Check that the activity is being set on a non-current thread for the current process. | 29 | // Check that the activity is being set on a non-current thread for the current process. |
| 30 | R_UNLESS(thread->GetOwnerProcess() == system.Kernel().CurrentProcess(), ResultInvalidHandle); | 30 | R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()), |
| 31 | ResultInvalidHandle); | ||
| 31 | R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy); | 32 | R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy); |
| 32 | 33 | ||
| 33 | // Set the activity. | 34 | // Set the activity. |
diff --git a/src/core/hle/kernel/svc/svc_address_arbiter.cpp b/src/core/hle/kernel/svc/svc_address_arbiter.cpp index e6a5d2ae5..998bd3f22 100644 --- a/src/core/hle/kernel/svc/svc_address_arbiter.cpp +++ b/src/core/hle/kernel/svc/svc_address_arbiter.cpp | |||
| @@ -72,7 +72,7 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t | |||
| 72 | timeout = timeout_ns; | 72 | timeout = timeout_ns; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | return system.Kernel().CurrentProcess()->WaitAddressArbiter(address, arb_type, value, timeout); | 75 | return GetCurrentProcess(system.Kernel()).WaitAddressArbiter(address, arb_type, value, timeout); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // Signals to an address (via Address Arbiter) | 78 | // Signals to an address (via Address Arbiter) |
| @@ -95,8 +95,8 @@ Result SignalToAddress(Core::System& system, VAddr address, SignalType signal_ty | |||
| 95 | return ResultInvalidEnumValue; | 95 | return ResultInvalidEnumValue; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | return system.Kernel().CurrentProcess()->SignalAddressArbiter(address, signal_type, value, | 98 | return GetCurrentProcess(system.Kernel()) |
| 99 | count); | 99 | .SignalAddressArbiter(address, signal_type, value, count); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value, | 102 | Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value, |
diff --git a/src/core/hle/kernel/svc/svc_cache.cpp b/src/core/hle/kernel/svc/svc_cache.cpp index b5404760e..598b71da5 100644 --- a/src/core/hle/kernel/svc/svc_cache.cpp +++ b/src/core/hle/kernel/svc/svc_cache.cpp | |||
| @@ -38,7 +38,7 @@ Result FlushProcessDataCache(Core::System& system, Handle process_handle, u64 ad | |||
| 38 | 38 | ||
| 39 | // Get the process from its handle. | 39 | // Get the process from its handle. |
| 40 | KScopedAutoObject process = | 40 | KScopedAutoObject process = |
| 41 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); | 41 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle); |
| 42 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); | 42 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); |
| 43 | 43 | ||
| 44 | // Verify the region is within range. | 44 | // Verify the region is within range. |
diff --git a/src/core/hle/kernel/svc/svc_code_memory.cpp b/src/core/hle/kernel/svc/svc_code_memory.cpp index ec256b757..538ff1c71 100644 --- a/src/core/hle/kernel/svc/svc_code_memory.cpp +++ b/src/core/hle/kernel/svc/svc_code_memory.cpp | |||
| @@ -46,7 +46,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, size_t | |||
| 46 | R_UNLESS(code_mem != nullptr, ResultOutOfResource); | 46 | R_UNLESS(code_mem != nullptr, ResultOutOfResource); |
| 47 | 47 | ||
| 48 | // Verify that the region is in range. | 48 | // Verify that the region is in range. |
| 49 | R_UNLESS(system.CurrentProcess()->PageTable().Contains(address, size), | 49 | R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size), |
| 50 | ResultInvalidCurrentMemory); | 50 | ResultInvalidCurrentMemory); |
| 51 | 51 | ||
| 52 | // Initialize the code memory. | 52 | // Initialize the code memory. |
| @@ -56,7 +56,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, size_t | |||
| 56 | KCodeMemory::Register(kernel, code_mem); | 56 | KCodeMemory::Register(kernel, code_mem); |
| 57 | 57 | ||
| 58 | // Add the code memory to the handle table. | 58 | // Add the code memory to the handle table. |
| 59 | R_TRY(system.CurrentProcess()->GetHandleTable().Add(out, code_mem)); | 59 | R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem)); |
| 60 | 60 | ||
| 61 | code_mem->Close(); | 61 | code_mem->Close(); |
| 62 | 62 | ||
| @@ -79,8 +79,9 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, | |||
| 79 | R_UNLESS((address < address + size), ResultInvalidCurrentMemory); | 79 | R_UNLESS((address < address + size), ResultInvalidCurrentMemory); |
| 80 | 80 | ||
| 81 | // Get the code memory from its handle. | 81 | // Get the code memory from its handle. |
| 82 | KScopedAutoObject code_mem = | 82 | KScopedAutoObject code_mem = GetCurrentProcess(system.Kernel()) |
| 83 | system.CurrentProcess()->GetHandleTable().GetObject<KCodeMemory>(code_memory_handle); | 83 | .GetHandleTable() |
| 84 | .GetObject<KCodeMemory>(code_memory_handle); | ||
| 84 | R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle); | 85 | R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle); |
| 85 | 86 | ||
| 86 | // NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process. | 87 | // NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process. |
| @@ -90,9 +91,10 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, | |||
| 90 | switch (operation) { | 91 | switch (operation) { |
| 91 | case CodeMemoryOperation::Map: { | 92 | case CodeMemoryOperation::Map: { |
| 92 | // Check that the region is in range. | 93 | // Check that the region is in range. |
| 93 | R_UNLESS( | 94 | R_UNLESS(GetCurrentProcess(system.Kernel()) |
| 94 | system.CurrentProcess()->PageTable().CanContain(address, size, KMemoryState::CodeOut), | 95 | .PageTable() |
| 95 | ResultInvalidMemoryRegion); | 96 | .CanContain(address, size, KMemoryState::CodeOut), |
| 97 | ResultInvalidMemoryRegion); | ||
| 96 | 98 | ||
| 97 | // Check the memory permission. | 99 | // Check the memory permission. |
| 98 | R_UNLESS(IsValidMapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission); | 100 | R_UNLESS(IsValidMapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission); |
| @@ -102,9 +104,10 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, | |||
| 102 | } break; | 104 | } break; |
| 103 | case CodeMemoryOperation::Unmap: { | 105 | case CodeMemoryOperation::Unmap: { |
| 104 | // Check that the region is in range. | 106 | // Check that the region is in range. |
| 105 | R_UNLESS( | 107 | R_UNLESS(GetCurrentProcess(system.Kernel()) |
| 106 | system.CurrentProcess()->PageTable().CanContain(address, size, KMemoryState::CodeOut), | 108 | .PageTable() |
| 107 | ResultInvalidMemoryRegion); | 109 | .CanContain(address, size, KMemoryState::CodeOut), |
| 110 | ResultInvalidMemoryRegion); | ||
| 108 | 111 | ||
| 109 | // Check the memory permission. | 112 | // Check the memory permission. |
| 110 | R_UNLESS(IsValidUnmapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission); | 113 | R_UNLESS(IsValidUnmapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission); |
diff --git a/src/core/hle/kernel/svc/svc_condition_variable.cpp b/src/core/hle/kernel/svc/svc_condition_variable.cpp index b59a33e68..8ad1a0b8f 100644 --- a/src/core/hle/kernel/svc/svc_condition_variable.cpp +++ b/src/core/hle/kernel/svc/svc_condition_variable.cpp | |||
| @@ -43,8 +43,8 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke | |||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | // Wait on the condition variable. | 45 | // Wait on the condition variable. |
| 46 | return system.Kernel().CurrentProcess()->WaitConditionVariable( | 46 | return GetCurrentProcess(system.Kernel()) |
| 47 | address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); | 47 | .WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | /// Signal process wide key | 50 | /// Signal process wide key |
| @@ -52,8 +52,8 @@ void SignalProcessWideKey(Core::System& system, VAddr cv_key, s32 count) { | |||
| 52 | LOG_TRACE(Kernel_SVC, "called, cv_key=0x{:X}, count=0x{:08X}", cv_key, count); | 52 | LOG_TRACE(Kernel_SVC, "called, cv_key=0x{:X}, count=0x{:08X}", cv_key, count); |
| 53 | 53 | ||
| 54 | // Signal the condition variable. | 54 | // Signal the condition variable. |
| 55 | return system.Kernel().CurrentProcess()->SignalConditionVariable( | 55 | return GetCurrentProcess(system.Kernel()) |
| 56 | Common::AlignDown(cv_key, sizeof(u32)), count); | 56 | .SignalConditionVariable(Common::AlignDown(cv_key, sizeof(u32)), count); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | Result WaitProcessWideKeyAtomic64(Core::System& system, uint64_t address, uint64_t cv_key, | 59 | Result WaitProcessWideKeyAtomic64(Core::System& system, uint64_t address, uint64_t cv_key, |
diff --git a/src/core/hle/kernel/svc/svc_device_address_space.cpp b/src/core/hle/kernel/svc/svc_device_address_space.cpp index cdc453c35..f68c0e6a9 100644 --- a/src/core/hle/kernel/svc/svc_device_address_space.cpp +++ b/src/core/hle/kernel/svc/svc_device_address_space.cpp | |||
| @@ -37,15 +37,16 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_ | |||
| 37 | KDeviceAddressSpace::Register(system.Kernel(), das); | 37 | KDeviceAddressSpace::Register(system.Kernel(), das); |
| 38 | 38 | ||
| 39 | // Add to the handle table. | 39 | // Add to the handle table. |
| 40 | R_TRY(system.CurrentProcess()->GetHandleTable().Add(out, das)); | 40 | R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, das)); |
| 41 | 41 | ||
| 42 | R_SUCCEED(); | 42 | R_SUCCEED(); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) { | 45 | Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) { |
| 46 | // Get the device address space. | 46 | // Get the device address space. |
| 47 | KScopedAutoObject das = | 47 | KScopedAutoObject das = GetCurrentProcess(system.Kernel()) |
| 48 | system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); | 48 | .GetHandleTable() |
| 49 | .GetObject<KDeviceAddressSpace>(das_handle); | ||
| 49 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); | 50 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); |
| 50 | 51 | ||
| 51 | // Attach. | 52 | // Attach. |
| @@ -54,8 +55,9 @@ Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Ha | |||
| 54 | 55 | ||
| 55 | Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) { | 56 | Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) { |
| 56 | // Get the device address space. | 57 | // Get the device address space. |
| 57 | KScopedAutoObject das = | 58 | KScopedAutoObject das = GetCurrentProcess(system.Kernel()) |
| 58 | system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); | 59 | .GetHandleTable() |
| 60 | .GetObject<KDeviceAddressSpace>(das_handle); | ||
| 59 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); | 61 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); |
| 60 | 62 | ||
| 61 | // Detach. | 63 | // Detach. |
| @@ -94,13 +96,14 @@ Result MapDeviceAddressSpaceByForce(Core::System& system, Handle das_handle, Han | |||
| 94 | R_UNLESS(reserved == 0, ResultInvalidEnumValue); | 96 | R_UNLESS(reserved == 0, ResultInvalidEnumValue); |
| 95 | 97 | ||
| 96 | // Get the device address space. | 98 | // Get the device address space. |
| 97 | KScopedAutoObject das = | 99 | KScopedAutoObject das = GetCurrentProcess(system.Kernel()) |
| 98 | system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); | 100 | .GetHandleTable() |
| 101 | .GetObject<KDeviceAddressSpace>(das_handle); | ||
| 99 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); | 102 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); |
| 100 | 103 | ||
| 101 | // Get the process. | 104 | // Get the process. |
| 102 | KScopedAutoObject process = | 105 | KScopedAutoObject process = |
| 103 | system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); | 106 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle); |
| 104 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); | 107 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); |
| 105 | 108 | ||
| 106 | // Validate that the process address is within range. | 109 | // Validate that the process address is within range. |
| @@ -134,13 +137,14 @@ Result MapDeviceAddressSpaceAligned(Core::System& system, Handle das_handle, Han | |||
| 134 | R_UNLESS(reserved == 0, ResultInvalidEnumValue); | 137 | R_UNLESS(reserved == 0, ResultInvalidEnumValue); |
| 135 | 138 | ||
| 136 | // Get the device address space. | 139 | // Get the device address space. |
| 137 | KScopedAutoObject das = | 140 | KScopedAutoObject das = GetCurrentProcess(system.Kernel()) |
| 138 | system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); | 141 | .GetHandleTable() |
| 142 | .GetObject<KDeviceAddressSpace>(das_handle); | ||
| 139 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); | 143 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); |
| 140 | 144 | ||
| 141 | // Get the process. | 145 | // Get the process. |
| 142 | KScopedAutoObject process = | 146 | KScopedAutoObject process = |
| 143 | system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); | 147 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle); |
| 144 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); | 148 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); |
| 145 | 149 | ||
| 146 | // Validate that the process address is within range. | 150 | // Validate that the process address is within range. |
| @@ -165,13 +169,14 @@ Result UnmapDeviceAddressSpace(Core::System& system, Handle das_handle, Handle p | |||
| 165 | ResultInvalidCurrentMemory); | 169 | ResultInvalidCurrentMemory); |
| 166 | 170 | ||
| 167 | // Get the device address space. | 171 | // Get the device address space. |
| 168 | KScopedAutoObject das = | 172 | KScopedAutoObject das = GetCurrentProcess(system.Kernel()) |
| 169 | system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); | 173 | .GetHandleTable() |
| 174 | .GetObject<KDeviceAddressSpace>(das_handle); | ||
| 170 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); | 175 | R_UNLESS(das.IsNotNull(), ResultInvalidHandle); |
| 171 | 176 | ||
| 172 | // Get the process. | 177 | // Get the process. |
| 173 | KScopedAutoObject process = | 178 | KScopedAutoObject process = |
| 174 | system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); | 179 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle); |
| 175 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); | 180 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); |
| 176 | 181 | ||
| 177 | // Validate that the process address is within range. | 182 | // Validate that the process address is within range. |
diff --git a/src/core/hle/kernel/svc/svc_event.cpp b/src/core/hle/kernel/svc/svc_event.cpp index e8fb9efbc..a948493e8 100644 --- a/src/core/hle/kernel/svc/svc_event.cpp +++ b/src/core/hle/kernel/svc/svc_event.cpp | |||
| @@ -15,7 +15,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) { | |||
| 15 | LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); | 15 | LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); |
| 16 | 16 | ||
| 17 | // Get the current handle table. | 17 | // Get the current handle table. |
| 18 | const KHandleTable& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 18 | const KHandleTable& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 19 | 19 | ||
| 20 | // Get the event. | 20 | // Get the event. |
| 21 | KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); | 21 | KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); |
| @@ -28,7 +28,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) { | |||
| 28 | LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); | 28 | LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); |
| 29 | 29 | ||
| 30 | // Get the current handle table. | 30 | // Get the current handle table. |
| 31 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 31 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 32 | 32 | ||
| 33 | // Try to clear the writable event. | 33 | // Try to clear the writable event. |
| 34 | { | 34 | { |
| @@ -56,10 +56,10 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { | |||
| 56 | 56 | ||
| 57 | // Get the kernel reference and handle table. | 57 | // Get the kernel reference and handle table. |
| 58 | auto& kernel = system.Kernel(); | 58 | auto& kernel = system.Kernel(); |
| 59 | auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); | 59 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); |
| 60 | 60 | ||
| 61 | // Reserve a new event from the process resource limit | 61 | // Reserve a new event from the process resource limit |
| 62 | KScopedResourceReservation event_reservation(kernel.CurrentProcess(), | 62 | KScopedResourceReservation event_reservation(GetCurrentProcessPointer(kernel), |
| 63 | LimitableResource::EventCountMax); | 63 | LimitableResource::EventCountMax); |
| 64 | R_UNLESS(event_reservation.Succeeded(), ResultLimitReached); | 64 | R_UNLESS(event_reservation.Succeeded(), ResultLimitReached); |
| 65 | 65 | ||
| @@ -68,7 +68,7 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { | |||
| 68 | R_UNLESS(event != nullptr, ResultOutOfResource); | 68 | R_UNLESS(event != nullptr, ResultOutOfResource); |
| 69 | 69 | ||
| 70 | // Initialize the event. | 70 | // Initialize the event. |
| 71 | event->Initialize(kernel.CurrentProcess()); | 71 | event->Initialize(GetCurrentProcessPointer(kernel)); |
| 72 | 72 | ||
| 73 | // Commit the thread reservation. | 73 | // Commit the thread reservation. |
| 74 | event_reservation.Commit(); | 74 | event_reservation.Commit(); |
diff --git a/src/core/hle/kernel/svc/svc_info.cpp b/src/core/hle/kernel/svc/svc_info.cpp index ad56e2fe6..58dc47508 100644 --- a/src/core/hle/kernel/svc/svc_info.cpp +++ b/src/core/hle/kernel/svc/svc_info.cpp | |||
| @@ -44,7 +44,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 44 | return ResultInvalidEnumValue; | 44 | return ResultInvalidEnumValue; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 47 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 48 | KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); | 48 | KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); |
| 49 | if (process.IsNull()) { | 49 | if (process.IsNull()) { |
| 50 | LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}", | 50 | LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}", |
| @@ -154,7 +154,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 154 | return ResultInvalidCombination; | 154 | return ResultInvalidCombination; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | KProcess* const current_process = system.Kernel().CurrentProcess(); | 157 | KProcess* const current_process = GetCurrentProcessPointer(system.Kernel()); |
| 158 | KHandleTable& handle_table = current_process->GetHandleTable(); | 158 | KHandleTable& handle_table = current_process->GetHandleTable(); |
| 159 | const auto resource_limit = current_process->GetResourceLimit(); | 159 | const auto resource_limit = current_process->GetResourceLimit(); |
| 160 | if (!resource_limit) { | 160 | if (!resource_limit) { |
| @@ -183,7 +183,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 183 | return ResultInvalidCombination; | 183 | return ResultInvalidCombination; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | *result = system.Kernel().CurrentProcess()->GetRandomEntropy(info_sub_id); | 186 | *result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id); |
| 187 | return ResultSuccess; | 187 | return ResultSuccess; |
| 188 | 188 | ||
| 189 | case InfoType::InitialProcessIdRange: | 189 | case InfoType::InitialProcessIdRange: |
| @@ -200,9 +200,9 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 200 | return ResultInvalidCombination; | 200 | return ResultInvalidCombination; |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | KScopedAutoObject thread = | 203 | KScopedAutoObject thread = GetCurrentProcess(system.Kernel()) |
| 204 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>( | 204 | .GetHandleTable() |
| 205 | static_cast<Handle>(handle)); | 205 | .GetObject<KThread>(static_cast<Handle>(handle)); |
| 206 | if (thread.IsNull()) { | 206 | if (thread.IsNull()) { |
| 207 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", | 207 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", |
| 208 | static_cast<Handle>(handle)); | 208 | static_cast<Handle>(handle)); |
| @@ -249,7 +249,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 249 | R_UNLESS(info_sub_id == 0, ResultInvalidCombination); | 249 | R_UNLESS(info_sub_id == 0, ResultInvalidCombination); |
| 250 | 250 | ||
| 251 | // Get the handle table. | 251 | // Get the handle table. |
| 252 | KProcess* current_process = system.Kernel().CurrentProcess(); | 252 | KProcess* current_process = GetCurrentProcessPointer(system.Kernel()); |
| 253 | KHandleTable& handle_table = current_process->GetHandleTable(); | 253 | KHandleTable& handle_table = current_process->GetHandleTable(); |
| 254 | 254 | ||
| 255 | // Get a new handle for the current process. | 255 | // Get a new handle for the current process. |
diff --git a/src/core/hle/kernel/svc/svc_ipc.cpp b/src/core/hle/kernel/svc/svc_ipc.cpp index 97ce49dde..a7a2c3b92 100644 --- a/src/core/hle/kernel/svc/svc_ipc.cpp +++ b/src/core/hle/kernel/svc/svc_ipc.cpp | |||
| @@ -12,11 +12,9 @@ namespace Kernel::Svc { | |||
| 12 | 12 | ||
| 13 | /// Makes a blocking IPC call to a service. | 13 | /// Makes a blocking IPC call to a service. |
| 14 | Result SendSyncRequest(Core::System& system, Handle handle) { | 14 | Result SendSyncRequest(Core::System& system, Handle handle) { |
| 15 | auto& kernel = system.Kernel(); | ||
| 16 | |||
| 17 | // Get the client session from its handle. | 15 | // Get the client session from its handle. |
| 18 | KScopedAutoObject session = | 16 | KScopedAutoObject session = |
| 19 | kernel.CurrentProcess()->GetHandleTable().GetObject<KClientSession>(handle); | 17 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KClientSession>(handle); |
| 20 | R_UNLESS(session.IsNotNull(), ResultInvalidHandle); | 18 | R_UNLESS(session.IsNotNull(), ResultInvalidHandle); |
| 21 | 19 | ||
| 22 | LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); | 20 | LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); |
| @@ -40,7 +38,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha | |||
| 40 | Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles, | 38 | Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles, |
| 41 | Handle reply_target, s64 timeout_ns) { | 39 | Handle reply_target, s64 timeout_ns) { |
| 42 | auto& kernel = system.Kernel(); | 40 | auto& kernel = system.Kernel(); |
| 43 | auto& handle_table = GetCurrentThread(kernel).GetOwnerProcess()->GetHandleTable(); | 41 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); |
| 44 | 42 | ||
| 45 | R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); | 43 | R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); |
| 46 | R_UNLESS(system.Memory().IsValidVirtualAddressRange( | 44 | R_UNLESS(system.Memory().IsValidVirtualAddressRange( |
diff --git a/src/core/hle/kernel/svc/svc_lock.cpp b/src/core/hle/kernel/svc/svc_lock.cpp index 7005ac30b..f3d3e140b 100644 --- a/src/core/hle/kernel/svc/svc_lock.cpp +++ b/src/core/hle/kernel/svc/svc_lock.cpp | |||
| @@ -24,7 +24,7 @@ Result ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address, | |||
| 24 | return ResultInvalidAddress; | 24 | return ResultInvalidAddress; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | return system.Kernel().CurrentProcess()->WaitForAddress(thread_handle, address, tag); | 27 | return GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | /// Unlock a mutex | 30 | /// Unlock a mutex |
| @@ -43,7 +43,7 @@ Result ArbitrateUnlock(Core::System& system, VAddr address) { | |||
| 43 | return ResultInvalidAddress; | 43 | return ResultInvalidAddress; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | return system.Kernel().CurrentProcess()->SignalToAddress(address); | 46 | return GetCurrentProcess(system.Kernel()).SignalToAddress(address); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) { | 49 | Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) { |
diff --git a/src/core/hle/kernel/svc/svc_memory.cpp b/src/core/hle/kernel/svc/svc_memory.cpp index 21f818da6..214bcd073 100644 --- a/src/core/hle/kernel/svc/svc_memory.cpp +++ b/src/core/hle/kernel/svc/svc_memory.cpp | |||
| @@ -113,7 +113,7 @@ Result SetMemoryPermission(Core::System& system, VAddr address, u64 size, Memory | |||
| 113 | R_UNLESS(IsValidSetMemoryPermission(perm), ResultInvalidNewMemoryPermission); | 113 | R_UNLESS(IsValidSetMemoryPermission(perm), ResultInvalidNewMemoryPermission); |
| 114 | 114 | ||
| 115 | // Validate that the region is in range for the current process. | 115 | // Validate that the region is in range for the current process. |
| 116 | auto& page_table = system.Kernel().CurrentProcess()->PageTable(); | 116 | auto& page_table = GetCurrentProcess(system.Kernel()).PageTable(); |
| 117 | R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); | 117 | R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); |
| 118 | 118 | ||
| 119 | // Set the memory attribute. | 119 | // Set the memory attribute. |
| @@ -137,7 +137,7 @@ Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mas | |||
| 137 | R_UNLESS((mask | attr | SupportedMask) == SupportedMask, ResultInvalidCombination); | 137 | R_UNLESS((mask | attr | SupportedMask) == SupportedMask, ResultInvalidCombination); |
| 138 | 138 | ||
| 139 | // Validate that the region is in range for the current process. | 139 | // Validate that the region is in range for the current process. |
| 140 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; | 140 | auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()}; |
| 141 | R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); | 141 | R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); |
| 142 | 142 | ||
| 143 | // Set the memory attribute. | 143 | // Set the memory attribute. |
| @@ -149,7 +149,7 @@ Result MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size) | |||
| 149 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, | 149 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, |
| 150 | src_addr, size); | 150 | src_addr, size); |
| 151 | 151 | ||
| 152 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; | 152 | auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()}; |
| 153 | 153 | ||
| 154 | if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; | 154 | if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; |
| 155 | result.IsError()) { | 155 | result.IsError()) { |
| @@ -164,7 +164,7 @@ Result UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 siz | |||
| 164 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, | 164 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, |
| 165 | src_addr, size); | 165 | src_addr, size); |
| 166 | 166 | ||
| 167 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; | 167 | auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()}; |
| 168 | 168 | ||
| 169 | if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; | 169 | if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; |
| 170 | result.IsError()) { | 170 | result.IsError()) { |
diff --git a/src/core/hle/kernel/svc/svc_physical_memory.cpp b/src/core/hle/kernel/svc/svc_physical_memory.cpp index 8d00e1fc3..a1f534454 100644 --- a/src/core/hle/kernel/svc/svc_physical_memory.cpp +++ b/src/core/hle/kernel/svc/svc_physical_memory.cpp | |||
| @@ -16,7 +16,7 @@ Result SetHeapSize(Core::System& system, VAddr* out_address, u64 size) { | |||
| 16 | R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize); | 16 | R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize); |
| 17 | 17 | ||
| 18 | // Set the heap size. | 18 | // Set the heap size. |
| 19 | R_TRY(system.Kernel().CurrentProcess()->PageTable().SetHeapSize(out_address, size)); | 19 | R_TRY(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size)); |
| 20 | 20 | ||
| 21 | return ResultSuccess; | 21 | return ResultSuccess; |
| 22 | } | 22 | } |
| @@ -45,7 +45,7 @@ Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { | |||
| 45 | return ResultInvalidMemoryRegion; | 45 | return ResultInvalidMemoryRegion; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | KProcess* const current_process{system.Kernel().CurrentProcess()}; | 48 | KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; |
| 49 | auto& page_table{current_process->PageTable()}; | 49 | auto& page_table{current_process->PageTable()}; |
| 50 | 50 | ||
| 51 | if (current_process->GetSystemResourceSize() == 0) { | 51 | if (current_process->GetSystemResourceSize() == 0) { |
| @@ -94,7 +94,7 @@ Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { | |||
| 94 | return ResultInvalidMemoryRegion; | 94 | return ResultInvalidMemoryRegion; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | KProcess* const current_process{system.Kernel().CurrentProcess()}; | 97 | KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; |
| 98 | auto& page_table{current_process->PageTable()}; | 98 | auto& page_table{current_process->PageTable()}; |
| 99 | 99 | ||
| 100 | if (current_process->GetSystemResourceSize() == 0) { | 100 | if (current_process->GetSystemResourceSize() == 0) { |
diff --git a/src/core/hle/kernel/svc/svc_port.cpp b/src/core/hle/kernel/svc/svc_port.cpp index 2e5d228bb..2b7cebde5 100644 --- a/src/core/hle/kernel/svc/svc_port.cpp +++ b/src/core/hle/kernel/svc/svc_port.cpp | |||
| @@ -34,7 +34,7 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, VAddr port_name_add | |||
| 34 | 34 | ||
| 35 | // Get the current handle table. | 35 | // Get the current handle table. |
| 36 | auto& kernel = system.Kernel(); | 36 | auto& kernel = system.Kernel(); |
| 37 | auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); | 37 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); |
| 38 | 38 | ||
| 39 | // Find the client port. | 39 | // Find the client port. |
| 40 | auto port = kernel.CreateNamedServicePort(port_name); | 40 | auto port = kernel.CreateNamedServicePort(port_name); |
diff --git a/src/core/hle/kernel/svc/svc_process.cpp b/src/core/hle/kernel/svc/svc_process.cpp index d2c20aad2..c35d2be76 100644 --- a/src/core/hle/kernel/svc/svc_process.cpp +++ b/src/core/hle/kernel/svc/svc_process.cpp | |||
| @@ -9,7 +9,7 @@ namespace Kernel::Svc { | |||
| 9 | 9 | ||
| 10 | /// Exits the current process | 10 | /// Exits the current process |
| 11 | void ExitProcess(Core::System& system) { | 11 | void ExitProcess(Core::System& system) { |
| 12 | auto* current_process = system.Kernel().CurrentProcess(); | 12 | auto* current_process = GetCurrentProcessPointer(system.Kernel()); |
| 13 | 13 | ||
| 14 | LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessID()); | 14 | LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessID()); |
| 15 | ASSERT_MSG(current_process->GetState() == KProcess::State::Running, | 15 | ASSERT_MSG(current_process->GetState() == KProcess::State::Running, |
| @@ -23,9 +23,9 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) { | |||
| 23 | LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); | 23 | LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); |
| 24 | 24 | ||
| 25 | // Get the object from the handle table. | 25 | // Get the object from the handle table. |
| 26 | KScopedAutoObject obj = | 26 | KScopedAutoObject obj = GetCurrentProcess(system.Kernel()) |
| 27 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KAutoObject>( | 27 | .GetHandleTable() |
| 28 | static_cast<Handle>(handle)); | 28 | .GetObject<KAutoObject>(static_cast<Handle>(handle)); |
| 29 | R_UNLESS(obj.IsNotNull(), ResultInvalidHandle); | 29 | R_UNLESS(obj.IsNotNull(), ResultInvalidHandle); |
| 30 | 30 | ||
| 31 | // Get the process from the object. | 31 | // Get the process from the object. |
| @@ -63,10 +63,10 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr | |||
| 63 | return ResultOutOfRange; | 63 | return ResultOutOfRange; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | const auto& kernel = system.Kernel(); | 66 | auto& kernel = system.Kernel(); |
| 67 | const auto total_copy_size = out_process_ids_size * sizeof(u64); | 67 | const auto total_copy_size = out_process_ids_size * sizeof(u64); |
| 68 | 68 | ||
| 69 | if (out_process_ids_size > 0 && !kernel.CurrentProcess()->PageTable().IsInsideAddressSpace( | 69 | if (out_process_ids_size > 0 && !GetCurrentProcess(kernel).PageTable().IsInsideAddressSpace( |
| 70 | out_process_ids, total_copy_size)) { | 70 | out_process_ids, total_copy_size)) { |
| 71 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", | 71 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", |
| 72 | out_process_ids, out_process_ids + total_copy_size); | 72 | out_process_ids, out_process_ids + total_copy_size); |
| @@ -92,7 +92,7 @@ Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle, | |||
| 92 | ProcessInfoType info_type) { | 92 | ProcessInfoType info_type) { |
| 93 | LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type=0x{:X}", process_handle, info_type); | 93 | LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type=0x{:X}", process_handle, info_type); |
| 94 | 94 | ||
| 95 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 95 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 96 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); | 96 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); |
| 97 | if (process.IsNull()) { | 97 | if (process.IsNull()) { |
| 98 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", | 98 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
diff --git a/src/core/hle/kernel/svc/svc_process_memory.cpp b/src/core/hle/kernel/svc/svc_process_memory.cpp index dbe24e139..4dfd9e5bb 100644 --- a/src/core/hle/kernel/svc/svc_process_memory.cpp +++ b/src/core/hle/kernel/svc/svc_process_memory.cpp | |||
| @@ -45,7 +45,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, V | |||
| 45 | 45 | ||
| 46 | // Get the process from its handle. | 46 | // Get the process from its handle. |
| 47 | KScopedAutoObject process = | 47 | KScopedAutoObject process = |
| 48 | system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); | 48 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle); |
| 49 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); | 49 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); |
| 50 | 50 | ||
| 51 | // Validate that the address is in range. | 51 | // Validate that the address is in range. |
| @@ -71,7 +71,7 @@ Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_ | |||
| 71 | R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory); | 71 | R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory); |
| 72 | 72 | ||
| 73 | // Get the processes. | 73 | // Get the processes. |
| 74 | KProcess* dst_process = system.CurrentProcess(); | 74 | KProcess* dst_process = GetCurrentProcessPointer(system.Kernel()); |
| 75 | KScopedAutoObject src_process = | 75 | KScopedAutoObject src_process = |
| 76 | dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle); | 76 | dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle); |
| 77 | R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); | 77 | R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); |
| @@ -114,7 +114,7 @@ Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle proces | |||
| 114 | R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory); | 114 | R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory); |
| 115 | 115 | ||
| 116 | // Get the processes. | 116 | // Get the processes. |
| 117 | KProcess* dst_process = system.CurrentProcess(); | 117 | KProcess* dst_process = GetCurrentProcessPointer(system.Kernel()); |
| 118 | KScopedAutoObject src_process = | 118 | KScopedAutoObject src_process = |
| 119 | dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle); | 119 | dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle); |
| 120 | R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); | 120 | R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); |
| @@ -174,7 +174,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 174 | return ResultInvalidCurrentMemory; | 174 | return ResultInvalidCurrentMemory; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 177 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 178 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); | 178 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); |
| 179 | if (process.IsNull()) { | 179 | if (process.IsNull()) { |
| 180 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | 180 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", |
| @@ -242,7 +242,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 242 | return ResultInvalidCurrentMemory; | 242 | return ResultInvalidCurrentMemory; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 245 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 246 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); | 246 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); |
| 247 | if (process.IsNull()) { | 247 | if (process.IsNull()) { |
| 248 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | 248 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", |
diff --git a/src/core/hle/kernel/svc/svc_query_memory.cpp b/src/core/hle/kernel/svc/svc_query_memory.cpp index db140a341..ee75ad370 100644 --- a/src/core/hle/kernel/svc/svc_query_memory.cpp +++ b/src/core/hle/kernel/svc/svc_query_memory.cpp | |||
| @@ -22,7 +22,7 @@ Result QueryMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out | |||
| 22 | Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info, | 22 | Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info, |
| 23 | Handle process_handle, uint64_t address) { | 23 | Handle process_handle, uint64_t address) { |
| 24 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address); | 24 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address); |
| 25 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 25 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 26 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); | 26 | KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); |
| 27 | if (process.IsNull()) { | 27 | if (process.IsNull()) { |
| 28 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", | 28 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
diff --git a/src/core/hle/kernel/svc/svc_resource_limit.cpp b/src/core/hle/kernel/svc/svc_resource_limit.cpp index ebc886028..88166299e 100644 --- a/src/core/hle/kernel/svc/svc_resource_limit.cpp +++ b/src/core/hle/kernel/svc/svc_resource_limit.cpp | |||
| @@ -27,7 +27,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) { | |||
| 27 | KResourceLimit::Register(kernel, resource_limit); | 27 | KResourceLimit::Register(kernel, resource_limit); |
| 28 | 28 | ||
| 29 | // Add the limit to the handle table. | 29 | // Add the limit to the handle table. |
| 30 | R_TRY(kernel.CurrentProcess()->GetHandleTable().Add(out_handle, resource_limit)); | 30 | R_TRY(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit)); |
| 31 | 31 | ||
| 32 | return ResultSuccess; | 32 | return ResultSuccess; |
| 33 | } | 33 | } |
| @@ -41,9 +41,9 @@ Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value, | |||
| 41 | R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); | 41 | R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); |
| 42 | 42 | ||
| 43 | // Get the resource limit. | 43 | // Get the resource limit. |
| 44 | auto& kernel = system.Kernel(); | 44 | KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel()) |
| 45 | KScopedAutoObject resource_limit = | 45 | .GetHandleTable() |
| 46 | kernel.CurrentProcess()->GetHandleTable().GetObject<KResourceLimit>(resource_limit_handle); | 46 | .GetObject<KResourceLimit>(resource_limit_handle); |
| 47 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); | 47 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); |
| 48 | 48 | ||
| 49 | // Get the limit value. | 49 | // Get the limit value. |
| @@ -61,9 +61,9 @@ Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value | |||
| 61 | R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); | 61 | R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); |
| 62 | 62 | ||
| 63 | // Get the resource limit. | 63 | // Get the resource limit. |
| 64 | auto& kernel = system.Kernel(); | 64 | KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel()) |
| 65 | KScopedAutoObject resource_limit = | 65 | .GetHandleTable() |
| 66 | kernel.CurrentProcess()->GetHandleTable().GetObject<KResourceLimit>(resource_limit_handle); | 66 | .GetObject<KResourceLimit>(resource_limit_handle); |
| 67 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); | 67 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); |
| 68 | 68 | ||
| 69 | // Get the current value. | 69 | // Get the current value. |
| @@ -81,9 +81,9 @@ Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_ha | |||
| 81 | R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); | 81 | R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); |
| 82 | 82 | ||
| 83 | // Get the resource limit. | 83 | // Get the resource limit. |
| 84 | auto& kernel = system.Kernel(); | 84 | KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel()) |
| 85 | KScopedAutoObject resource_limit = | 85 | .GetHandleTable() |
| 86 | kernel.CurrentProcess()->GetHandleTable().GetObject<KResourceLimit>(resource_limit_handle); | 86 | .GetObject<KResourceLimit>(resource_limit_handle); |
| 87 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); | 87 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); |
| 88 | 88 | ||
| 89 | // Set the limit value. | 89 | // Set the limit value. |
diff --git a/src/core/hle/kernel/svc/svc_session.cpp b/src/core/hle/kernel/svc/svc_session.cpp index 0deb61b62..00fd1605e 100644 --- a/src/core/hle/kernel/svc/svc_session.cpp +++ b/src/core/hle/kernel/svc/svc_session.cpp | |||
| @@ -13,7 +13,7 @@ namespace { | |||
| 13 | 13 | ||
| 14 | template <typename T> | 14 | template <typename T> |
| 15 | Result CreateSession(Core::System& system, Handle* out_server, Handle* out_client, u64 name) { | 15 | Result CreateSession(Core::System& system, Handle* out_server, Handle* out_client, u64 name) { |
| 16 | auto& process = *system.CurrentProcess(); | 16 | auto& process = GetCurrentProcess(system.Kernel()); |
| 17 | auto& handle_table = process.GetHandleTable(); | 17 | auto& handle_table = process.GetHandleTable(); |
| 18 | 18 | ||
| 19 | // Declare the session we're going to allocate. | 19 | // Declare the session we're going to allocate. |
diff --git a/src/core/hle/kernel/svc/svc_shared_memory.cpp b/src/core/hle/kernel/svc/svc_shared_memory.cpp index 40d6260e3..18e0dc904 100644 --- a/src/core/hle/kernel/svc/svc_shared_memory.cpp +++ b/src/core/hle/kernel/svc/svc_shared_memory.cpp | |||
| @@ -42,7 +42,7 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, | |||
| 42 | R_UNLESS(IsValidSharedMemoryPermission(map_perm), ResultInvalidNewMemoryPermission); | 42 | R_UNLESS(IsValidSharedMemoryPermission(map_perm), ResultInvalidNewMemoryPermission); |
| 43 | 43 | ||
| 44 | // Get the current process. | 44 | // Get the current process. |
| 45 | auto& process = *system.Kernel().CurrentProcess(); | 45 | auto& process = GetCurrentProcess(system.Kernel()); |
| 46 | auto& page_table = process.PageTable(); | 46 | auto& page_table = process.PageTable(); |
| 47 | 47 | ||
| 48 | // Get the shared memory. | 48 | // Get the shared memory. |
| @@ -75,7 +75,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr addres | |||
| 75 | R_UNLESS((address < address + size), ResultInvalidCurrentMemory); | 75 | R_UNLESS((address < address + size), ResultInvalidCurrentMemory); |
| 76 | 76 | ||
| 77 | // Get the current process. | 77 | // Get the current process. |
| 78 | auto& process = *system.Kernel().CurrentProcess(); | 78 | auto& process = GetCurrentProcess(system.Kernel()); |
| 79 | auto& page_table = process.PageTable(); | 79 | auto& page_table = process.PageTable(); |
| 80 | 80 | ||
| 81 | // Get the shared memory. | 81 | // Get the shared memory. |
diff --git a/src/core/hle/kernel/svc/svc_synchronization.cpp b/src/core/hle/kernel/svc/svc_synchronization.cpp index e516a3800..1a8f7e191 100644 --- a/src/core/hle/kernel/svc/svc_synchronization.cpp +++ b/src/core/hle/kernel/svc/svc_synchronization.cpp | |||
| @@ -14,7 +14,7 @@ Result CloseHandle(Core::System& system, Handle handle) { | |||
| 14 | LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); | 14 | LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); |
| 15 | 15 | ||
| 16 | // Remove the handle. | 16 | // Remove the handle. |
| 17 | R_UNLESS(system.Kernel().CurrentProcess()->GetHandleTable().Remove(handle), | 17 | R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle), |
| 18 | ResultInvalidHandle); | 18 | ResultInvalidHandle); |
| 19 | 19 | ||
| 20 | return ResultSuccess; | 20 | return ResultSuccess; |
| @@ -25,7 +25,7 @@ Result ResetSignal(Core::System& system, Handle handle) { | |||
| 25 | LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle); | 25 | LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle); |
| 26 | 26 | ||
| 27 | // Get the current handle table. | 27 | // Get the current handle table. |
| 28 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 28 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 29 | 29 | ||
| 30 | // Try to reset as readable event. | 30 | // Try to reset as readable event. |
| 31 | { | 31 | { |
| @@ -59,7 +59,7 @@ Result WaitSynchronization(Core::System& system, s32* index, VAddr handles_addre | |||
| 59 | 59 | ||
| 60 | auto& kernel = system.Kernel(); | 60 | auto& kernel = system.Kernel(); |
| 61 | std::vector<KSynchronizationObject*> objs(num_handles); | 61 | std::vector<KSynchronizationObject*> objs(num_handles); |
| 62 | const auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); | 62 | const auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); |
| 63 | Handle* handles = system.Memory().GetPointer<Handle>(handles_address); | 63 | Handle* handles = system.Memory().GetPointer<Handle>(handles_address); |
| 64 | 64 | ||
| 65 | // Copy user handles. | 65 | // Copy user handles. |
| @@ -91,7 +91,7 @@ Result CancelSynchronization(Core::System& system, Handle handle) { | |||
| 91 | 91 | ||
| 92 | // Get the thread from its handle. | 92 | // Get the thread from its handle. |
| 93 | KScopedAutoObject thread = | 93 | KScopedAutoObject thread = |
| 94 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(handle); | 94 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle); |
| 95 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 95 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 96 | 96 | ||
| 97 | // Cancel the thread's wait. | 97 | // Cancel the thread's wait. |
| @@ -106,7 +106,7 @@ void SynchronizePreemptionState(Core::System& system) { | |||
| 106 | KScopedSchedulerLock sl{kernel}; | 106 | KScopedSchedulerLock sl{kernel}; |
| 107 | 107 | ||
| 108 | // If the current thread is pinned, unpin it. | 108 | // If the current thread is pinned, unpin it. |
| 109 | KProcess* cur_process = system.Kernel().CurrentProcess(); | 109 | KProcess* cur_process = GetCurrentProcessPointer(kernel); |
| 110 | const auto core_id = GetCurrentCoreId(kernel); | 110 | const auto core_id = GetCurrentCoreId(kernel); |
| 111 | 111 | ||
| 112 | if (cur_process->GetPinnedThread(core_id) == GetCurrentThreadPointer(kernel)) { | 112 | if (cur_process->GetPinnedThread(core_id) == GetCurrentThreadPointer(kernel)) { |
diff --git a/src/core/hle/kernel/svc/svc_thread.cpp b/src/core/hle/kernel/svc/svc_thread.cpp index 3e325c998..b39807841 100644 --- a/src/core/hle/kernel/svc/svc_thread.cpp +++ b/src/core/hle/kernel/svc/svc_thread.cpp | |||
| @@ -28,7 +28,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, | |||
| 28 | 28 | ||
| 29 | // Adjust core id, if it's the default magic. | 29 | // Adjust core id, if it's the default magic. |
| 30 | auto& kernel = system.Kernel(); | 30 | auto& kernel = system.Kernel(); |
| 31 | auto& process = *kernel.CurrentProcess(); | 31 | auto& process = GetCurrentProcess(kernel); |
| 32 | if (core_id == IdealCoreUseProcessValue) { | 32 | if (core_id == IdealCoreUseProcessValue) { |
| 33 | core_id = process.GetIdealCoreId(); | 33 | core_id = process.GetIdealCoreId(); |
| 34 | } | 34 | } |
| @@ -53,9 +53,9 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | // Reserve a new thread from the process resource limit (waiting up to 100ms). | 55 | // Reserve a new thread from the process resource limit (waiting up to 100ms). |
| 56 | KScopedResourceReservation thread_reservation( | 56 | KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1, |
| 57 | kernel.CurrentProcess(), LimitableResource::ThreadCountMax, 1, | 57 | system.CoreTiming().GetGlobalTimeNs().count() + |
| 58 | system.CoreTiming().GetGlobalTimeNs().count() + 100000000); | 58 | 100000000); |
| 59 | if (!thread_reservation.Succeeded()) { | 59 | if (!thread_reservation.Succeeded()) { |
| 60 | LOG_ERROR(Kernel_SVC, "Could not reserve a new thread"); | 60 | LOG_ERROR(Kernel_SVC, "Could not reserve a new thread"); |
| 61 | return ResultLimitReached; | 61 | return ResultLimitReached; |
| @@ -97,7 +97,7 @@ Result StartThread(Core::System& system, Handle thread_handle) { | |||
| 97 | 97 | ||
| 98 | // Get the thread from its handle. | 98 | // Get the thread from its handle. |
| 99 | KScopedAutoObject thread = | 99 | KScopedAutoObject thread = |
| 100 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); | 100 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle); |
| 101 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 101 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 102 | 102 | ||
| 103 | // Try to start the thread. | 103 | // Try to start the thread. |
| @@ -156,11 +156,11 @@ Result GetThreadContext3(Core::System& system, VAddr out_context, Handle thread_ | |||
| 156 | 156 | ||
| 157 | // Get the thread from its handle. | 157 | // Get the thread from its handle. |
| 158 | KScopedAutoObject thread = | 158 | KScopedAutoObject thread = |
| 159 | kernel.CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); | 159 | GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(thread_handle); |
| 160 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 160 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 161 | 161 | ||
| 162 | // Require the handle be to a non-current thread in the current process. | 162 | // Require the handle be to a non-current thread in the current process. |
| 163 | const auto* current_process = kernel.CurrentProcess(); | 163 | const auto* current_process = GetCurrentProcessPointer(kernel); |
| 164 | R_UNLESS(current_process == thread->GetOwnerProcess(), ResultInvalidId); | 164 | R_UNLESS(current_process == thread->GetOwnerProcess(), ResultInvalidId); |
| 165 | 165 | ||
| 166 | // Verify that the thread isn't terminated. | 166 | // Verify that the thread isn't terminated. |
| @@ -211,7 +211,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle) | |||
| 211 | 211 | ||
| 212 | // Get the thread from its handle. | 212 | // Get the thread from its handle. |
| 213 | KScopedAutoObject thread = | 213 | KScopedAutoObject thread = |
| 214 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(handle); | 214 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle); |
| 215 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 215 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 216 | 216 | ||
| 217 | // Get the thread's priority. | 217 | // Get the thread's priority. |
| @@ -222,7 +222,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle) | |||
| 222 | /// Sets the priority for the specified thread | 222 | /// Sets the priority for the specified thread |
| 223 | Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priority) { | 223 | Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priority) { |
| 224 | // Get the current process. | 224 | // Get the current process. |
| 225 | KProcess& process = *system.Kernel().CurrentProcess(); | 225 | KProcess& process = GetCurrentProcess(system.Kernel()); |
| 226 | 226 | ||
| 227 | // Validate the priority. | 227 | // Validate the priority. |
| 228 | R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority, | 228 | R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority, |
| @@ -253,7 +253,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa | |||
| 253 | return ResultOutOfRange; | 253 | return ResultOutOfRange; |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | auto* const current_process = system.Kernel().CurrentProcess(); | 256 | auto* const current_process = GetCurrentProcessPointer(system.Kernel()); |
| 257 | const auto total_copy_size = out_thread_ids_size * sizeof(u64); | 257 | const auto total_copy_size = out_thread_ids_size * sizeof(u64); |
| 258 | 258 | ||
| 259 | if (out_thread_ids_size > 0 && | 259 | if (out_thread_ids_size > 0 && |
| @@ -284,7 +284,7 @@ Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affini | |||
| 284 | 284 | ||
| 285 | // Get the thread from its handle. | 285 | // Get the thread from its handle. |
| 286 | KScopedAutoObject thread = | 286 | KScopedAutoObject thread = |
| 287 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); | 287 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle); |
| 288 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 288 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 289 | 289 | ||
| 290 | // Get the core mask. | 290 | // Get the core mask. |
| @@ -297,11 +297,11 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id | |||
| 297 | u64 affinity_mask) { | 297 | u64 affinity_mask) { |
| 298 | // Determine the core id/affinity mask. | 298 | // Determine the core id/affinity mask. |
| 299 | if (core_id == IdealCoreUseProcessValue) { | 299 | if (core_id == IdealCoreUseProcessValue) { |
| 300 | core_id = system.Kernel().CurrentProcess()->GetIdealCoreId(); | 300 | core_id = GetCurrentProcess(system.Kernel()).GetIdealCoreId(); |
| 301 | affinity_mask = (1ULL << core_id); | 301 | affinity_mask = (1ULL << core_id); |
| 302 | } else { | 302 | } else { |
| 303 | // Validate the affinity mask. | 303 | // Validate the affinity mask. |
| 304 | const u64 process_core_mask = system.Kernel().CurrentProcess()->GetCoreMask(); | 304 | const u64 process_core_mask = GetCurrentProcess(system.Kernel()).GetCoreMask(); |
| 305 | R_UNLESS((affinity_mask | process_core_mask) == process_core_mask, ResultInvalidCoreId); | 305 | R_UNLESS((affinity_mask | process_core_mask) == process_core_mask, ResultInvalidCoreId); |
| 306 | R_UNLESS(affinity_mask != 0, ResultInvalidCombination); | 306 | R_UNLESS(affinity_mask != 0, ResultInvalidCombination); |
| 307 | 307 | ||
| @@ -316,7 +316,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id | |||
| 316 | 316 | ||
| 317 | // Get the thread from its handle. | 317 | // Get the thread from its handle. |
| 318 | KScopedAutoObject thread = | 318 | KScopedAutoObject thread = |
| 319 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); | 319 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle); |
| 320 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 320 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 321 | 321 | ||
| 322 | // Set the core mask. | 322 | // Set the core mask. |
| @@ -329,7 +329,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id | |||
| 329 | Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) { | 329 | Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) { |
| 330 | // Get the thread from its handle. | 330 | // Get the thread from its handle. |
| 331 | KScopedAutoObject thread = | 331 | KScopedAutoObject thread = |
| 332 | system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); | 332 | GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle); |
| 333 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 333 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 334 | 334 | ||
| 335 | // Get the thread's id. | 335 | // Get the thread's id. |
diff --git a/src/core/hle/kernel/svc/svc_transfer_memory.cpp b/src/core/hle/kernel/svc/svc_transfer_memory.cpp index a4c040e49..7ffc24adf 100644 --- a/src/core/hle/kernel/svc/svc_transfer_memory.cpp +++ b/src/core/hle/kernel/svc/svc_transfer_memory.cpp | |||
| @@ -39,11 +39,11 @@ Result CreateTransferMemory(Core::System& system, Handle* out, VAddr address, u6 | |||
| 39 | R_UNLESS(IsValidTransferMemoryPermission(map_perm), ResultInvalidNewMemoryPermission); | 39 | R_UNLESS(IsValidTransferMemoryPermission(map_perm), ResultInvalidNewMemoryPermission); |
| 40 | 40 | ||
| 41 | // Get the current process and handle table. | 41 | // Get the current process and handle table. |
| 42 | auto& process = *kernel.CurrentProcess(); | 42 | auto& process = GetCurrentProcess(kernel); |
| 43 | auto& handle_table = process.GetHandleTable(); | 43 | auto& handle_table = process.GetHandleTable(); |
| 44 | 44 | ||
| 45 | // Reserve a new transfer memory from the process resource limit. | 45 | // Reserve a new transfer memory from the process resource limit. |
| 46 | KScopedResourceReservation trmem_reservation(kernel.CurrentProcess(), | 46 | KScopedResourceReservation trmem_reservation(&process, |
| 47 | LimitableResource::TransferMemoryCountMax); | 47 | LimitableResource::TransferMemoryCountMax); |
| 48 | R_UNLESS(trmem_reservation.Succeeded(), ResultLimitReached); | 48 | R_UNLESS(trmem_reservation.Succeeded(), ResultLimitReached); |
| 49 | 49 | ||
diff --git a/src/core/hle/kernel/svc_generator.py b/src/core/hle/kernel/svc_generator.py index b0a5707ec..34d2ac659 100644 --- a/src/core/hle/kernel/svc_generator.py +++ b/src/core/hle/kernel/svc_generator.py | |||
| @@ -592,7 +592,7 @@ void Call(Core::System& system, u32 imm) { | |||
| 592 | auto& kernel = system.Kernel(); | 592 | auto& kernel = system.Kernel(); |
| 593 | kernel.EnterSVCProfile(); | 593 | kernel.EnterSVCProfile(); |
| 594 | 594 | ||
| 595 | if (system.CurrentProcess()->Is64BitProcess()) { | 595 | if (GetCurrentProcess(system.Kernel()).Is64BitProcess()) { |
| 596 | Call64(system, imm); | 596 | Call64(system, imm); |
| 597 | } else { | 597 | } else { |
| 598 | Call32(system, imm); | 598 | Call32(system, imm); |