diff options
| author | 2023-03-07 00:13:05 -0500 | |
|---|---|---|
| committer | 2023-03-12 22:09:08 -0400 | |
| commit | 91fd4e30f2a12868201b08e73de299db1c3d116a (patch) | |
| tree | ac85044f0554995ef6af3a3d9a4508286c2b95b3 | |
| parent | kernel: convert miscellaneous (diff) | |
| download | yuzu-91fd4e30f2a12868201b08e73de299db1c3d116a.tar.gz yuzu-91fd4e30f2a12868201b08e73de299db1c3d116a.tar.xz yuzu-91fd4e30f2a12868201b08e73de299db1c3d116a.zip | |
kernel/svc: convert to new style
21 files changed, 192 insertions, 304 deletions
diff --git a/src/core/hle/kernel/k_readable_event.cpp b/src/core/hle/kernel/k_readable_event.cpp index 5c942d47c..eeac678e4 100644 --- a/src/core/hle/kernel/k_readable_event.cpp +++ b/src/core/hle/kernel/k_readable_event.cpp | |||
| @@ -48,24 +48,22 @@ Result KReadableEvent::Signal() { | |||
| 48 | this->NotifyAvailable(); | 48 | this->NotifyAvailable(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | return ResultSuccess; | 51 | R_SUCCEED(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | Result KReadableEvent::Clear() { | 54 | Result KReadableEvent::Clear() { |
| 55 | this->Reset(); | 55 | this->Reset(); |
| 56 | 56 | ||
| 57 | return ResultSuccess; | 57 | R_SUCCEED(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | Result KReadableEvent::Reset() { | 60 | Result KReadableEvent::Reset() { |
| 61 | KScopedSchedulerLock lk{kernel}; | 61 | KScopedSchedulerLock lk{kernel}; |
| 62 | 62 | ||
| 63 | if (!m_is_signaled) { | 63 | R_UNLESS(m_is_signaled, ResultInvalidState); |
| 64 | return ResultInvalidState; | ||
| 65 | } | ||
| 66 | 64 | ||
| 67 | m_is_signaled = false; | 65 | m_is_signaled = false; |
| 68 | return ResultSuccess; | 66 | R_SUCCEED(); |
| 69 | } | 67 | } |
| 70 | 68 | ||
| 71 | } // namespace Kernel | 69 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/k_resource_limit.cpp b/src/core/hle/kernel/k_resource_limit.cpp index 626517619..2847da291 100644 --- a/src/core/hle/kernel/k_resource_limit.cpp +++ b/src/core/hle/kernel/k_resource_limit.cpp | |||
| @@ -82,7 +82,7 @@ Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) { | |||
| 82 | limit_values[index] = value; | 82 | limit_values[index] = value; |
| 83 | peak_values[index] = current_values[index]; | 83 | peak_values[index] = current_values[index]; |
| 84 | 84 | ||
| 85 | return ResultSuccess; | 85 | R_SUCCEED(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | bool KResourceLimit::Reserve(LimitableResource which, s64 value) { | 88 | bool KResourceLimit::Reserve(LimitableResource which, s64 value) { |
diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp index 6831243b5..c68ec09ce 100644 --- a/src/core/hle/kernel/k_server_session.cpp +++ b/src/core/hle/kernel/k_server_session.cpp | |||
| @@ -272,7 +272,7 @@ Result KServerSession::SendReply(bool is_hle) { | |||
| 272 | } | 272 | } |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | return result; | 275 | R_RETURN(result); |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context, | 278 | Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context, |
| @@ -339,7 +339,7 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext | |||
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | // We succeeded. | 341 | // We succeeded. |
| 342 | return ResultSuccess; | 342 | R_SUCCEED(); |
| 343 | } | 343 | } |
| 344 | 344 | ||
| 345 | void KServerSession::CleanupRequests() { | 345 | void KServerSession::CleanupRequests() { |
diff --git a/src/core/hle/kernel/svc/svc_address_arbiter.cpp b/src/core/hle/kernel/svc/svc_address_arbiter.cpp index 998bd3f22..22071731b 100644 --- a/src/core/hle/kernel/svc/svc_address_arbiter.cpp +++ b/src/core/hle/kernel/svc/svc_address_arbiter.cpp | |||
| @@ -43,18 +43,9 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t | |||
| 43 | address, arb_type, value, timeout_ns); | 43 | address, arb_type, value, timeout_ns); |
| 44 | 44 | ||
| 45 | // Validate input. | 45 | // Validate input. |
| 46 | if (IsKernelAddress(address)) { | 46 | R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory); |
| 47 | LOG_ERROR(Kernel_SVC, "Attempting to wait on kernel address (address={:08X})", address); | 47 | R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress); |
| 48 | return ResultInvalidCurrentMemory; | 48 | R_UNLESS(IsValidArbitrationType(arb_type), ResultInvalidEnumValue); |
| 49 | } | ||
| 50 | if (!Common::IsAligned(address, sizeof(s32))) { | ||
| 51 | LOG_ERROR(Kernel_SVC, "Wait address must be 4 byte aligned (address={:08X})", address); | ||
| 52 | return ResultInvalidAddress; | ||
| 53 | } | ||
| 54 | if (!IsValidArbitrationType(arb_type)) { | ||
| 55 | LOG_ERROR(Kernel_SVC, "Invalid arbitration type specified (type={})", arb_type); | ||
| 56 | return ResultInvalidEnumValue; | ||
| 57 | } | ||
| 58 | 49 | ||
| 59 | // Convert timeout from nanoseconds to ticks. | 50 | // Convert timeout from nanoseconds to ticks. |
| 60 | s64 timeout{}; | 51 | s64 timeout{}; |
| @@ -72,7 +63,8 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t | |||
| 72 | timeout = timeout_ns; | 63 | timeout = timeout_ns; |
| 73 | } | 64 | } |
| 74 | 65 | ||
| 75 | return GetCurrentProcess(system.Kernel()).WaitAddressArbiter(address, arb_type, value, timeout); | 66 | R_RETURN( |
| 67 | GetCurrentProcess(system.Kernel()).WaitAddressArbiter(address, arb_type, value, timeout)); | ||
| 76 | } | 68 | } |
| 77 | 69 | ||
| 78 | // Signals to an address (via Address Arbiter) | 70 | // Signals to an address (via Address Arbiter) |
| @@ -82,41 +74,32 @@ Result SignalToAddress(Core::System& system, VAddr address, SignalType signal_ty | |||
| 82 | address, signal_type, value, count); | 74 | address, signal_type, value, count); |
| 83 | 75 | ||
| 84 | // Validate input. | 76 | // Validate input. |
| 85 | if (IsKernelAddress(address)) { | 77 | R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory); |
| 86 | LOG_ERROR(Kernel_SVC, "Attempting to signal to a kernel address (address={:08X})", address); | 78 | R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress); |
| 87 | return ResultInvalidCurrentMemory; | 79 | R_UNLESS(IsValidSignalType(signal_type), ResultInvalidEnumValue); |
| 88 | } | ||
| 89 | if (!Common::IsAligned(address, sizeof(s32))) { | ||
| 90 | LOG_ERROR(Kernel_SVC, "Signaled address must be 4 byte aligned (address={:08X})", address); | ||
| 91 | return ResultInvalidAddress; | ||
| 92 | } | ||
| 93 | if (!IsValidSignalType(signal_type)) { | ||
| 94 | LOG_ERROR(Kernel_SVC, "Invalid signal type specified (type={})", signal_type); | ||
| 95 | return ResultInvalidEnumValue; | ||
| 96 | } | ||
| 97 | 80 | ||
| 98 | return GetCurrentProcess(system.Kernel()) | 81 | R_RETURN(GetCurrentProcess(system.Kernel()) |
| 99 | .SignalAddressArbiter(address, signal_type, value, count); | 82 | .SignalAddressArbiter(address, signal_type, value, count)); |
| 100 | } | 83 | } |
| 101 | 84 | ||
| 102 | Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value, | 85 | Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value, |
| 103 | s64 timeout_ns) { | 86 | s64 timeout_ns) { |
| 104 | return WaitForAddress(system, address, arb_type, value, timeout_ns); | 87 | R_RETURN(WaitForAddress(system, address, arb_type, value, timeout_ns)); |
| 105 | } | 88 | } |
| 106 | 89 | ||
| 107 | Result SignalToAddress64(Core::System& system, VAddr address, SignalType signal_type, s32 value, | 90 | Result SignalToAddress64(Core::System& system, VAddr address, SignalType signal_type, s32 value, |
| 108 | s32 count) { | 91 | s32 count) { |
| 109 | return SignalToAddress(system, address, signal_type, value, count); | 92 | R_RETURN(SignalToAddress(system, address, signal_type, value, count)); |
| 110 | } | 93 | } |
| 111 | 94 | ||
| 112 | Result WaitForAddress64From32(Core::System& system, u32 address, ArbitrationType arb_type, | 95 | Result WaitForAddress64From32(Core::System& system, u32 address, ArbitrationType arb_type, |
| 113 | s32 value, s64 timeout_ns) { | 96 | s32 value, s64 timeout_ns) { |
| 114 | return WaitForAddress(system, address, arb_type, value, timeout_ns); | 97 | R_RETURN(WaitForAddress(system, address, arb_type, value, timeout_ns)); |
| 115 | } | 98 | } |
| 116 | 99 | ||
| 117 | Result SignalToAddress64From32(Core::System& system, u32 address, SignalType signal_type, s32 value, | 100 | Result SignalToAddress64From32(Core::System& system, u32 address, SignalType signal_type, s32 value, |
| 118 | s32 count) { | 101 | s32 count) { |
| 119 | return SignalToAddress(system, address, signal_type, value, count); | 102 | R_RETURN(SignalToAddress(system, address, signal_type, value, count)); |
| 120 | } | 103 | } |
| 121 | 104 | ||
| 122 | } // namespace Kernel::Svc | 105 | } // namespace Kernel::Svc |
diff --git a/src/core/hle/kernel/svc/svc_code_memory.cpp b/src/core/hle/kernel/svc/svc_code_memory.cpp index 8bed747af..43feab986 100644 --- a/src/core/hle/kernel/svc/svc_code_memory.cpp +++ b/src/core/hle/kernel/svc/svc_code_memory.cpp | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/scope_exit.h" | ||
| 4 | #include "core/core.h" | 5 | #include "core/core.h" |
| 5 | #include "core/hle/kernel/k_code_memory.h" | 6 | #include "core/hle/kernel/k_code_memory.h" |
| 6 | #include "core/hle/kernel/k_process.h" | 7 | #include "core/hle/kernel/k_process.h" |
| @@ -44,6 +45,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, uint64 | |||
| 44 | 45 | ||
| 45 | KCodeMemory* code_mem = KCodeMemory::Create(kernel); | 46 | KCodeMemory* code_mem = KCodeMemory::Create(kernel); |
| 46 | R_UNLESS(code_mem != nullptr, ResultOutOfResource); | 47 | R_UNLESS(code_mem != nullptr, ResultOutOfResource); |
| 48 | SCOPE_EXIT({ code_mem->Close(); }); | ||
| 47 | 49 | ||
| 48 | // Verify that the region is in range. | 50 | // Verify that the region is in range. |
| 49 | R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size), | 51 | R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size), |
| @@ -58,9 +60,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, uint64 | |||
| 58 | // Add the code memory to the handle table. | 60 | // Add the code memory to the handle table. |
| 59 | R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem)); | 61 | R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem)); |
| 60 | 62 | ||
| 61 | code_mem->Close(); | 63 | R_SUCCEED(); |
| 62 | |||
| 63 | return ResultSuccess; | ||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, | 66 | Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, |
| @@ -140,10 +140,10 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, | |||
| 140 | R_TRY(code_mem->UnmapFromOwner(address, size)); | 140 | R_TRY(code_mem->UnmapFromOwner(address, size)); |
| 141 | } break; | 141 | } break; |
| 142 | default: | 142 | default: |
| 143 | return ResultInvalidEnumValue; | 143 | R_THROW(ResultInvalidEnumValue); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | return ResultSuccess; | 146 | R_SUCCEED(); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | Result CreateCodeMemory64(Core::System& system, Handle* out_handle, uint64_t address, | 149 | Result CreateCodeMemory64(Core::System& system, Handle* out_handle, uint64_t address, |
diff --git a/src/core/hle/kernel/svc/svc_condition_variable.cpp b/src/core/hle/kernel/svc/svc_condition_variable.cpp index 8ad1a0b8f..648ed23d0 100644 --- a/src/core/hle/kernel/svc/svc_condition_variable.cpp +++ b/src/core/hle/kernel/svc/svc_condition_variable.cpp | |||
| @@ -17,14 +17,8 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke | |||
| 17 | cv_key, tag, timeout_ns); | 17 | cv_key, tag, timeout_ns); |
| 18 | 18 | ||
| 19 | // Validate input. | 19 | // Validate input. |
| 20 | if (IsKernelAddress(address)) { | 20 | R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory); |
| 21 | LOG_ERROR(Kernel_SVC, "Attempted to wait on kernel address (address={:08X})", address); | 21 | R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress); |
| 22 | return ResultInvalidCurrentMemory; | ||
| 23 | } | ||
| 24 | if (!Common::IsAligned(address, sizeof(s32))) { | ||
| 25 | LOG_ERROR(Kernel_SVC, "Address must be 4 byte aligned (address={:08X})", address); | ||
| 26 | return ResultInvalidAddress; | ||
| 27 | } | ||
| 28 | 22 | ||
| 29 | // Convert timeout from nanoseconds to ticks. | 23 | // Convert timeout from nanoseconds to ticks. |
| 30 | s64 timeout{}; | 24 | s64 timeout{}; |
| @@ -43,8 +37,9 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke | |||
| 43 | } | 37 | } |
| 44 | 38 | ||
| 45 | // Wait on the condition variable. | 39 | // Wait on the condition variable. |
| 46 | return GetCurrentProcess(system.Kernel()) | 40 | R_RETURN( |
| 47 | .WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); | 41 | GetCurrentProcess(system.Kernel()) |
| 42 | .WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout)); | ||
| 48 | } | 43 | } |
| 49 | 44 | ||
| 50 | /// Signal process wide key | 45 | /// Signal process wide key |
diff --git a/src/core/hle/kernel/svc/svc_event.cpp b/src/core/hle/kernel/svc/svc_event.cpp index 8692b00f2..901202e6a 100644 --- a/src/core/hle/kernel/svc/svc_event.cpp +++ b/src/core/hle/kernel/svc/svc_event.cpp | |||
| @@ -21,7 +21,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) { | |||
| 21 | KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); | 21 | KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); |
| 22 | R_UNLESS(event.IsNotNull(), ResultInvalidHandle); | 22 | R_UNLESS(event.IsNotNull(), ResultInvalidHandle); |
| 23 | 23 | ||
| 24 | return event->Signal(); | 24 | R_RETURN(event->Signal()); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | Result ClearEvent(Core::System& system, Handle event_handle) { | 27 | Result ClearEvent(Core::System& system, Handle event_handle) { |
| @@ -34,7 +34,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) { | |||
| 34 | { | 34 | { |
| 35 | KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); | 35 | KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); |
| 36 | if (event.IsNotNull()) { | 36 | if (event.IsNotNull()) { |
| 37 | return event->Clear(); | 37 | R_RETURN(event->Clear()); |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| @@ -42,13 +42,11 @@ Result ClearEvent(Core::System& system, Handle event_handle) { | |||
| 42 | { | 42 | { |
| 43 | KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(event_handle); | 43 | KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(event_handle); |
| 44 | if (readable_event.IsNotNull()) { | 44 | if (readable_event.IsNotNull()) { |
| 45 | return readable_event->Clear(); | 45 | R_RETURN(readable_event->Clear()); |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | LOG_ERROR(Kernel_SVC, "Event handle does not exist, event_handle=0x{:08X}", event_handle); | 49 | R_THROW(ResultInvalidHandle); |
| 50 | |||
| 51 | return ResultInvalidHandle; | ||
| 52 | } | 50 | } |
| 53 | 51 | ||
| 54 | Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { | 52 | Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { |
| @@ -86,14 +84,12 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { | |||
| 86 | R_TRY(handle_table.Add(out_write, event)); | 84 | R_TRY(handle_table.Add(out_write, event)); |
| 87 | 85 | ||
| 88 | // Ensure that we maintain a clean handle state on exit. | 86 | // Ensure that we maintain a clean handle state on exit. |
| 89 | auto handle_guard = SCOPE_GUARD({ handle_table.Remove(*out_write); }); | 87 | ON_RESULT_FAILURE { |
| 88 | handle_table.Remove(*out_write); | ||
| 89 | }; | ||
| 90 | 90 | ||
| 91 | // Add the readable event to the handle table. | 91 | // Add the readable event to the handle table. |
| 92 | R_TRY(handle_table.Add(out_read, std::addressof(event->GetReadableEvent()))); | 92 | R_RETURN(handle_table.Add(out_read, std::addressof(event->GetReadableEvent()))); |
| 93 | |||
| 94 | // We succeeded. | ||
| 95 | handle_guard.Cancel(); | ||
| 96 | return ResultSuccess; | ||
| 97 | } | 93 | } |
| 98 | 94 | ||
| 99 | Result SignalEvent64(Core::System& system, Handle event_handle) { | 95 | Result SignalEvent64(Core::System& system, Handle event_handle) { |
diff --git a/src/core/hle/kernel/svc/svc_info.cpp b/src/core/hle/kernel/svc/svc_info.cpp index cbed4dc8c..806acb539 100644 --- a/src/core/hle/kernel/svc/svc_info.cpp +++ b/src/core/hle/kernel/svc/svc_info.cpp | |||
| @@ -38,126 +38,110 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 38 | case InfoType::UsedNonSystemMemorySize: | 38 | case InfoType::UsedNonSystemMemorySize: |
| 39 | case InfoType::IsApplication: | 39 | case InfoType::IsApplication: |
| 40 | case InfoType::FreeThreadCount: { | 40 | case InfoType::FreeThreadCount: { |
| 41 | if (info_sub_id != 0) { | 41 | R_UNLESS(info_sub_id == 0, ResultInvalidEnumValue); |
| 42 | LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, | ||
| 43 | info_sub_id); | ||
| 44 | return ResultInvalidEnumValue; | ||
| 45 | } | ||
| 46 | 42 | ||
| 47 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); | 43 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| 48 | KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); | 44 | KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); |
| 49 | if (process.IsNull()) { | 45 | R_UNLESS(process.IsNotNull(), ResultInvalidHandle); |
| 50 | LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}", | ||
| 51 | info_id, info_sub_id, handle); | ||
| 52 | return ResultInvalidHandle; | ||
| 53 | } | ||
| 54 | 46 | ||
| 55 | switch (info_id_type) { | 47 | switch (info_id_type) { |
| 56 | case InfoType::CoreMask: | 48 | case InfoType::CoreMask: |
| 57 | *result = process->GetCoreMask(); | 49 | *result = process->GetCoreMask(); |
| 58 | return ResultSuccess; | 50 | R_SUCCEED(); |
| 59 | 51 | ||
| 60 | case InfoType::PriorityMask: | 52 | case InfoType::PriorityMask: |
| 61 | *result = process->GetPriorityMask(); | 53 | *result = process->GetPriorityMask(); |
| 62 | return ResultSuccess; | 54 | R_SUCCEED(); |
| 63 | 55 | ||
| 64 | case InfoType::AliasRegionAddress: | 56 | case InfoType::AliasRegionAddress: |
| 65 | *result = process->PageTable().GetAliasRegionStart(); | 57 | *result = process->PageTable().GetAliasRegionStart(); |
| 66 | return ResultSuccess; | 58 | R_SUCCEED(); |
| 67 | 59 | ||
| 68 | case InfoType::AliasRegionSize: | 60 | case InfoType::AliasRegionSize: |
| 69 | *result = process->PageTable().GetAliasRegionSize(); | 61 | *result = process->PageTable().GetAliasRegionSize(); |
| 70 | return ResultSuccess; | 62 | R_SUCCEED(); |
| 71 | 63 | ||
| 72 | case InfoType::HeapRegionAddress: | 64 | case InfoType::HeapRegionAddress: |
| 73 | *result = process->PageTable().GetHeapRegionStart(); | 65 | *result = process->PageTable().GetHeapRegionStart(); |
| 74 | return ResultSuccess; | 66 | R_SUCCEED(); |
| 75 | 67 | ||
| 76 | case InfoType::HeapRegionSize: | 68 | case InfoType::HeapRegionSize: |
| 77 | *result = process->PageTable().GetHeapRegionSize(); | 69 | *result = process->PageTable().GetHeapRegionSize(); |
| 78 | return ResultSuccess; | 70 | R_SUCCEED(); |
| 79 | 71 | ||
| 80 | case InfoType::AslrRegionAddress: | 72 | case InfoType::AslrRegionAddress: |
| 81 | *result = process->PageTable().GetAliasCodeRegionStart(); | 73 | *result = process->PageTable().GetAliasCodeRegionStart(); |
| 82 | return ResultSuccess; | 74 | R_SUCCEED(); |
| 83 | 75 | ||
| 84 | case InfoType::AslrRegionSize: | 76 | case InfoType::AslrRegionSize: |
| 85 | *result = process->PageTable().GetAliasCodeRegionSize(); | 77 | *result = process->PageTable().GetAliasCodeRegionSize(); |
| 86 | return ResultSuccess; | 78 | R_SUCCEED(); |
| 87 | 79 | ||
| 88 | case InfoType::StackRegionAddress: | 80 | case InfoType::StackRegionAddress: |
| 89 | *result = process->PageTable().GetStackRegionStart(); | 81 | *result = process->PageTable().GetStackRegionStart(); |
| 90 | return ResultSuccess; | 82 | R_SUCCEED(); |
| 91 | 83 | ||
| 92 | case InfoType::StackRegionSize: | 84 | case InfoType::StackRegionSize: |
| 93 | *result = process->PageTable().GetStackRegionSize(); | 85 | *result = process->PageTable().GetStackRegionSize(); |
| 94 | return ResultSuccess; | 86 | R_SUCCEED(); |
| 95 | 87 | ||
| 96 | case InfoType::TotalMemorySize: | 88 | case InfoType::TotalMemorySize: |
| 97 | *result = process->GetTotalPhysicalMemoryAvailable(); | 89 | *result = process->GetTotalPhysicalMemoryAvailable(); |
| 98 | return ResultSuccess; | 90 | R_SUCCEED(); |
| 99 | 91 | ||
| 100 | case InfoType::UsedMemorySize: | 92 | case InfoType::UsedMemorySize: |
| 101 | *result = process->GetTotalPhysicalMemoryUsed(); | 93 | *result = process->GetTotalPhysicalMemoryUsed(); |
| 102 | return ResultSuccess; | 94 | R_SUCCEED(); |
| 103 | 95 | ||
| 104 | case InfoType::SystemResourceSizeTotal: | 96 | case InfoType::SystemResourceSizeTotal: |
| 105 | *result = process->GetSystemResourceSize(); | 97 | *result = process->GetSystemResourceSize(); |
| 106 | return ResultSuccess; | 98 | R_SUCCEED(); |
| 107 | 99 | ||
| 108 | case InfoType::SystemResourceSizeUsed: | 100 | case InfoType::SystemResourceSizeUsed: |
| 109 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage"); | 101 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage"); |
| 110 | *result = process->GetSystemResourceUsage(); | 102 | *result = process->GetSystemResourceUsage(); |
| 111 | return ResultSuccess; | 103 | R_SUCCEED(); |
| 112 | 104 | ||
| 113 | case InfoType::ProgramId: | 105 | case InfoType::ProgramId: |
| 114 | *result = process->GetProgramID(); | 106 | *result = process->GetProgramID(); |
| 115 | return ResultSuccess; | 107 | R_SUCCEED(); |
| 116 | 108 | ||
| 117 | case InfoType::UserExceptionContextAddress: | 109 | case InfoType::UserExceptionContextAddress: |
| 118 | *result = process->GetProcessLocalRegionAddress(); | 110 | *result = process->GetProcessLocalRegionAddress(); |
| 119 | return ResultSuccess; | 111 | R_SUCCEED(); |
| 120 | 112 | ||
| 121 | case InfoType::TotalNonSystemMemorySize: | 113 | case InfoType::TotalNonSystemMemorySize: |
| 122 | *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource(); | 114 | *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource(); |
| 123 | return ResultSuccess; | 115 | R_SUCCEED(); |
| 124 | 116 | ||
| 125 | case InfoType::UsedNonSystemMemorySize: | 117 | case InfoType::UsedNonSystemMemorySize: |
| 126 | *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); | 118 | *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); |
| 127 | return ResultSuccess; | 119 | R_SUCCEED(); |
| 128 | 120 | ||
| 129 | case InfoType::IsApplication: | 121 | case InfoType::IsApplication: |
| 130 | LOG_WARNING(Kernel_SVC, "(STUBBED) Assuming process is application"); | 122 | LOG_WARNING(Kernel_SVC, "(STUBBED) Assuming process is application"); |
| 131 | *result = true; | 123 | *result = true; |
| 132 | return ResultSuccess; | 124 | R_SUCCEED(); |
| 133 | 125 | ||
| 134 | case InfoType::FreeThreadCount: | 126 | case InfoType::FreeThreadCount: |
| 135 | *result = process->GetFreeThreadCount(); | 127 | *result = process->GetFreeThreadCount(); |
| 136 | return ResultSuccess; | 128 | R_SUCCEED(); |
| 137 | 129 | ||
| 138 | default: | 130 | default: |
| 139 | break; | 131 | break; |
| 140 | } | 132 | } |
| 141 | 133 | ||
| 142 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); | 134 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); |
| 143 | return ResultInvalidEnumValue; | 135 | R_THROW(ResultInvalidEnumValue); |
| 144 | } | 136 | } |
| 145 | 137 | ||
| 146 | case InfoType::DebuggerAttached: | 138 | case InfoType::DebuggerAttached: |
| 147 | *result = 0; | 139 | *result = 0; |
| 148 | return ResultSuccess; | 140 | R_SUCCEED(); |
| 149 | 141 | ||
| 150 | case InfoType::ResourceLimit: { | 142 | case InfoType::ResourceLimit: { |
| 151 | if (handle != 0) { | 143 | R_UNLESS(handle == 0, ResultInvalidHandle); |
| 152 | LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); | 144 | R_UNLESS(info_sub_id == 0, ResultInvalidCombination); |
| 153 | return ResultInvalidHandle; | ||
| 154 | } | ||
| 155 | |||
| 156 | if (info_sub_id != 0) { | ||
| 157 | LOG_ERROR(Kernel, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, | ||
| 158 | info_sub_id); | ||
| 159 | return ResultInvalidCombination; | ||
| 160 | } | ||
| 161 | 145 | ||
| 162 | KProcess* const current_process = GetCurrentProcessPointer(system.Kernel()); | 146 | KProcess* const current_process = GetCurrentProcessPointer(system.Kernel()); |
| 163 | KHandleTable& handle_table = current_process->GetHandleTable(); | 147 | KHandleTable& handle_table = current_process->GetHandleTable(); |
| @@ -165,44 +149,35 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 165 | if (!resource_limit) { | 149 | if (!resource_limit) { |
| 166 | *result = Svc::InvalidHandle; | 150 | *result = Svc::InvalidHandle; |
| 167 | // Yes, the kernel considers this a successful operation. | 151 | // Yes, the kernel considers this a successful operation. |
| 168 | return ResultSuccess; | 152 | R_SUCCEED(); |
| 169 | } | 153 | } |
| 170 | 154 | ||
| 171 | Handle resource_handle{}; | 155 | Handle resource_handle{}; |
| 172 | R_TRY(handle_table.Add(&resource_handle, resource_limit)); | 156 | R_TRY(handle_table.Add(&resource_handle, resource_limit)); |
| 173 | 157 | ||
| 174 | *result = resource_handle; | 158 | *result = resource_handle; |
| 175 | return ResultSuccess; | 159 | R_SUCCEED(); |
| 176 | } | 160 | } |
| 177 | 161 | ||
| 178 | case InfoType::RandomEntropy: | 162 | case InfoType::RandomEntropy: |
| 179 | if (handle != 0) { | 163 | R_UNLESS(handle == 0, ResultInvalidHandle); |
| 180 | LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", | 164 | R_UNLESS(info_sub_id < KProcess::RANDOM_ENTROPY_SIZE, ResultInvalidCombination); |
| 181 | handle); | ||
| 182 | return ResultInvalidHandle; | ||
| 183 | } | ||
| 184 | |||
| 185 | if (info_sub_id >= KProcess::RANDOM_ENTROPY_SIZE) { | ||
| 186 | LOG_ERROR(Kernel_SVC, "Entropy size is out of range, expected {} but got {}", | ||
| 187 | KProcess::RANDOM_ENTROPY_SIZE, info_sub_id); | ||
| 188 | return ResultInvalidCombination; | ||
| 189 | } | ||
| 190 | 165 | ||
| 191 | *result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id); | 166 | *result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id); |
| 192 | return ResultSuccess; | 167 | R_SUCCEED(); |
| 193 | 168 | ||
| 194 | case InfoType::InitialProcessIdRange: | 169 | case InfoType::InitialProcessIdRange: |
| 195 | LOG_WARNING(Kernel_SVC, | 170 | LOG_WARNING(Kernel_SVC, |
| 196 | "(STUBBED) Attempted to query privileged process id bounds, returned 0"); | 171 | "(STUBBED) Attempted to query privileged process id bounds, returned 0"); |
| 197 | *result = 0; | 172 | *result = 0; |
| 198 | return ResultSuccess; | 173 | R_SUCCEED(); |
| 199 | 174 | ||
| 200 | case InfoType::ThreadTickCount: { | 175 | case InfoType::ThreadTickCount: { |
| 201 | constexpr u64 num_cpus = 4; | 176 | constexpr u64 num_cpus = 4; |
| 202 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { | 177 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { |
| 203 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, | 178 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, |
| 204 | info_sub_id); | 179 | info_sub_id); |
| 205 | return ResultInvalidCombination; | 180 | R_THROW(ResultInvalidCombination); |
| 206 | } | 181 | } |
| 207 | 182 | ||
| 208 | KScopedAutoObject thread = GetCurrentProcess(system.Kernel()) | 183 | KScopedAutoObject thread = GetCurrentProcess(system.Kernel()) |
| @@ -211,7 +186,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 211 | if (thread.IsNull()) { | 186 | if (thread.IsNull()) { |
| 212 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", | 187 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", |
| 213 | static_cast<Handle>(handle)); | 188 | static_cast<Handle>(handle)); |
| 214 | return ResultInvalidHandle; | 189 | R_THROW(ResultInvalidHandle); |
| 215 | } | 190 | } |
| 216 | 191 | ||
| 217 | const auto& core_timing = system.CoreTiming(); | 192 | const auto& core_timing = system.CoreTiming(); |
| @@ -230,7 +205,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 230 | } | 205 | } |
| 231 | 206 | ||
| 232 | *result = out_ticks; | 207 | *result = out_ticks; |
| 233 | return ResultSuccess; | 208 | R_SUCCEED(); |
| 234 | } | 209 | } |
| 235 | case InfoType::IdleTickCount: { | 210 | case InfoType::IdleTickCount: { |
| 236 | // Verify the input handle is invalid. | 211 | // Verify the input handle is invalid. |
| @@ -244,7 +219,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 244 | 219 | ||
| 245 | // Get the idle tick count. | 220 | // Get the idle tick count. |
| 246 | *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime(); | 221 | *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime(); |
| 247 | return ResultSuccess; | 222 | R_SUCCEED(); |
| 248 | } | 223 | } |
| 249 | case InfoType::MesosphereCurrentProcess: { | 224 | case InfoType::MesosphereCurrentProcess: { |
| 250 | // Verify the input handle is invalid. | 225 | // Verify the input handle is invalid. |
| @@ -265,11 +240,11 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle | |||
| 265 | *result = tmp; | 240 | *result = tmp; |
| 266 | 241 | ||
| 267 | // We succeeded. | 242 | // We succeeded. |
| 268 | return ResultSuccess; | 243 | R_SUCCEED(); |
| 269 | } | 244 | } |
| 270 | default: | 245 | default: |
| 271 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); | 246 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); |
| 272 | return ResultInvalidEnumValue; | 247 | R_THROW(ResultInvalidEnumValue); |
| 273 | } | 248 | } |
| 274 | } | 249 | } |
| 275 | 250 | ||
diff --git a/src/core/hle/kernel/svc/svc_ipc.cpp b/src/core/hle/kernel/svc/svc_ipc.cpp index a7a2c3b92..bca303650 100644 --- a/src/core/hle/kernel/svc/svc_ipc.cpp +++ b/src/core/hle/kernel/svc/svc_ipc.cpp | |||
| @@ -19,7 +19,7 @@ Result SendSyncRequest(Core::System& system, Handle handle) { | |||
| 19 | 19 | ||
| 20 | LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); | 20 | LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); |
| 21 | 21 | ||
| 22 | return session->SendSyncRequest(); | 22 | R_RETURN(session->SendSyncRequest()); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | Result SendSyncRequestWithUserBuffer(Core::System& system, uint64_t message_buffer, | 25 | Result SendSyncRequestWithUserBuffer(Core::System& system, uint64_t message_buffer, |
| @@ -82,7 +82,7 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad | |||
| 82 | Result result = KSynchronizationObject::Wait(kernel, &index, objs.data(), | 82 | Result result = KSynchronizationObject::Wait(kernel, &index, objs.data(), |
| 83 | static_cast<s32>(objs.size()), timeout_ns); | 83 | static_cast<s32>(objs.size()), timeout_ns); |
| 84 | if (result == ResultTimedOut) { | 84 | if (result == ResultTimedOut) { |
| 85 | return result; | 85 | R_RETURN(result); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | // Receive the request. | 88 | // Receive the request. |
| @@ -97,7 +97,7 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | *out_index = index; | 99 | *out_index = index; |
| 100 | return result; | 100 | R_RETURN(result); |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | 103 | ||
diff --git a/src/core/hle/kernel/svc/svc_lock.cpp b/src/core/hle/kernel/svc/svc_lock.cpp index f3d3e140b..3681279d6 100644 --- a/src/core/hle/kernel/svc/svc_lock.cpp +++ b/src/core/hle/kernel/svc/svc_lock.cpp | |||
| @@ -14,17 +14,10 @@ Result ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address, | |||
| 14 | thread_handle, address, tag); | 14 | thread_handle, address, tag); |
| 15 | 15 | ||
| 16 | // Validate the input address. | 16 | // Validate the input address. |
| 17 | if (IsKernelAddress(address)) { | 17 | R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory); |
| 18 | LOG_ERROR(Kernel_SVC, "Attempting to arbitrate a lock on a kernel address (address={:08X})", | 18 | R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress); |
| 19 | address); | ||
| 20 | return ResultInvalidCurrentMemory; | ||
| 21 | } | ||
| 22 | if (!Common::IsAligned(address, sizeof(u32))) { | ||
| 23 | LOG_ERROR(Kernel_SVC, "Input address must be 4 byte aligned (address: {:08X})", address); | ||
| 24 | return ResultInvalidAddress; | ||
| 25 | } | ||
| 26 | 19 | ||
| 27 | return GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag); | 20 | R_RETURN(GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag)); |
| 28 | } | 21 | } |
| 29 | 22 | ||
| 30 | /// Unlock a mutex | 23 | /// Unlock a mutex |
| @@ -32,18 +25,10 @@ Result ArbitrateUnlock(Core::System& system, VAddr address) { | |||
| 32 | LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); | 25 | LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); |
| 33 | 26 | ||
| 34 | // Validate the input address. | 27 | // Validate the input address. |
| 35 | if (IsKernelAddress(address)) { | 28 | R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory); |
| 36 | LOG_ERROR(Kernel_SVC, | 29 | R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress); |
| 37 | "Attempting to arbitrate an unlock on a kernel address (address={:08X})", | ||
| 38 | address); | ||
| 39 | return ResultInvalidCurrentMemory; | ||
| 40 | } | ||
| 41 | if (!Common::IsAligned(address, sizeof(u32))) { | ||
| 42 | LOG_ERROR(Kernel_SVC, "Input address must be 4 byte aligned (address: {:08X})", address); | ||
| 43 | return ResultInvalidAddress; | ||
| 44 | } | ||
| 45 | 30 | ||
| 46 | return GetCurrentProcess(system.Kernel()).SignalToAddress(address); | 31 | R_RETURN(GetCurrentProcess(system.Kernel()).SignalToAddress(address)); |
| 47 | } | 32 | } |
| 48 | 33 | ||
| 49 | Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) { | 34 | 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 214bcd073..4db25a3b7 100644 --- a/src/core/hle/kernel/svc/svc_memory.cpp +++ b/src/core/hle/kernel/svc/svc_memory.cpp | |||
| @@ -33,49 +33,49 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd | |||
| 33 | u64 size) { | 33 | u64 size) { |
| 34 | if (!Common::Is4KBAligned(dst_addr)) { | 34 | if (!Common::Is4KBAligned(dst_addr)) { |
| 35 | LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); | 35 | LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); |
| 36 | return ResultInvalidAddress; | 36 | R_THROW(ResultInvalidAddress); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | if (!Common::Is4KBAligned(src_addr)) { | 39 | if (!Common::Is4KBAligned(src_addr)) { |
| 40 | LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); | 40 | LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); |
| 41 | return ResultInvalidSize; | 41 | R_THROW(ResultInvalidSize); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | if (size == 0) { | 44 | if (size == 0) { |
| 45 | LOG_ERROR(Kernel_SVC, "Size is 0"); | 45 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 46 | return ResultInvalidSize; | 46 | R_THROW(ResultInvalidSize); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | if (!Common::Is4KBAligned(size)) { | 49 | if (!Common::Is4KBAligned(size)) { |
| 50 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); | 50 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); |
| 51 | return ResultInvalidSize; | 51 | R_THROW(ResultInvalidSize); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | if (!IsValidAddressRange(dst_addr, size)) { | 54 | if (!IsValidAddressRange(dst_addr, size)) { |
| 55 | LOG_ERROR(Kernel_SVC, | 55 | LOG_ERROR(Kernel_SVC, |
| 56 | "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}", | 56 | "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 57 | dst_addr, size); | 57 | dst_addr, size); |
| 58 | return ResultInvalidCurrentMemory; | 58 | R_THROW(ResultInvalidCurrentMemory); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | if (!IsValidAddressRange(src_addr, size)) { | 61 | if (!IsValidAddressRange(src_addr, size)) { |
| 62 | LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}", | 62 | LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 63 | src_addr, size); | 63 | src_addr, size); |
| 64 | return ResultInvalidCurrentMemory; | 64 | R_THROW(ResultInvalidCurrentMemory); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | if (!manager.IsInsideAddressSpace(src_addr, size)) { | 67 | if (!manager.IsInsideAddressSpace(src_addr, size)) { |
| 68 | LOG_ERROR(Kernel_SVC, | 68 | LOG_ERROR(Kernel_SVC, |
| 69 | "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", | 69 | "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", |
| 70 | src_addr, size); | 70 | src_addr, size); |
| 71 | return ResultInvalidCurrentMemory; | 71 | R_THROW(ResultInvalidCurrentMemory); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | if (manager.IsOutsideStackRegion(dst_addr, size)) { | 74 | if (manager.IsOutsideStackRegion(dst_addr, size)) { |
| 75 | LOG_ERROR(Kernel_SVC, | 75 | LOG_ERROR(Kernel_SVC, |
| 76 | "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}", | 76 | "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}", |
| 77 | dst_addr, size); | 77 | dst_addr, size); |
| 78 | return ResultInvalidMemoryRegion; | 78 | R_THROW(ResultInvalidMemoryRegion); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | if (manager.IsInsideHeapRegion(dst_addr, size)) { | 81 | if (manager.IsInsideHeapRegion(dst_addr, size)) { |
| @@ -83,7 +83,7 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd | |||
| 83 | "Destination does not fit within the heap region, addr=0x{:016X}, " | 83 | "Destination does not fit within the heap region, addr=0x{:016X}, " |
| 84 | "size=0x{:016X}", | 84 | "size=0x{:016X}", |
| 85 | dst_addr, size); | 85 | dst_addr, size); |
| 86 | return ResultInvalidMemoryRegion; | 86 | R_THROW(ResultInvalidMemoryRegion); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | if (manager.IsInsideAliasRegion(dst_addr, size)) { | 89 | if (manager.IsInsideAliasRegion(dst_addr, size)) { |
| @@ -91,10 +91,10 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd | |||
| 91 | "Destination does not fit within the map region, addr=0x{:016X}, " | 91 | "Destination does not fit within the map region, addr=0x{:016X}, " |
| 92 | "size=0x{:016X}", | 92 | "size=0x{:016X}", |
| 93 | dst_addr, size); | 93 | dst_addr, size); |
| 94 | return ResultInvalidMemoryRegion; | 94 | R_THROW(ResultInvalidMemoryRegion); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | return ResultSuccess; | 97 | R_SUCCEED(); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | } // namespace | 100 | } // namespace |
| @@ -117,7 +117,7 @@ Result SetMemoryPermission(Core::System& system, VAddr address, u64 size, Memory | |||
| 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. |
| 120 | return page_table.SetMemoryPermission(address, size, perm); | 120 | R_RETURN(page_table.SetMemoryPermission(address, size, perm)); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mask, u32 attr) { | 123 | Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mask, u32 attr) { |
| @@ -141,7 +141,7 @@ Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mas | |||
| 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. |
| 144 | return page_table.SetMemoryAttribute(address, size, mask, attr); | 144 | R_RETURN(page_table.SetMemoryAttribute(address, size, mask, attr)); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | /// Maps a memory range into a different range. | 147 | /// Maps a memory range into a different range. |
| @@ -156,7 +156,7 @@ Result MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size) | |||
| 156 | return result; | 156 | return result; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | return page_table.MapMemory(dst_addr, src_addr, size); | 159 | R_RETURN(page_table.MapMemory(dst_addr, src_addr, size)); |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | /// Unmaps a region that was previously mapped with svcMapMemory | 162 | /// Unmaps a region that was previously mapped with svcMapMemory |
| @@ -171,7 +171,7 @@ Result UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 siz | |||
| 171 | return result; | 171 | return result; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | return page_table.UnmapMemory(dst_addr, src_addr, size); | 174 | R_RETURN(page_table.UnmapMemory(dst_addr, src_addr, size)); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | Result SetMemoryPermission64(Core::System& system, uint64_t address, uint64_t size, | 177 | Result SetMemoryPermission64(Core::System& system, uint64_t address, uint64_t size, |
diff --git a/src/core/hle/kernel/svc/svc_physical_memory.cpp b/src/core/hle/kernel/svc/svc_physical_memory.cpp index ed6a624ac..63196e1ed 100644 --- a/src/core/hle/kernel/svc/svc_physical_memory.cpp +++ b/src/core/hle/kernel/svc/svc_physical_memory.cpp | |||
| @@ -16,9 +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(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size)); | 19 | R_RETURN(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size)); |
| 20 | |||
| 21 | return ResultSuccess; | ||
| 22 | } | 20 | } |
| 23 | 21 | ||
| 24 | /// Maps memory at a desired address | 22 | /// Maps memory at a desired address |
| @@ -27,22 +25,22 @@ Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { | |||
| 27 | 25 | ||
| 28 | if (!Common::Is4KBAligned(addr)) { | 26 | if (!Common::Is4KBAligned(addr)) { |
| 29 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); | 27 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); |
| 30 | return ResultInvalidAddress; | 28 | R_THROW(ResultInvalidAddress); |
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | if (!Common::Is4KBAligned(size)) { | 31 | if (!Common::Is4KBAligned(size)) { |
| 34 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); | 32 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); |
| 35 | return ResultInvalidSize; | 33 | R_THROW(ResultInvalidSize); |
| 36 | } | 34 | } |
| 37 | 35 | ||
| 38 | if (size == 0) { | 36 | if (size == 0) { |
| 39 | LOG_ERROR(Kernel_SVC, "Size is zero"); | 37 | LOG_ERROR(Kernel_SVC, "Size is zero"); |
| 40 | return ResultInvalidSize; | 38 | R_THROW(ResultInvalidSize); |
| 41 | } | 39 | } |
| 42 | 40 | ||
| 43 | if (!(addr < addr + size)) { | 41 | if (!(addr < addr + size)) { |
| 44 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); | 42 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); |
| 45 | return ResultInvalidMemoryRegion; | 43 | R_THROW(ResultInvalidMemoryRegion); |
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; | 46 | KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; |
| @@ -50,24 +48,24 @@ Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { | |||
| 50 | 48 | ||
| 51 | if (current_process->GetSystemResourceSize() == 0) { | 49 | if (current_process->GetSystemResourceSize() == 0) { |
| 52 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); | 50 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); |
| 53 | return ResultInvalidState; | 51 | R_THROW(ResultInvalidState); |
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | if (!page_table.IsInsideAddressSpace(addr, size)) { | 54 | if (!page_table.IsInsideAddressSpace(addr, size)) { |
| 57 | LOG_ERROR(Kernel_SVC, | 55 | LOG_ERROR(Kernel_SVC, |
| 58 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, | 56 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, |
| 59 | size); | 57 | size); |
| 60 | return ResultInvalidMemoryRegion; | 58 | R_THROW(ResultInvalidMemoryRegion); |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | if (page_table.IsOutsideAliasRegion(addr, size)) { | 61 | if (page_table.IsOutsideAliasRegion(addr, size)) { |
| 64 | LOG_ERROR(Kernel_SVC, | 62 | LOG_ERROR(Kernel_SVC, |
| 65 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, | 63 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, |
| 66 | size); | 64 | size); |
| 67 | return ResultInvalidMemoryRegion; | 65 | R_THROW(ResultInvalidMemoryRegion); |
| 68 | } | 66 | } |
| 69 | 67 | ||
| 70 | return page_table.MapPhysicalMemory(addr, size); | 68 | R_RETURN(page_table.MapPhysicalMemory(addr, size)); |
| 71 | } | 69 | } |
| 72 | 70 | ||
| 73 | /// Unmaps memory previously mapped via MapPhysicalMemory | 71 | /// Unmaps memory previously mapped via MapPhysicalMemory |
| @@ -76,22 +74,22 @@ Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { | |||
| 76 | 74 | ||
| 77 | if (!Common::Is4KBAligned(addr)) { | 75 | if (!Common::Is4KBAligned(addr)) { |
| 78 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); | 76 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); |
| 79 | return ResultInvalidAddress; | 77 | R_THROW(ResultInvalidAddress); |
| 80 | } | 78 | } |
| 81 | 79 | ||
| 82 | if (!Common::Is4KBAligned(size)) { | 80 | if (!Common::Is4KBAligned(size)) { |
| 83 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); | 81 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); |
| 84 | return ResultInvalidSize; | 82 | R_THROW(ResultInvalidSize); |
| 85 | } | 83 | } |
| 86 | 84 | ||
| 87 | if (size == 0) { | 85 | if (size == 0) { |
| 88 | LOG_ERROR(Kernel_SVC, "Size is zero"); | 86 | LOG_ERROR(Kernel_SVC, "Size is zero"); |
| 89 | return ResultInvalidSize; | 87 | R_THROW(ResultInvalidSize); |
| 90 | } | 88 | } |
| 91 | 89 | ||
| 92 | if (!(addr < addr + size)) { | 90 | if (!(addr < addr + size)) { |
| 93 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); | 91 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); |
| 94 | return ResultInvalidMemoryRegion; | 92 | R_THROW(ResultInvalidMemoryRegion); |
| 95 | } | 93 | } |
| 96 | 94 | ||
| 97 | KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; | 95 | KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; |
| @@ -99,24 +97,24 @@ Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { | |||
| 99 | 97 | ||
| 100 | if (current_process->GetSystemResourceSize() == 0) { | 98 | if (current_process->GetSystemResourceSize() == 0) { |
| 101 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); | 99 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); |
| 102 | return ResultInvalidState; | 100 | R_THROW(ResultInvalidState); |
| 103 | } | 101 | } |
| 104 | 102 | ||
| 105 | if (!page_table.IsInsideAddressSpace(addr, size)) { | 103 | if (!page_table.IsInsideAddressSpace(addr, size)) { |
| 106 | LOG_ERROR(Kernel_SVC, | 104 | LOG_ERROR(Kernel_SVC, |
| 107 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, | 105 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, |
| 108 | size); | 106 | size); |
| 109 | return ResultInvalidMemoryRegion; | 107 | R_THROW(ResultInvalidMemoryRegion); |
| 110 | } | 108 | } |
| 111 | 109 | ||
| 112 | if (page_table.IsOutsideAliasRegion(addr, size)) { | 110 | if (page_table.IsOutsideAliasRegion(addr, size)) { |
| 113 | LOG_ERROR(Kernel_SVC, | 111 | LOG_ERROR(Kernel_SVC, |
| 114 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, | 112 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, |
| 115 | size); | 113 | size); |
| 116 | return ResultInvalidMemoryRegion; | 114 | R_THROW(ResultInvalidMemoryRegion); |
| 117 | } | 115 | } |
| 118 | 116 | ||
| 119 | return page_table.UnmapPhysicalMemory(addr, size); | 117 | R_RETURN(page_table.UnmapPhysicalMemory(addr, size)); |
| 120 | } | 118 | } |
| 121 | 119 | ||
| 122 | Result MapPhysicalMemoryUnsafe(Core::System& system, uint64_t address, uint64_t size) { | 120 | Result MapPhysicalMemoryUnsafe(Core::System& system, uint64_t address, uint64_t size) { |
diff --git a/src/core/hle/kernel/svc/svc_process.cpp b/src/core/hle/kernel/svc/svc_process.cpp index c35d2be76..e4149fba9 100644 --- a/src/core/hle/kernel/svc/svc_process.cpp +++ b/src/core/hle/kernel/svc/svc_process.cpp | |||
| @@ -47,7 +47,7 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) { | |||
| 47 | // Get the process id. | 47 | // Get the process id. |
| 48 | *out_process_id = process->GetId(); | 48 | *out_process_id = process->GetId(); |
| 49 | 49 | ||
| 50 | return ResultSuccess; | 50 | R_SUCCEED(); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_process_ids, | 53 | Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_process_ids, |
| @@ -60,7 +60,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr | |||
| 60 | LOG_ERROR(Kernel_SVC, | 60 | LOG_ERROR(Kernel_SVC, |
| 61 | "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}", | 61 | "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}", |
| 62 | out_process_ids_size); | 62 | out_process_ids_size); |
| 63 | return ResultOutOfRange; | 63 | R_THROW(ResultOutOfRange); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | auto& kernel = system.Kernel(); | 66 | auto& kernel = system.Kernel(); |
| @@ -70,7 +70,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr | |||
| 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); |
| 73 | return ResultInvalidCurrentMemory; | 73 | R_THROW(ResultInvalidCurrentMemory); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | auto& memory = system.Memory(); | 76 | auto& memory = system.Memory(); |
| @@ -85,7 +85,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr | |||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | *out_num_processes = static_cast<u32>(num_processes); | 87 | *out_num_processes = static_cast<u32>(num_processes); |
| 88 | return ResultSuccess; | 88 | R_SUCCEED(); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle, | 91 | Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle, |
| @@ -97,17 +97,17 @@ Result GetProcessInfo(Core::System& system, s64* out, Handle 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}", |
| 99 | process_handle); | 99 | process_handle); |
| 100 | return ResultInvalidHandle; | 100 | R_THROW(ResultInvalidHandle); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | if (info_type != ProcessInfoType::ProcessState) { | 103 | if (info_type != ProcessInfoType::ProcessState) { |
| 104 | LOG_ERROR(Kernel_SVC, "Expected info_type to be ProcessState but got {} instead", | 104 | LOG_ERROR(Kernel_SVC, "Expected info_type to be ProcessState but got {} instead", |
| 105 | info_type); | 105 | info_type); |
| 106 | return ResultInvalidEnumValue; | 106 | R_THROW(ResultInvalidEnumValue); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | *out = static_cast<s64>(process->GetState()); | 109 | *out = static_cast<s64>(process->GetState()); |
| 110 | return ResultSuccess; | 110 | R_SUCCEED(); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | Result CreateProcess(Core::System& system, Handle* out_handle, uint64_t parameters, uint64_t caps, | 113 | Result CreateProcess(Core::System& system, Handle* out_handle, uint64_t parameters, uint64_t caps, |
diff --git a/src/core/hle/kernel/svc/svc_process_memory.cpp b/src/core/hle/kernel/svc/svc_process_memory.cpp index 8e2fb4092..f9210ca1e 100644 --- a/src/core/hle/kernel/svc/svc_process_memory.cpp +++ b/src/core/hle/kernel/svc/svc_process_memory.cpp | |||
| @@ -53,7 +53,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, V | |||
| 53 | R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); | 53 | R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); |
| 54 | 54 | ||
| 55 | // Set the memory permission. | 55 | // Set the memory permission. |
| 56 | return page_table.SetProcessMemoryPermission(address, size, perm); | 56 | R_RETURN(page_table.SetProcessMemoryPermission(address, size, perm)); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, | 59 | Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, |
| @@ -93,10 +93,8 @@ Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_ | |||
| 93 | KMemoryAttribute::All, KMemoryAttribute::None)); | 93 | KMemoryAttribute::All, KMemoryAttribute::None)); |
| 94 | 94 | ||
| 95 | // Map the group. | 95 | // Map the group. |
| 96 | R_TRY(dst_pt.MapPageGroup(dst_address, pg, KMemoryState::SharedCode, | 96 | R_RETURN(dst_pt.MapPageGroup(dst_address, pg, KMemoryState::SharedCode, |
| 97 | KMemoryPermission::UserReadWrite)); | 97 | KMemoryPermission::UserReadWrite)); |
| 98 | |||
| 99 | return ResultSuccess; | ||
| 100 | } | 98 | } |
| 101 | 99 | ||
| 102 | Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, | 100 | Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, |
| @@ -129,9 +127,7 @@ Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle proces | |||
| 129 | ResultInvalidMemoryRegion); | 127 | ResultInvalidMemoryRegion); |
| 130 | 128 | ||
| 131 | // Unmap the memory. | 129 | // Unmap the memory. |
| 132 | R_TRY(dst_pt.UnmapProcessMemory(dst_address, size, src_pt, src_address)); | 130 | R_RETURN(dst_pt.UnmapProcessMemory(dst_address, size, src_pt, src_address)); |
| 133 | |||
| 134 | return ResultSuccess; | ||
| 135 | } | 131 | } |
| 136 | 132 | ||
| 137 | Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, | 133 | Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, |
| @@ -144,18 +140,18 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 144 | if (!Common::Is4KBAligned(src_address)) { | 140 | if (!Common::Is4KBAligned(src_address)) { |
| 145 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | 141 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", |
| 146 | src_address); | 142 | src_address); |
| 147 | return ResultInvalidAddress; | 143 | R_THROW(ResultInvalidAddress); |
| 148 | } | 144 | } |
| 149 | 145 | ||
| 150 | if (!Common::Is4KBAligned(dst_address)) { | 146 | if (!Common::Is4KBAligned(dst_address)) { |
| 151 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | 147 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", |
| 152 | dst_address); | 148 | dst_address); |
| 153 | return ResultInvalidAddress; | 149 | R_THROW(ResultInvalidAddress); |
| 154 | } | 150 | } |
| 155 | 151 | ||
| 156 | if (size == 0 || !Common::Is4KBAligned(size)) { | 152 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 157 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); | 153 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); |
| 158 | return ResultInvalidSize; | 154 | R_THROW(ResultInvalidSize); |
| 159 | } | 155 | } |
| 160 | 156 | ||
| 161 | if (!IsValidAddressRange(dst_address, size)) { | 157 | if (!IsValidAddressRange(dst_address, size)) { |
| @@ -163,7 +159,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 163 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | 159 | "Destination address range overflows the address space (dst_address=0x{:016X}, " |
| 164 | "size=0x{:016X}).", | 160 | "size=0x{:016X}).", |
| 165 | dst_address, size); | 161 | dst_address, size); |
| 166 | return ResultInvalidCurrentMemory; | 162 | R_THROW(ResultInvalidCurrentMemory); |
| 167 | } | 163 | } |
| 168 | 164 | ||
| 169 | if (!IsValidAddressRange(src_address, size)) { | 165 | if (!IsValidAddressRange(src_address, size)) { |
| @@ -171,7 +167,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 171 | "Source address range overflows the address space (src_address=0x{:016X}, " | 167 | "Source address range overflows the address space (src_address=0x{:016X}, " |
| 172 | "size=0x{:016X}).", | 168 | "size=0x{:016X}).", |
| 173 | src_address, size); | 169 | src_address, size); |
| 174 | return ResultInvalidCurrentMemory; | 170 | R_THROW(ResultInvalidCurrentMemory); |
| 175 | } | 171 | } |
| 176 | 172 | ||
| 177 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); | 173 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| @@ -179,7 +175,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 179 | if (process.IsNull()) { | 175 | if (process.IsNull()) { |
| 180 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | 176 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", |
| 181 | process_handle); | 177 | process_handle); |
| 182 | return ResultInvalidHandle; | 178 | R_THROW(ResultInvalidHandle); |
| 183 | } | 179 | } |
| 184 | 180 | ||
| 185 | auto& page_table = process->PageTable(); | 181 | auto& page_table = process->PageTable(); |
| @@ -188,7 +184,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 188 | "Source address range is not within the address space (src_address=0x{:016X}, " | 184 | "Source address range is not within the address space (src_address=0x{:016X}, " |
| 189 | "size=0x{:016X}).", | 185 | "size=0x{:016X}).", |
| 190 | src_address, size); | 186 | src_address, size); |
| 191 | return ResultInvalidCurrentMemory; | 187 | R_THROW(ResultInvalidCurrentMemory); |
| 192 | } | 188 | } |
| 193 | 189 | ||
| 194 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { | 190 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { |
| @@ -196,10 +192,10 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst | |||
| 196 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | 192 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " |
| 197 | "size=0x{:016X}).", | 193 | "size=0x{:016X}).", |
| 198 | dst_address, size); | 194 | dst_address, size); |
| 199 | return ResultInvalidMemoryRegion; | 195 | R_THROW(ResultInvalidMemoryRegion); |
| 200 | } | 196 | } |
| 201 | 197 | ||
| 202 | return page_table.MapCodeMemory(dst_address, src_address, size); | 198 | R_RETURN(page_table.MapCodeMemory(dst_address, src_address, size)); |
| 203 | } | 199 | } |
| 204 | 200 | ||
| 205 | Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, | 201 | Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, |
| @@ -212,18 +208,18 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 212 | if (!Common::Is4KBAligned(dst_address)) { | 208 | if (!Common::Is4KBAligned(dst_address)) { |
| 213 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | 209 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", |
| 214 | dst_address); | 210 | dst_address); |
| 215 | return ResultInvalidAddress; | 211 | R_THROW(ResultInvalidAddress); |
| 216 | } | 212 | } |
| 217 | 213 | ||
| 218 | if (!Common::Is4KBAligned(src_address)) { | 214 | if (!Common::Is4KBAligned(src_address)) { |
| 219 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | 215 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", |
| 220 | src_address); | 216 | src_address); |
| 221 | return ResultInvalidAddress; | 217 | R_THROW(ResultInvalidAddress); |
| 222 | } | 218 | } |
| 223 | 219 | ||
| 224 | if (size == 0 || !Common::Is4KBAligned(size)) { | 220 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 225 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); | 221 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); |
| 226 | return ResultInvalidSize; | 222 | R_THROW(ResultInvalidSize); |
| 227 | } | 223 | } |
| 228 | 224 | ||
| 229 | if (!IsValidAddressRange(dst_address, size)) { | 225 | if (!IsValidAddressRange(dst_address, size)) { |
| @@ -231,7 +227,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 231 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | 227 | "Destination address range overflows the address space (dst_address=0x{:016X}, " |
| 232 | "size=0x{:016X}).", | 228 | "size=0x{:016X}).", |
| 233 | dst_address, size); | 229 | dst_address, size); |
| 234 | return ResultInvalidCurrentMemory; | 230 | R_THROW(ResultInvalidCurrentMemory); |
| 235 | } | 231 | } |
| 236 | 232 | ||
| 237 | if (!IsValidAddressRange(src_address, size)) { | 233 | if (!IsValidAddressRange(src_address, size)) { |
| @@ -239,7 +235,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 239 | "Source address range overflows the address space (src_address=0x{:016X}, " | 235 | "Source address range overflows the address space (src_address=0x{:016X}, " |
| 240 | "size=0x{:016X}).", | 236 | "size=0x{:016X}).", |
| 241 | src_address, size); | 237 | src_address, size); |
| 242 | return ResultInvalidCurrentMemory; | 238 | R_THROW(ResultInvalidCurrentMemory); |
| 243 | } | 239 | } |
| 244 | 240 | ||
| 245 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); | 241 | const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); |
| @@ -247,7 +243,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 247 | if (process.IsNull()) { | 243 | if (process.IsNull()) { |
| 248 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | 244 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", |
| 249 | process_handle); | 245 | process_handle); |
| 250 | return ResultInvalidHandle; | 246 | R_THROW(ResultInvalidHandle); |
| 251 | } | 247 | } |
| 252 | 248 | ||
| 253 | auto& page_table = process->PageTable(); | 249 | auto& page_table = process->PageTable(); |
| @@ -256,7 +252,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 256 | "Source address range is not within the address space (src_address=0x{:016X}, " | 252 | "Source address range is not within the address space (src_address=0x{:016X}, " |
| 257 | "size=0x{:016X}).", | 253 | "size=0x{:016X}).", |
| 258 | src_address, size); | 254 | src_address, size); |
| 259 | return ResultInvalidCurrentMemory; | 255 | R_THROW(ResultInvalidCurrentMemory); |
| 260 | } | 256 | } |
| 261 | 257 | ||
| 262 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { | 258 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { |
| @@ -264,11 +260,11 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d | |||
| 264 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | 260 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " |
| 265 | "size=0x{:016X}).", | 261 | "size=0x{:016X}).", |
| 266 | dst_address, size); | 262 | dst_address, size); |
| 267 | return ResultInvalidMemoryRegion; | 263 | R_THROW(ResultInvalidMemoryRegion); |
| 268 | } | 264 | } |
| 269 | 265 | ||
| 270 | return page_table.UnmapCodeMemory(dst_address, src_address, size, | 266 | R_RETURN(page_table.UnmapCodeMemory(dst_address, src_address, size, |
| 271 | KPageTable::ICacheInvalidationStrategy::InvalidateAll); | 267 | KPageTable::ICacheInvalidationStrategy::InvalidateAll)); |
| 272 | } | 268 | } |
| 273 | 269 | ||
| 274 | Result SetProcessMemoryPermission64(Core::System& system, Handle process_handle, uint64_t address, | 270 | Result SetProcessMemoryPermission64(Core::System& system, Handle process_handle, uint64_t address, |
diff --git a/src/core/hle/kernel/svc/svc_query_memory.cpp b/src/core/hle/kernel/svc/svc_query_memory.cpp index ee75ad370..b2290164c 100644 --- a/src/core/hle/kernel/svc/svc_query_memory.cpp +++ b/src/core/hle/kernel/svc/svc_query_memory.cpp | |||
| @@ -15,8 +15,8 @@ Result QueryMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out | |||
| 15 | out_memory_info, query_address); | 15 | out_memory_info, query_address); |
| 16 | 16 | ||
| 17 | // Query memory is just QueryProcessMemory on the current process. | 17 | // Query memory is just QueryProcessMemory on the current process. |
| 18 | return QueryProcessMemory(system, out_memory_info, out_page_info, CurrentProcess, | 18 | R_RETURN( |
| 19 | query_address); | 19 | QueryProcessMemory(system, out_memory_info, out_page_info, CurrentProcess, query_address)); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 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, |
| @@ -27,7 +27,7 @@ Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageIn | |||
| 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}", |
| 29 | process_handle); | 29 | process_handle); |
| 30 | return ResultInvalidHandle; | 30 | R_THROW(ResultInvalidHandle); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | auto& memory{system.Memory()}; | 33 | auto& memory{system.Memory()}; |
diff --git a/src/core/hle/kernel/svc/svc_resource_limit.cpp b/src/core/hle/kernel/svc/svc_resource_limit.cpp index 88166299e..d96a7e879 100644 --- a/src/core/hle/kernel/svc/svc_resource_limit.cpp +++ b/src/core/hle/kernel/svc/svc_resource_limit.cpp | |||
| @@ -27,9 +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(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit)); | 30 | R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit)); |
| 31 | |||
| 32 | return ResultSuccess; | ||
| 33 | } | 31 | } |
| 34 | 32 | ||
| 35 | Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value, | 33 | Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value, |
| @@ -49,7 +47,7 @@ Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value, | |||
| 49 | // Get the limit value. | 47 | // Get the limit value. |
| 50 | *out_limit_value = resource_limit->GetLimitValue(which); | 48 | *out_limit_value = resource_limit->GetLimitValue(which); |
| 51 | 49 | ||
| 52 | return ResultSuccess; | 50 | R_SUCCEED(); |
| 53 | } | 51 | } |
| 54 | 52 | ||
| 55 | Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value, | 53 | Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value, |
| @@ -69,7 +67,7 @@ Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value | |||
| 69 | // Get the current value. | 67 | // Get the current value. |
| 70 | *out_current_value = resource_limit->GetCurrentValue(which); | 68 | *out_current_value = resource_limit->GetCurrentValue(which); |
| 71 | 69 | ||
| 72 | return ResultSuccess; | 70 | R_SUCCEED(); |
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_handle, | 73 | Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_handle, |
| @@ -87,9 +85,7 @@ Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_ha | |||
| 87 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); | 85 | R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); |
| 88 | 86 | ||
| 89 | // Set the limit value. | 87 | // Set the limit value. |
| 90 | R_TRY(resource_limit->SetLimitValue(which, limit_value)); | 88 | R_RETURN(resource_limit->SetLimitValue(which, limit_value)); |
| 91 | |||
| 92 | return ResultSuccess; | ||
| 93 | } | 89 | } |
| 94 | 90 | ||
| 95 | Result GetResourceLimitPeakValue(Core::System& system, int64_t* out_peak_value, | 91 | Result GetResourceLimitPeakValue(Core::System& system, int64_t* out_peak_value, |
diff --git a/src/core/hle/kernel/svc/svc_session.cpp b/src/core/hle/kernel/svc/svc_session.cpp index 90d680540..d5a3d0120 100644 --- a/src/core/hle/kernel/svc/svc_session.cpp +++ b/src/core/hle/kernel/svc/svc_session.cpp | |||
| @@ -25,7 +25,7 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien | |||
| 25 | if (session_reservation.Succeeded()) { | 25 | if (session_reservation.Succeeded()) { |
| 26 | session = T::Create(system.Kernel()); | 26 | session = T::Create(system.Kernel()); |
| 27 | } else { | 27 | } else { |
| 28 | return ResultLimitReached; | 28 | R_THROW(ResultLimitReached); |
| 29 | 29 | ||
| 30 | // // We couldn't reserve a session. Check that we support dynamically expanding the | 30 | // // We couldn't reserve a session. Check that we support dynamically expanding the |
| 31 | // // resource limit. | 31 | // // resource limit. |
| @@ -77,15 +77,13 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien | |||
| 77 | // Add the server session to the handle table. | 77 | // Add the server session to the handle table. |
| 78 | R_TRY(handle_table.Add(out_server, &session->GetServerSession())); | 78 | R_TRY(handle_table.Add(out_server, &session->GetServerSession())); |
| 79 | 79 | ||
| 80 | // Add the client session to the handle table. | 80 | // Ensure that we maintain a clean handle state on exit. |
| 81 | const auto result = handle_table.Add(out_client, &session->GetClientSession()); | 81 | ON_RESULT_FAILURE { |
| 82 | |||
| 83 | if (!R_SUCCEEDED(result)) { | ||
| 84 | // Ensure that we maintain a clean handle state on exit. | ||
| 85 | handle_table.Remove(*out_server); | 82 | handle_table.Remove(*out_server); |
| 86 | } | 83 | }; |
| 87 | 84 | ||
| 88 | return result; | 85 | // Add the client session to the handle table. |
| 86 | R_RETURN(handle_table.Add(out_client, &session->GetClientSession())); | ||
| 89 | } | 87 | } |
| 90 | 88 | ||
| 91 | } // namespace | 89 | } // namespace |
| @@ -94,9 +92,9 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien | |||
| 94 | u64 name) { | 92 | u64 name) { |
| 95 | if (is_light) { | 93 | if (is_light) { |
| 96 | // return CreateSession<KLightSession>(system, out_server, out_client, name); | 94 | // return CreateSession<KLightSession>(system, out_server, out_client, name); |
| 97 | return ResultNotImplemented; | 95 | R_THROW(ResultNotImplemented); |
| 98 | } else { | 96 | } else { |
| 99 | return CreateSession<KSession>(system, out_server, out_client, name); | 97 | R_RETURN(CreateSession<KSession>(system, out_server, out_client, name)); |
| 100 | } | 98 | } |
| 101 | } | 99 | } |
| 102 | 100 | ||
diff --git a/src/core/hle/kernel/svc/svc_shared_memory.cpp b/src/core/hle/kernel/svc/svc_shared_memory.cpp index 18e0dc904..40d878f17 100644 --- a/src/core/hle/kernel/svc/svc_shared_memory.cpp +++ b/src/core/hle/kernel/svc/svc_shared_memory.cpp | |||
| @@ -56,15 +56,12 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, | |||
| 56 | R_TRY(process.AddSharedMemory(shmem.GetPointerUnsafe(), address, size)); | 56 | R_TRY(process.AddSharedMemory(shmem.GetPointerUnsafe(), address, size)); |
| 57 | 57 | ||
| 58 | // Ensure that we clean up the shared memory if we fail to map it. | 58 | // Ensure that we clean up the shared memory if we fail to map it. |
| 59 | auto guard = | 59 | ON_RESULT_FAILURE { |
| 60 | SCOPE_GUARD({ process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); }); | 60 | process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); |
| 61 | }; | ||
| 61 | 62 | ||
| 62 | // Map the shared memory. | 63 | // Map the shared memory. |
| 63 | R_TRY(shmem->Map(process, address, size, map_perm)); | 64 | R_RETURN(shmem->Map(process, address, size, map_perm)); |
| 64 | |||
| 65 | // We succeeded. | ||
| 66 | guard.Cancel(); | ||
| 67 | return ResultSuccess; | ||
| 68 | } | 65 | } |
| 69 | 66 | ||
| 70 | Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, u64 size) { | 67 | Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, u64 size) { |
| @@ -91,7 +88,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr addres | |||
| 91 | // Remove the shared memory from the process. | 88 | // Remove the shared memory from the process. |
| 92 | process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); | 89 | process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); |
| 93 | 90 | ||
| 94 | return ResultSuccess; | 91 | R_SUCCEED(); |
| 95 | } | 92 | } |
| 96 | 93 | ||
| 97 | Result CreateSharedMemory(Core::System& system, Handle* out_handle, uint64_t size, | 94 | Result CreateSharedMemory(Core::System& system, Handle* out_handle, uint64_t size, |
diff --git a/src/core/hle/kernel/svc/svc_synchronization.cpp b/src/core/hle/kernel/svc/svc_synchronization.cpp index 9e7bf9530..660b45c23 100644 --- a/src/core/hle/kernel/svc/svc_synchronization.cpp +++ b/src/core/hle/kernel/svc/svc_synchronization.cpp | |||
| @@ -17,7 +17,7 @@ Result CloseHandle(Core::System& system, Handle handle) { | |||
| 17 | R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle), | 17 | R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle), |
| 18 | ResultInvalidHandle); | 18 | ResultInvalidHandle); |
| 19 | 19 | ||
| 20 | return ResultSuccess; | 20 | R_SUCCEED(); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /// Clears the signaled state of an event or process. | 23 | /// Clears the signaled state of an event or process. |
| @@ -31,7 +31,7 @@ Result ResetSignal(Core::System& system, Handle handle) { | |||
| 31 | { | 31 | { |
| 32 | KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(handle); | 32 | KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(handle); |
| 33 | if (readable_event.IsNotNull()) { | 33 | if (readable_event.IsNotNull()) { |
| 34 | return readable_event->Reset(); | 34 | R_RETURN(readable_event->Reset()); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -39,13 +39,11 @@ Result ResetSignal(Core::System& system, Handle handle) { | |||
| 39 | { | 39 | { |
| 40 | KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); | 40 | KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); |
| 41 | if (process.IsNotNull()) { | 41 | if (process.IsNotNull()) { |
| 42 | return process->Reset(); | 42 | R_RETURN(process->Reset()); |
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle); | 46 | R_THROW(ResultInvalidHandle); |
| 47 | |||
| 48 | return ResultInvalidHandle; | ||
| 49 | } | 47 | } |
| 50 | 48 | ||
| 51 | static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles, | 49 | static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles, |
| @@ -109,7 +107,7 @@ Result CancelSynchronization(Core::System& system, Handle handle) { | |||
| 109 | 107 | ||
| 110 | // Cancel the thread's wait. | 108 | // Cancel the thread's wait. |
| 111 | thread->WaitCancel(); | 109 | thread->WaitCancel(); |
| 112 | return ResultSuccess; | 110 | R_SUCCEED(); |
| 113 | } | 111 | } |
| 114 | 112 | ||
| 115 | void SynchronizePreemptionState(Core::System& system) { | 113 | void SynchronizePreemptionState(Core::System& system) { |
diff --git a/src/core/hle/kernel/svc/svc_thread.cpp b/src/core/hle/kernel/svc/svc_thread.cpp index 9bc1ebe74..5e888153b 100644 --- a/src/core/hle/kernel/svc/svc_thread.cpp +++ b/src/core/hle/kernel/svc/svc_thread.cpp | |||
| @@ -34,39 +34,22 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | // Validate arguments. | 36 | // Validate arguments. |
| 37 | if (!IsValidVirtualCoreId(core_id)) { | 37 | R_UNLESS(IsValidVirtualCoreId(core_id), ResultInvalidCoreId); |
| 38 | LOG_ERROR(Kernel_SVC, "Invalid Core ID specified (id={})", core_id); | 38 | R_UNLESS(((1ull << core_id) & process.GetCoreMask()) != 0, ResultInvalidCoreId); |
| 39 | return ResultInvalidCoreId; | ||
| 40 | } | ||
| 41 | if (((1ULL << core_id) & process.GetCoreMask()) == 0) { | ||
| 42 | LOG_ERROR(Kernel_SVC, "Core ID doesn't fall within allowable cores (id={})", core_id); | ||
| 43 | return ResultInvalidCoreId; | ||
| 44 | } | ||
| 45 | 39 | ||
| 46 | if (HighestThreadPriority > priority || priority > LowestThreadPriority) { | 40 | R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority, |
| 47 | LOG_ERROR(Kernel_SVC, "Invalid priority specified (priority={})", priority); | 41 | ResultInvalidPriority); |
| 48 | return ResultInvalidPriority; | 42 | R_UNLESS(process.CheckThreadPriority(priority), ResultInvalidPriority); |
| 49 | } | ||
| 50 | if (!process.CheckThreadPriority(priority)) { | ||
| 51 | LOG_ERROR(Kernel_SVC, "Invalid allowable thread priority (priority={})", priority); | ||
| 52 | return ResultInvalidPriority; | ||
| 53 | } | ||
| 54 | 43 | ||
| 55 | // Reserve a new thread from the process resource limit (waiting up to 100ms). | 44 | // Reserve a new thread from the process resource limit (waiting up to 100ms). |
| 56 | KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1, | 45 | KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1, |
| 57 | system.CoreTiming().GetGlobalTimeNs().count() + | 46 | system.CoreTiming().GetGlobalTimeNs().count() + |
| 58 | 100000000); | 47 | 100000000); |
| 59 | if (!thread_reservation.Succeeded()) { | 48 | R_UNLESS(thread_reservation.Succeeded(), ResultLimitReached); |
| 60 | LOG_ERROR(Kernel_SVC, "Could not reserve a new thread"); | ||
| 61 | return ResultLimitReached; | ||
| 62 | } | ||
| 63 | 49 | ||
| 64 | // Create the thread. | 50 | // Create the thread. |
| 65 | KThread* thread = KThread::Create(kernel); | 51 | KThread* thread = KThread::Create(kernel); |
| 66 | if (!thread) { | 52 | R_UNLESS(thread != nullptr, ResultOutOfResource) |
| 67 | LOG_ERROR(Kernel_SVC, "Unable to create new threads. Thread creation limit reached."); | ||
| 68 | return ResultOutOfResource; | ||
| 69 | } | ||
| 70 | SCOPE_EXIT({ thread->Close(); }); | 53 | SCOPE_EXIT({ thread->Close(); }); |
| 71 | 54 | ||
| 72 | // Initialize the thread. | 55 | // Initialize the thread. |
| @@ -89,9 +72,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, | |||
| 89 | KThread::Register(kernel, thread); | 72 | KThread::Register(kernel, thread); |
| 90 | 73 | ||
| 91 | // Add the thread to the handle table. | 74 | // Add the thread to the handle table. |
| 92 | R_TRY(process.GetHandleTable().Add(out_handle, thread)); | 75 | R_RETURN(process.GetHandleTable().Add(out_handle, thread)); |
| 93 | |||
| 94 | return ResultSuccess; | ||
| 95 | } | 76 | } |
| 96 | 77 | ||
| 97 | /// Starts the thread for the provided handle | 78 | /// Starts the thread for the provided handle |
| @@ -110,7 +91,7 @@ Result StartThread(Core::System& system, Handle thread_handle) { | |||
| 110 | thread->Open(); | 91 | thread->Open(); |
| 111 | system.Kernel().RegisterInUseObject(thread.GetPointerUnsafe()); | 92 | system.Kernel().RegisterInUseObject(thread.GetPointerUnsafe()); |
| 112 | 93 | ||
| 113 | return ResultSuccess; | 94 | R_SUCCEED(); |
| 114 | } | 95 | } |
| 115 | 96 | ||
| 116 | /// Called when a thread exits | 97 | /// Called when a thread exits |
| @@ -202,10 +183,8 @@ Result GetThreadContext3(Core::System& system, VAddr out_context, Handle thread_ | |||
| 202 | // Copy the thread context to user space. | 183 | // Copy the thread context to user space. |
| 203 | system.Memory().WriteBlock(out_context, context.data(), context.size()); | 184 | system.Memory().WriteBlock(out_context, context.data(), context.size()); |
| 204 | 185 | ||
| 205 | return ResultSuccess; | 186 | R_SUCCEED(); |
| 206 | } | 187 | } |
| 207 | |||
| 208 | return ResultSuccess; | ||
| 209 | } | 188 | } |
| 210 | 189 | ||
| 211 | /// Gets the priority for the specified thread | 190 | /// Gets the priority for the specified thread |
| @@ -219,7 +198,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle) | |||
| 219 | 198 | ||
| 220 | // Get the thread's priority. | 199 | // Get the thread's priority. |
| 221 | *out_priority = thread->GetPriority(); | 200 | *out_priority = thread->GetPriority(); |
| 222 | return ResultSuccess; | 201 | R_SUCCEED(); |
| 223 | } | 202 | } |
| 224 | 203 | ||
| 225 | /// Sets the priority for the specified thread | 204 | /// Sets the priority for the specified thread |
| @@ -238,7 +217,7 @@ Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priorit | |||
| 238 | 217 | ||
| 239 | // Set the thread priority. | 218 | // Set the thread priority. |
| 240 | thread->SetBasePriority(priority); | 219 | thread->SetBasePriority(priority); |
| 241 | return ResultSuccess; | 220 | R_SUCCEED(); |
| 242 | } | 221 | } |
| 243 | 222 | ||
| 244 | Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_thread_ids, | 223 | Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_thread_ids, |
| @@ -253,7 +232,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa | |||
| 253 | if ((out_thread_ids_size & 0xF0000000) != 0) { | 232 | if ((out_thread_ids_size & 0xF0000000) != 0) { |
| 254 | LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}", | 233 | LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}", |
| 255 | out_thread_ids_size); | 234 | out_thread_ids_size); |
| 256 | return ResultOutOfRange; | 235 | R_THROW(ResultOutOfRange); |
| 257 | } | 236 | } |
| 258 | 237 | ||
| 259 | auto* const current_process = GetCurrentProcessPointer(system.Kernel()); | 238 | auto* const current_process = GetCurrentProcessPointer(system.Kernel()); |
| @@ -263,7 +242,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa | |||
| 263 | !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) { | 242 | !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) { |
| 264 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", | 243 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", |
| 265 | out_thread_ids, out_thread_ids + total_copy_size); | 244 | out_thread_ids, out_thread_ids + total_copy_size); |
| 266 | return ResultInvalidCurrentMemory; | 245 | R_THROW(ResultInvalidCurrentMemory); |
| 267 | } | 246 | } |
| 268 | 247 | ||
| 269 | auto& memory = system.Memory(); | 248 | auto& memory = system.Memory(); |
| @@ -278,7 +257,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa | |||
| 278 | } | 257 | } |
| 279 | 258 | ||
| 280 | *out_num_threads = static_cast<u32>(num_threads); | 259 | *out_num_threads = static_cast<u32>(num_threads); |
| 281 | return ResultSuccess; | 260 | R_SUCCEED(); |
| 282 | } | 261 | } |
| 283 | 262 | ||
| 284 | Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affinity_mask, | 263 | Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affinity_mask, |
| @@ -291,9 +270,7 @@ Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affini | |||
| 291 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 270 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 292 | 271 | ||
| 293 | // Get the core mask. | 272 | // Get the core mask. |
| 294 | R_TRY(thread->GetCoreMask(out_core_id, out_affinity_mask)); | 273 | R_RETURN(thread->GetCoreMask(out_core_id, out_affinity_mask)); |
| 295 | |||
| 296 | return ResultSuccess; | ||
| 297 | } | 274 | } |
| 298 | 275 | ||
| 299 | Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id, | 276 | Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id, |
| @@ -323,9 +300,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id | |||
| 323 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); | 300 | R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); |
| 324 | 301 | ||
| 325 | // Set the core mask. | 302 | // Set the core mask. |
| 326 | R_TRY(thread->SetCoreMask(core_id, affinity_mask)); | 303 | R_RETURN(thread->SetCoreMask(core_id, affinity_mask)); |
| 327 | |||
| 328 | return ResultSuccess; | ||
| 329 | } | 304 | } |
| 330 | 305 | ||
| 331 | /// Get the ID for the specified thread. | 306 | /// Get the ID for the specified thread. |
| @@ -337,7 +312,7 @@ Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handl | |||
| 337 | 312 | ||
| 338 | // Get the thread's id. | 313 | // Get the thread's id. |
| 339 | *out_thread_id = thread->GetId(); | 314 | *out_thread_id = thread->GetId(); |
| 340 | return ResultSuccess; | 315 | R_SUCCEED(); |
| 341 | } | 316 | } |
| 342 | 317 | ||
| 343 | Result CreateThread64(Core::System& system, Handle* out_handle, uint64_t func, uint64_t arg, | 318 | Result CreateThread64(Core::System& system, Handle* out_handle, uint64_t func, uint64_t arg, |
diff --git a/src/core/hle/kernel/svc/svc_transfer_memory.cpp b/src/core/hle/kernel/svc/svc_transfer_memory.cpp index 7ffc24adf..ff4a87916 100644 --- a/src/core/hle/kernel/svc/svc_transfer_memory.cpp +++ b/src/core/hle/kernel/svc/svc_transfer_memory.cpp | |||
| @@ -67,9 +67,7 @@ Result CreateTransferMemory(Core::System& system, Handle* out, VAddr address, u6 | |||
| 67 | KTransferMemory::Register(kernel, trmem); | 67 | KTransferMemory::Register(kernel, trmem); |
| 68 | 68 | ||
| 69 | // Add the transfer memory to the handle table. | 69 | // Add the transfer memory to the handle table. |
| 70 | R_TRY(handle_table.Add(out, trmem)); | 70 | R_RETURN(handle_table.Add(out, trmem)); |
| 71 | |||
| 72 | return ResultSuccess; | ||
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size, | 73 | Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size, |