yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

kernel/svc: convert to new style

This commit is contained in:
Liam 2023-03-07 00:13:05 -05:00
parent 57f1d8ef8d
commit 91fd4e30f2
21 changed files with 192 additions and 304 deletions

View File

@ -48,24 +48,22 @@ Result KReadableEvent::Signal() {
this->NotifyAvailable(); this->NotifyAvailable();
} }
return ResultSuccess; R_SUCCEED();
} }
Result KReadableEvent::Clear() { Result KReadableEvent::Clear() {
this->Reset(); this->Reset();
return ResultSuccess; R_SUCCEED();
} }
Result KReadableEvent::Reset() { Result KReadableEvent::Reset() {
KScopedSchedulerLock lk{kernel}; KScopedSchedulerLock lk{kernel};
if (!m_is_signaled) { R_UNLESS(m_is_signaled, ResultInvalidState);
return ResultInvalidState;
}
m_is_signaled = false; m_is_signaled = false;
return ResultSuccess; R_SUCCEED();
} }
} // namespace Kernel } // namespace Kernel

View File

@ -82,7 +82,7 @@ Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) {
limit_values[index] = value; limit_values[index] = value;
peak_values[index] = current_values[index]; peak_values[index] = current_values[index];
return ResultSuccess; R_SUCCEED();
} }
bool KResourceLimit::Reserve(LimitableResource which, s64 value) { bool KResourceLimit::Reserve(LimitableResource which, s64 value) {

View File

@ -272,7 +272,7 @@ Result KServerSession::SendReply(bool is_hle) {
} }
} }
return result; R_RETURN(result);
} }
Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context, Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context,
@ -339,7 +339,7 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext
} }
// We succeeded. // We succeeded.
return ResultSuccess; R_SUCCEED();
} }
void KServerSession::CleanupRequests() { void KServerSession::CleanupRequests() {

View File

@ -43,18 +43,9 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t
address, arb_type, value, timeout_ns); address, arb_type, value, timeout_ns);
// Validate input. // Validate input.
if (IsKernelAddress(address)) { R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
LOG_ERROR(Kernel_SVC, "Attempting to wait on kernel address (address={:08X})", address); R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress);
return ResultInvalidCurrentMemory; R_UNLESS(IsValidArbitrationType(arb_type), ResultInvalidEnumValue);
}
if (!Common::IsAligned(address, sizeof(s32))) {
LOG_ERROR(Kernel_SVC, "Wait address must be 4 byte aligned (address={:08X})", address);
return ResultInvalidAddress;
}
if (!IsValidArbitrationType(arb_type)) {
LOG_ERROR(Kernel_SVC, "Invalid arbitration type specified (type={})", arb_type);
return ResultInvalidEnumValue;
}
// Convert timeout from nanoseconds to ticks. // Convert timeout from nanoseconds to ticks.
s64 timeout{}; s64 timeout{};
@ -72,7 +63,8 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t
timeout = timeout_ns; timeout = timeout_ns;
} }
return GetCurrentProcess(system.Kernel()).WaitAddressArbiter(address, arb_type, value, timeout); R_RETURN(
GetCurrentProcess(system.Kernel()).WaitAddressArbiter(address, arb_type, value, timeout));
} }
// Signals to an address (via Address Arbiter) // Signals to an address (via Address Arbiter)
@ -82,41 +74,32 @@ Result SignalToAddress(Core::System& system, VAddr address, SignalType signal_ty
address, signal_type, value, count); address, signal_type, value, count);
// Validate input. // Validate input.
if (IsKernelAddress(address)) { R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
LOG_ERROR(Kernel_SVC, "Attempting to signal to a kernel address (address={:08X})", address); R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress);
return ResultInvalidCurrentMemory; R_UNLESS(IsValidSignalType(signal_type), ResultInvalidEnumValue);
}
if (!Common::IsAligned(address, sizeof(s32))) {
LOG_ERROR(Kernel_SVC, "Signaled address must be 4 byte aligned (address={:08X})", address);
return ResultInvalidAddress;
}
if (!IsValidSignalType(signal_type)) {
LOG_ERROR(Kernel_SVC, "Invalid signal type specified (type={})", signal_type);
return ResultInvalidEnumValue;
}
return GetCurrentProcess(system.Kernel()) R_RETURN(GetCurrentProcess(system.Kernel())
.SignalAddressArbiter(address, signal_type, value, count); .SignalAddressArbiter(address, signal_type, value, count));
} }
Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value, Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value,
s64 timeout_ns) { s64 timeout_ns) {
return WaitForAddress(system, address, arb_type, value, timeout_ns); R_RETURN(WaitForAddress(system, address, arb_type, value, timeout_ns));
} }
Result SignalToAddress64(Core::System& system, VAddr address, SignalType signal_type, s32 value, Result SignalToAddress64(Core::System& system, VAddr address, SignalType signal_type, s32 value,
s32 count) { s32 count) {
return SignalToAddress(system, address, signal_type, value, count); R_RETURN(SignalToAddress(system, address, signal_type, value, count));
} }
Result WaitForAddress64From32(Core::System& system, u32 address, ArbitrationType arb_type, Result WaitForAddress64From32(Core::System& system, u32 address, ArbitrationType arb_type,
s32 value, s64 timeout_ns) { s32 value, s64 timeout_ns) {
return WaitForAddress(system, address, arb_type, value, timeout_ns); R_RETURN(WaitForAddress(system, address, arb_type, value, timeout_ns));
} }
Result SignalToAddress64From32(Core::System& system, u32 address, SignalType signal_type, s32 value, Result SignalToAddress64From32(Core::System& system, u32 address, SignalType signal_type, s32 value,
s32 count) { s32 count) {
return SignalToAddress(system, address, signal_type, value, count); R_RETURN(SignalToAddress(system, address, signal_type, value, count));
} }
} // namespace Kernel::Svc } // namespace Kernel::Svc

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/scope_exit.h"
#include "core/core.h" #include "core/core.h"
#include "core/hle/kernel/k_code_memory.h" #include "core/hle/kernel/k_code_memory.h"
#include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_process.h"
@ -44,6 +45,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, uint64
KCodeMemory* code_mem = KCodeMemory::Create(kernel); KCodeMemory* code_mem = KCodeMemory::Create(kernel);
R_UNLESS(code_mem != nullptr, ResultOutOfResource); R_UNLESS(code_mem != nullptr, ResultOutOfResource);
SCOPE_EXIT({ code_mem->Close(); });
// Verify that the region is in range. // Verify that the region is in range.
R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size), R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size),
@ -58,9 +60,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, uint64
// Add the code memory to the handle table. // Add the code memory to the handle table.
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem)); R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem));
code_mem->Close(); R_SUCCEED();
return ResultSuccess;
} }
Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
@ -140,10 +140,10 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
R_TRY(code_mem->UnmapFromOwner(address, size)); R_TRY(code_mem->UnmapFromOwner(address, size));
} break; } break;
default: default:
return ResultInvalidEnumValue; R_THROW(ResultInvalidEnumValue);
} }
return ResultSuccess; R_SUCCEED();
} }
Result CreateCodeMemory64(Core::System& system, Handle* out_handle, uint64_t address, Result CreateCodeMemory64(Core::System& system, Handle* out_handle, uint64_t address,

View File

@ -17,14 +17,8 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke
cv_key, tag, timeout_ns); cv_key, tag, timeout_ns);
// Validate input. // Validate input.
if (IsKernelAddress(address)) { R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
LOG_ERROR(Kernel_SVC, "Attempted to wait on kernel address (address={:08X})", address); R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress);
return ResultInvalidCurrentMemory;
}
if (!Common::IsAligned(address, sizeof(s32))) {
LOG_ERROR(Kernel_SVC, "Address must be 4 byte aligned (address={:08X})", address);
return ResultInvalidAddress;
}
// Convert timeout from nanoseconds to ticks. // Convert timeout from nanoseconds to ticks.
s64 timeout{}; s64 timeout{};
@ -43,8 +37,9 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke
} }
// Wait on the condition variable. // Wait on the condition variable.
return GetCurrentProcess(system.Kernel()) R_RETURN(
.WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); GetCurrentProcess(system.Kernel())
.WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout));
} }
/// Signal process wide key /// Signal process wide key

View File

@ -21,7 +21,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
R_UNLESS(event.IsNotNull(), ResultInvalidHandle); R_UNLESS(event.IsNotNull(), ResultInvalidHandle);
return event->Signal(); R_RETURN(event->Signal());
} }
Result ClearEvent(Core::System& system, Handle event_handle) { Result ClearEvent(Core::System& system, Handle event_handle) {
@ -34,7 +34,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
{ {
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
if (event.IsNotNull()) { if (event.IsNotNull()) {
return event->Clear(); R_RETURN(event->Clear());
} }
} }
@ -42,13 +42,11 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
{ {
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(event_handle); KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(event_handle);
if (readable_event.IsNotNull()) { if (readable_event.IsNotNull()) {
return readable_event->Clear(); R_RETURN(readable_event->Clear());
} }
} }
LOG_ERROR(Kernel_SVC, "Event handle does not exist, event_handle=0x{:08X}", event_handle); R_THROW(ResultInvalidHandle);
return ResultInvalidHandle;
} }
Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { 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) {
R_TRY(handle_table.Add(out_write, event)); R_TRY(handle_table.Add(out_write, event));
// Ensure that we maintain a clean handle state on exit. // Ensure that we maintain a clean handle state on exit.
auto handle_guard = SCOPE_GUARD({ handle_table.Remove(*out_write); }); ON_RESULT_FAILURE {
handle_table.Remove(*out_write);
};
// Add the readable event to the handle table. // Add the readable event to the handle table.
R_TRY(handle_table.Add(out_read, std::addressof(event->GetReadableEvent()))); R_RETURN(handle_table.Add(out_read, std::addressof(event->GetReadableEvent())));
// We succeeded.
handle_guard.Cancel();
return ResultSuccess;
} }
Result SignalEvent64(Core::System& system, Handle event_handle) { Result SignalEvent64(Core::System& system, Handle event_handle) {

View File

@ -38,126 +38,110 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
case InfoType::UsedNonSystemMemorySize: case InfoType::UsedNonSystemMemorySize:
case InfoType::IsApplication: case InfoType::IsApplication:
case InfoType::FreeThreadCount: { case InfoType::FreeThreadCount: {
if (info_sub_id != 0) { R_UNLESS(info_sub_id == 0, ResultInvalidEnumValue);
LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,
info_sub_id);
return ResultInvalidEnumValue;
}
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
if (process.IsNull()) { R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}",
info_id, info_sub_id, handle);
return ResultInvalidHandle;
}
switch (info_id_type) { switch (info_id_type) {
case InfoType::CoreMask: case InfoType::CoreMask:
*result = process->GetCoreMask(); *result = process->GetCoreMask();
return ResultSuccess; R_SUCCEED();
case InfoType::PriorityMask: case InfoType::PriorityMask:
*result = process->GetPriorityMask(); *result = process->GetPriorityMask();
return ResultSuccess; R_SUCCEED();
case InfoType::AliasRegionAddress: case InfoType::AliasRegionAddress:
*result = process->PageTable().GetAliasRegionStart(); *result = process->PageTable().GetAliasRegionStart();
return ResultSuccess; R_SUCCEED();
case InfoType::AliasRegionSize: case InfoType::AliasRegionSize:
*result = process->PageTable().GetAliasRegionSize(); *result = process->PageTable().GetAliasRegionSize();
return ResultSuccess; R_SUCCEED();
case InfoType::HeapRegionAddress: case InfoType::HeapRegionAddress:
*result = process->PageTable().GetHeapRegionStart(); *result = process->PageTable().GetHeapRegionStart();
return ResultSuccess; R_SUCCEED();
case InfoType::HeapRegionSize: case InfoType::HeapRegionSize:
*result = process->PageTable().GetHeapRegionSize(); *result = process->PageTable().GetHeapRegionSize();
return ResultSuccess; R_SUCCEED();
case InfoType::AslrRegionAddress: case InfoType::AslrRegionAddress:
*result = process->PageTable().GetAliasCodeRegionStart(); *result = process->PageTable().GetAliasCodeRegionStart();
return ResultSuccess; R_SUCCEED();
case InfoType::AslrRegionSize: case InfoType::AslrRegionSize:
*result = process->PageTable().GetAliasCodeRegionSize(); *result = process->PageTable().GetAliasCodeRegionSize();
return ResultSuccess; R_SUCCEED();
case InfoType::StackRegionAddress: case InfoType::StackRegionAddress:
*result = process->PageTable().GetStackRegionStart(); *result = process->PageTable().GetStackRegionStart();
return ResultSuccess; R_SUCCEED();
case InfoType::StackRegionSize: case InfoType::StackRegionSize:
*result = process->PageTable().GetStackRegionSize(); *result = process->PageTable().GetStackRegionSize();
return ResultSuccess; R_SUCCEED();
case InfoType::TotalMemorySize: case InfoType::TotalMemorySize:
*result = process->GetTotalPhysicalMemoryAvailable(); *result = process->GetTotalPhysicalMemoryAvailable();
return ResultSuccess; R_SUCCEED();
case InfoType::UsedMemorySize: case InfoType::UsedMemorySize:
*result = process->GetTotalPhysicalMemoryUsed(); *result = process->GetTotalPhysicalMemoryUsed();
return ResultSuccess; R_SUCCEED();
case InfoType::SystemResourceSizeTotal: case InfoType::SystemResourceSizeTotal:
*result = process->GetSystemResourceSize(); *result = process->GetSystemResourceSize();
return ResultSuccess; R_SUCCEED();
case InfoType::SystemResourceSizeUsed: case InfoType::SystemResourceSizeUsed:
LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage"); LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage");
*result = process->GetSystemResourceUsage(); *result = process->GetSystemResourceUsage();
return ResultSuccess; R_SUCCEED();
case InfoType::ProgramId: case InfoType::ProgramId:
*result = process->GetProgramID(); *result = process->GetProgramID();
return ResultSuccess; R_SUCCEED();
case InfoType::UserExceptionContextAddress: case InfoType::UserExceptionContextAddress:
*result = process->GetProcessLocalRegionAddress(); *result = process->GetProcessLocalRegionAddress();
return ResultSuccess; R_SUCCEED();
case InfoType::TotalNonSystemMemorySize: case InfoType::TotalNonSystemMemorySize:
*result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource(); *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource();
return ResultSuccess; R_SUCCEED();
case InfoType::UsedNonSystemMemorySize: case InfoType::UsedNonSystemMemorySize:
*result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource();
return ResultSuccess; R_SUCCEED();
case InfoType::IsApplication: case InfoType::IsApplication:
LOG_WARNING(Kernel_SVC, "(STUBBED) Assuming process is application"); LOG_WARNING(Kernel_SVC, "(STUBBED) Assuming process is application");
*result = true; *result = true;
return ResultSuccess; R_SUCCEED();
case InfoType::FreeThreadCount: case InfoType::FreeThreadCount:
*result = process->GetFreeThreadCount(); *result = process->GetFreeThreadCount();
return ResultSuccess; R_SUCCEED();
default: default:
break; break;
} }
LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
return ResultInvalidEnumValue; R_THROW(ResultInvalidEnumValue);
} }
case InfoType::DebuggerAttached: case InfoType::DebuggerAttached:
*result = 0; *result = 0;
return ResultSuccess; R_SUCCEED();
case InfoType::ResourceLimit: { case InfoType::ResourceLimit: {
if (handle != 0) { R_UNLESS(handle == 0, ResultInvalidHandle);
LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); R_UNLESS(info_sub_id == 0, ResultInvalidCombination);
return ResultInvalidHandle;
}
if (info_sub_id != 0) {
LOG_ERROR(Kernel, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,
info_sub_id);
return ResultInvalidCombination;
}
KProcess* const current_process = GetCurrentProcessPointer(system.Kernel()); KProcess* const current_process = GetCurrentProcessPointer(system.Kernel());
KHandleTable& handle_table = current_process->GetHandleTable(); KHandleTable& handle_table = current_process->GetHandleTable();
@ -165,44 +149,35 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
if (!resource_limit) { if (!resource_limit) {
*result = Svc::InvalidHandle; *result = Svc::InvalidHandle;
// Yes, the kernel considers this a successful operation. // Yes, the kernel considers this a successful operation.
return ResultSuccess; R_SUCCEED();
} }
Handle resource_handle{}; Handle resource_handle{};
R_TRY(handle_table.Add(&resource_handle, resource_limit)); R_TRY(handle_table.Add(&resource_handle, resource_limit));
*result = resource_handle; *result = resource_handle;
return ResultSuccess; R_SUCCEED();
} }
case InfoType::RandomEntropy: case InfoType::RandomEntropy:
if (handle != 0) { R_UNLESS(handle == 0, ResultInvalidHandle);
LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", R_UNLESS(info_sub_id < KProcess::RANDOM_ENTROPY_SIZE, ResultInvalidCombination);
handle);
return ResultInvalidHandle;
}
if (info_sub_id >= KProcess::RANDOM_ENTROPY_SIZE) {
LOG_ERROR(Kernel_SVC, "Entropy size is out of range, expected {} but got {}",
KProcess::RANDOM_ENTROPY_SIZE, info_sub_id);
return ResultInvalidCombination;
}
*result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id); *result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id);
return ResultSuccess; R_SUCCEED();
case InfoType::InitialProcessIdRange: case InfoType::InitialProcessIdRange:
LOG_WARNING(Kernel_SVC, LOG_WARNING(Kernel_SVC,
"(STUBBED) Attempted to query privileged process id bounds, returned 0"); "(STUBBED) Attempted to query privileged process id bounds, returned 0");
*result = 0; *result = 0;
return ResultSuccess; R_SUCCEED();
case InfoType::ThreadTickCount: { case InfoType::ThreadTickCount: {
constexpr u64 num_cpus = 4; constexpr u64 num_cpus = 4;
if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) {
LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus,
info_sub_id); info_sub_id);
return ResultInvalidCombination; R_THROW(ResultInvalidCombination);
} }
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()) KScopedAutoObject thread = GetCurrentProcess(system.Kernel())
@ -211,7 +186,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
if (thread.IsNull()) { if (thread.IsNull()) {
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}",
static_cast<Handle>(handle)); static_cast<Handle>(handle));
return ResultInvalidHandle; R_THROW(ResultInvalidHandle);
} }
const auto& core_timing = system.CoreTiming(); const auto& core_timing = system.CoreTiming();
@ -230,7 +205,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
} }
*result = out_ticks; *result = out_ticks;
return ResultSuccess; R_SUCCEED();
} }
case InfoType::IdleTickCount: { case InfoType::IdleTickCount: {
// Verify the input handle is invalid. // Verify the input handle is invalid.
@ -244,7 +219,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
// Get the idle tick count. // Get the idle tick count.
*result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime(); *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime();
return ResultSuccess; R_SUCCEED();
} }
case InfoType::MesosphereCurrentProcess: { case InfoType::MesosphereCurrentProcess: {
// Verify the input handle is invalid. // Verify the input handle is invalid.
@ -265,11 +240,11 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
*result = tmp; *result = tmp;
// We succeeded. // We succeeded.
return ResultSuccess; R_SUCCEED();
} }
default: default:
LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
return ResultInvalidEnumValue; R_THROW(ResultInvalidEnumValue);
} }
} }

View File

@ -19,7 +19,7 @@ Result SendSyncRequest(Core::System& system, Handle handle) {
LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName());
return session->SendSyncRequest(); R_RETURN(session->SendSyncRequest());
} }
Result SendSyncRequestWithUserBuffer(Core::System& system, uint64_t message_buffer, 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
Result result = KSynchronizationObject::Wait(kernel, &index, objs.data(), Result result = KSynchronizationObject::Wait(kernel, &index, objs.data(),
static_cast<s32>(objs.size()), timeout_ns); static_cast<s32>(objs.size()), timeout_ns);
if (result == ResultTimedOut) { if (result == ResultTimedOut) {
return result; R_RETURN(result);
} }
// Receive the request. // Receive the request.
@ -97,7 +97,7 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad
} }
*out_index = index; *out_index = index;
return result; R_RETURN(result);
} }
} }

View File

@ -14,17 +14,10 @@ Result ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address,
thread_handle, address, tag); thread_handle, address, tag);
// Validate the input address. // Validate the input address.
if (IsKernelAddress(address)) { R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
LOG_ERROR(Kernel_SVC, "Attempting to arbitrate a lock on a kernel address (address={:08X})", R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress);
address);
return ResultInvalidCurrentMemory;
}
if (!Common::IsAligned(address, sizeof(u32))) {
LOG_ERROR(Kernel_SVC, "Input address must be 4 byte aligned (address: {:08X})", address);
return ResultInvalidAddress;
}
return GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag); R_RETURN(GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag));
} }
/// Unlock a mutex /// Unlock a mutex
@ -32,18 +25,10 @@ Result ArbitrateUnlock(Core::System& system, VAddr address) {
LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address);
// Validate the input address. // Validate the input address.
if (IsKernelAddress(address)) { R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
LOG_ERROR(Kernel_SVC, R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress);
"Attempting to arbitrate an unlock on a kernel address (address={:08X})",
address);
return ResultInvalidCurrentMemory;
}
if (!Common::IsAligned(address, sizeof(u32))) {
LOG_ERROR(Kernel_SVC, "Input address must be 4 byte aligned (address: {:08X})", address);
return ResultInvalidAddress;
}
return GetCurrentProcess(system.Kernel()).SignalToAddress(address); R_RETURN(GetCurrentProcess(system.Kernel()).SignalToAddress(address));
} }
Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) { Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) {

View File

@ -33,49 +33,49 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd
u64 size) { u64 size) {
if (!Common::Is4KBAligned(dst_addr)) { if (!Common::Is4KBAligned(dst_addr)) {
LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (!Common::Is4KBAligned(src_addr)) { if (!Common::Is4KBAligned(src_addr)) {
LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr);
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (size == 0) { if (size == 0) {
LOG_ERROR(Kernel_SVC, "Size is 0"); LOG_ERROR(Kernel_SVC, "Size is 0");
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (!Common::Is4KBAligned(size)) { if (!Common::Is4KBAligned(size)) {
LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size);
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (!IsValidAddressRange(dst_addr, size)) { if (!IsValidAddressRange(dst_addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}", "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}",
dst_addr, size); dst_addr, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (!IsValidAddressRange(src_addr, size)) { if (!IsValidAddressRange(src_addr, size)) {
LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}", LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}",
src_addr, size); src_addr, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (!manager.IsInsideAddressSpace(src_addr, size)) { if (!manager.IsInsideAddressSpace(src_addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}",
src_addr, size); src_addr, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (manager.IsOutsideStackRegion(dst_addr, size)) { if (manager.IsOutsideStackRegion(dst_addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}", "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}",
dst_addr, size); dst_addr, size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
if (manager.IsInsideHeapRegion(dst_addr, size)) { if (manager.IsInsideHeapRegion(dst_addr, size)) {
@ -83,7 +83,7 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd
"Destination does not fit within the heap region, addr=0x{:016X}, " "Destination does not fit within the heap region, addr=0x{:016X}, "
"size=0x{:016X}", "size=0x{:016X}",
dst_addr, size); dst_addr, size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
if (manager.IsInsideAliasRegion(dst_addr, size)) { if (manager.IsInsideAliasRegion(dst_addr, size)) {
@ -91,10 +91,10 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd
"Destination does not fit within the map region, addr=0x{:016X}, " "Destination does not fit within the map region, addr=0x{:016X}, "
"size=0x{:016X}", "size=0x{:016X}",
dst_addr, size); dst_addr, size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
return ResultSuccess; R_SUCCEED();
} }
} // namespace } // namespace
@ -117,7 +117,7 @@ Result SetMemoryPermission(Core::System& system, VAddr address, u64 size, Memory
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// Set the memory attribute. // Set the memory attribute.
return page_table.SetMemoryPermission(address, size, perm); R_RETURN(page_table.SetMemoryPermission(address, size, perm));
} }
Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mask, u32 attr) { 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
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// Set the memory attribute. // Set the memory attribute.
return page_table.SetMemoryAttribute(address, size, mask, attr); R_RETURN(page_table.SetMemoryAttribute(address, size, mask, attr));
} }
/// Maps a memory range into a different range. /// 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)
return result; return result;
} }
return page_table.MapMemory(dst_addr, src_addr, size); R_RETURN(page_table.MapMemory(dst_addr, src_addr, size));
} }
/// Unmaps a region that was previously mapped with svcMapMemory /// 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
return result; return result;
} }
return page_table.UnmapMemory(dst_addr, src_addr, size); R_RETURN(page_table.UnmapMemory(dst_addr, src_addr, size));
} }
Result SetMemoryPermission64(Core::System& system, uint64_t address, uint64_t size, Result SetMemoryPermission64(Core::System& system, uint64_t address, uint64_t size,

View File

@ -16,9 +16,7 @@ Result SetHeapSize(Core::System& system, VAddr* out_address, u64 size) {
R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize); R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize);
// Set the heap size. // Set the heap size.
R_TRY(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size)); R_RETURN(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size));
return ResultSuccess;
} }
/// Maps memory at a desired address /// Maps memory at a desired address
@ -27,22 +25,22 @@ Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
if (!Common::Is4KBAligned(addr)) { if (!Common::Is4KBAligned(addr)) {
LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (!Common::Is4KBAligned(size)) { if (!Common::Is4KBAligned(size)) {
LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size);
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (size == 0) { if (size == 0) {
LOG_ERROR(Kernel_SVC, "Size is zero"); LOG_ERROR(Kernel_SVC, "Size is zero");
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (!(addr < addr + size)) { if (!(addr < addr + size)) {
LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address");
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())};
@ -50,24 +48,24 @@ Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
if (current_process->GetSystemResourceSize() == 0) { if (current_process->GetSystemResourceSize() == 0) {
LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); LOG_ERROR(Kernel_SVC, "System Resource Size is zero");
return ResultInvalidState; R_THROW(ResultInvalidState);
} }
if (!page_table.IsInsideAddressSpace(addr, size)) { if (!page_table.IsInsideAddressSpace(addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,
size); size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
if (page_table.IsOutsideAliasRegion(addr, size)) { if (page_table.IsOutsideAliasRegion(addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr,
size); size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
return page_table.MapPhysicalMemory(addr, size); R_RETURN(page_table.MapPhysicalMemory(addr, size));
} }
/// Unmaps memory previously mapped via MapPhysicalMemory /// Unmaps memory previously mapped via MapPhysicalMemory
@ -76,22 +74,22 @@ Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
if (!Common::Is4KBAligned(addr)) { if (!Common::Is4KBAligned(addr)) {
LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (!Common::Is4KBAligned(size)) { if (!Common::Is4KBAligned(size)) {
LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size);
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (size == 0) { if (size == 0) {
LOG_ERROR(Kernel_SVC, "Size is zero"); LOG_ERROR(Kernel_SVC, "Size is zero");
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (!(addr < addr + size)) { if (!(addr < addr + size)) {
LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address");
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())};
@ -99,24 +97,24 @@ Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
if (current_process->GetSystemResourceSize() == 0) { if (current_process->GetSystemResourceSize() == 0) {
LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); LOG_ERROR(Kernel_SVC, "System Resource Size is zero");
return ResultInvalidState; R_THROW(ResultInvalidState);
} }
if (!page_table.IsInsideAddressSpace(addr, size)) { if (!page_table.IsInsideAddressSpace(addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,
size); size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
if (page_table.IsOutsideAliasRegion(addr, size)) { if (page_table.IsOutsideAliasRegion(addr, size)) {
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr,
size); size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
return page_table.UnmapPhysicalMemory(addr, size); R_RETURN(page_table.UnmapPhysicalMemory(addr, size));
} }
Result MapPhysicalMemoryUnsafe(Core::System& system, uint64_t address, uint64_t size) { Result MapPhysicalMemoryUnsafe(Core::System& system, uint64_t address, uint64_t size) {

View File

@ -47,7 +47,7 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) {
// Get the process id. // Get the process id.
*out_process_id = process->GetId(); *out_process_id = process->GetId();
return ResultSuccess; R_SUCCEED();
} }
Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_process_ids, 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
LOG_ERROR(Kernel_SVC, LOG_ERROR(Kernel_SVC,
"Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}", "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}",
out_process_ids_size); out_process_ids_size);
return ResultOutOfRange; R_THROW(ResultOutOfRange);
} }
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
@ -70,7 +70,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr
out_process_ids, total_copy_size)) { out_process_ids, total_copy_size)) {
LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
out_process_ids, out_process_ids + total_copy_size); out_process_ids, out_process_ids + total_copy_size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
auto& memory = system.Memory(); auto& memory = system.Memory();
@ -85,7 +85,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr
} }
*out_num_processes = static_cast<u32>(num_processes); *out_num_processes = static_cast<u32>(num_processes);
return ResultSuccess; R_SUCCEED();
} }
Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle, Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle,
@ -97,17 +97,17 @@ Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle,
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle); process_handle);
return ResultInvalidHandle; R_THROW(ResultInvalidHandle);
} }
if (info_type != ProcessInfoType::ProcessState) { if (info_type != ProcessInfoType::ProcessState) {
LOG_ERROR(Kernel_SVC, "Expected info_type to be ProcessState but got {} instead", LOG_ERROR(Kernel_SVC, "Expected info_type to be ProcessState but got {} instead",
info_type); info_type);
return ResultInvalidEnumValue; R_THROW(ResultInvalidEnumValue);
} }
*out = static_cast<s64>(process->GetState()); *out = static_cast<s64>(process->GetState());
return ResultSuccess; R_SUCCEED();
} }
Result CreateProcess(Core::System& system, Handle* out_handle, uint64_t parameters, uint64_t caps, Result CreateProcess(Core::System& system, Handle* out_handle, uint64_t parameters, uint64_t caps,

View File

@ -53,7 +53,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, V
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// Set the memory permission. // Set the memory permission.
return page_table.SetProcessMemoryPermission(address, size, perm); R_RETURN(page_table.SetProcessMemoryPermission(address, size, perm));
} }
Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, 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_
KMemoryAttribute::All, KMemoryAttribute::None)); KMemoryAttribute::All, KMemoryAttribute::None));
// Map the group. // Map the group.
R_TRY(dst_pt.MapPageGroup(dst_address, pg, KMemoryState::SharedCode, R_RETURN(dst_pt.MapPageGroup(dst_address, pg, KMemoryState::SharedCode,
KMemoryPermission::UserReadWrite)); KMemoryPermission::UserReadWrite));
return ResultSuccess;
} }
Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, 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
ResultInvalidMemoryRegion); ResultInvalidMemoryRegion);
// Unmap the memory. // Unmap the memory.
R_TRY(dst_pt.UnmapProcessMemory(dst_address, size, src_pt, src_address)); R_RETURN(dst_pt.UnmapProcessMemory(dst_address, size, src_pt, src_address));
return ResultSuccess;
} }
Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, 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
if (!Common::Is4KBAligned(src_address)) { if (!Common::Is4KBAligned(src_address)) {
LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).",
src_address); src_address);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (!Common::Is4KBAligned(dst_address)) { if (!Common::Is4KBAligned(dst_address)) {
LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).",
dst_address); dst_address);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (size == 0 || !Common::Is4KBAligned(size)) { if (size == 0 || !Common::Is4KBAligned(size)) {
LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size);
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (!IsValidAddressRange(dst_address, size)) { if (!IsValidAddressRange(dst_address, size)) {
@ -163,7 +159,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
"Destination address range overflows the address space (dst_address=0x{:016X}, " "Destination address range overflows the address space (dst_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
dst_address, size); dst_address, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (!IsValidAddressRange(src_address, size)) { if (!IsValidAddressRange(src_address, size)) {
@ -171,7 +167,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
"Source address range overflows the address space (src_address=0x{:016X}, " "Source address range overflows the address space (src_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
src_address, size); src_address, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
@ -179,7 +175,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle); process_handle);
return ResultInvalidHandle; R_THROW(ResultInvalidHandle);
} }
auto& page_table = process->PageTable(); auto& page_table = process->PageTable();
@ -188,7 +184,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
"Source address range is not within the address space (src_address=0x{:016X}, " "Source address range is not within the address space (src_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
src_address, size); src_address, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (!page_table.IsInsideASLRRegion(dst_address, size)) { if (!page_table.IsInsideASLRRegion(dst_address, size)) {
@ -196,10 +192,10 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
"Destination address range is not within the ASLR region (dst_address=0x{:016X}, " "Destination address range is not within the ASLR region (dst_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
dst_address, size); dst_address, size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
return page_table.MapCodeMemory(dst_address, src_address, size); R_RETURN(page_table.MapCodeMemory(dst_address, src_address, size));
} }
Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, 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
if (!Common::Is4KBAligned(dst_address)) { if (!Common::Is4KBAligned(dst_address)) {
LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).",
dst_address); dst_address);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (!Common::Is4KBAligned(src_address)) { if (!Common::Is4KBAligned(src_address)) {
LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).",
src_address); src_address);
return ResultInvalidAddress; R_THROW(ResultInvalidAddress);
} }
if (size == 0 || !Common::Is4KBAligned(size)) { if (size == 0 || !Common::Is4KBAligned(size)) {
LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size);
return ResultInvalidSize; R_THROW(ResultInvalidSize);
} }
if (!IsValidAddressRange(dst_address, size)) { if (!IsValidAddressRange(dst_address, size)) {
@ -231,7 +227,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
"Destination address range overflows the address space (dst_address=0x{:016X}, " "Destination address range overflows the address space (dst_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
dst_address, size); dst_address, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (!IsValidAddressRange(src_address, size)) { if (!IsValidAddressRange(src_address, size)) {
@ -239,7 +235,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
"Source address range overflows the address space (src_address=0x{:016X}, " "Source address range overflows the address space (src_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
src_address, size); src_address, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
@ -247,7 +243,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle); process_handle);
return ResultInvalidHandle; R_THROW(ResultInvalidHandle);
} }
auto& page_table = process->PageTable(); auto& page_table = process->PageTable();
@ -256,7 +252,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
"Source address range is not within the address space (src_address=0x{:016X}, " "Source address range is not within the address space (src_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
src_address, size); src_address, size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
if (!page_table.IsInsideASLRRegion(dst_address, size)) { if (!page_table.IsInsideASLRRegion(dst_address, size)) {
@ -264,11 +260,11 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
"Destination address range is not within the ASLR region (dst_address=0x{:016X}, " "Destination address range is not within the ASLR region (dst_address=0x{:016X}, "
"size=0x{:016X}).", "size=0x{:016X}).",
dst_address, size); dst_address, size);
return ResultInvalidMemoryRegion; R_THROW(ResultInvalidMemoryRegion);
} }
return page_table.UnmapCodeMemory(dst_address, src_address, size, R_RETURN(page_table.UnmapCodeMemory(dst_address, src_address, size,
KPageTable::ICacheInvalidationStrategy::InvalidateAll); KPageTable::ICacheInvalidationStrategy::InvalidateAll));
} }
Result SetProcessMemoryPermission64(Core::System& system, Handle process_handle, uint64_t address, Result SetProcessMemoryPermission64(Core::System& system, Handle process_handle, uint64_t address,

View File

@ -15,8 +15,8 @@ Result QueryMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out
out_memory_info, query_address); out_memory_info, query_address);
// Query memory is just QueryProcessMemory on the current process. // Query memory is just QueryProcessMemory on the current process.
return QueryProcessMemory(system, out_memory_info, out_page_info, CurrentProcess, R_RETURN(
query_address); QueryProcessMemory(system, out_memory_info, out_page_info, CurrentProcess, query_address));
} }
Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info, 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
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle); process_handle);
return ResultInvalidHandle; R_THROW(ResultInvalidHandle);
} }
auto& memory{system.Memory()}; auto& memory{system.Memory()};

View File

@ -27,9 +27,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
KResourceLimit::Register(kernel, resource_limit); KResourceLimit::Register(kernel, resource_limit);
// Add the limit to the handle table. // Add the limit to the handle table.
R_TRY(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit)); R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit));
return ResultSuccess;
} }
Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value, Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
@ -49,7 +47,7 @@ Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
// Get the limit value. // Get the limit value.
*out_limit_value = resource_limit->GetLimitValue(which); *out_limit_value = resource_limit->GetLimitValue(which);
return ResultSuccess; R_SUCCEED();
} }
Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value, Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value,
@ -69,7 +67,7 @@ Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value
// Get the current value. // Get the current value.
*out_current_value = resource_limit->GetCurrentValue(which); *out_current_value = resource_limit->GetCurrentValue(which);
return ResultSuccess; R_SUCCEED();
} }
Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_handle, Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_handle,
@ -87,9 +85,7 @@ Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_ha
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Set the limit value. // Set the limit value.
R_TRY(resource_limit->SetLimitValue(which, limit_value)); R_RETURN(resource_limit->SetLimitValue(which, limit_value));
return ResultSuccess;
} }
Result GetResourceLimitPeakValue(Core::System& system, int64_t* out_peak_value, Result GetResourceLimitPeakValue(Core::System& system, int64_t* out_peak_value,

View File

@ -25,7 +25,7 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
if (session_reservation.Succeeded()) { if (session_reservation.Succeeded()) {
session = T::Create(system.Kernel()); session = T::Create(system.Kernel());
} else { } else {
return ResultLimitReached; R_THROW(ResultLimitReached);
// // We couldn't reserve a session. Check that we support dynamically expanding the // // We couldn't reserve a session. Check that we support dynamically expanding the
// // resource limit. // // resource limit.
@ -77,15 +77,13 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
// Add the server session to the handle table. // Add the server session to the handle table.
R_TRY(handle_table.Add(out_server, &session->GetServerSession())); R_TRY(handle_table.Add(out_server, &session->GetServerSession()));
// Add the client session to the handle table.
const auto result = handle_table.Add(out_client, &session->GetClientSession());
if (!R_SUCCEEDED(result)) {
// Ensure that we maintain a clean handle state on exit. // Ensure that we maintain a clean handle state on exit.
ON_RESULT_FAILURE {
handle_table.Remove(*out_server); handle_table.Remove(*out_server);
} };
return result; // Add the client session to the handle table.
R_RETURN(handle_table.Add(out_client, &session->GetClientSession()));
} }
} // namespace } // namespace
@ -94,9 +92,9 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
u64 name) { u64 name) {
if (is_light) { if (is_light) {
// return CreateSession<KLightSession>(system, out_server, out_client, name); // return CreateSession<KLightSession>(system, out_server, out_client, name);
return ResultNotImplemented; R_THROW(ResultNotImplemented);
} else { } else {
return CreateSession<KSession>(system, out_server, out_client, name); R_RETURN(CreateSession<KSession>(system, out_server, out_client, name));
} }
} }

View File

@ -56,15 +56,12 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address,
R_TRY(process.AddSharedMemory(shmem.GetPointerUnsafe(), address, size)); R_TRY(process.AddSharedMemory(shmem.GetPointerUnsafe(), address, size));
// Ensure that we clean up the shared memory if we fail to map it. // Ensure that we clean up the shared memory if we fail to map it.
auto guard = ON_RESULT_FAILURE {
SCOPE_GUARD({ process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); }); process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size);
};
// Map the shared memory. // Map the shared memory.
R_TRY(shmem->Map(process, address, size, map_perm)); R_RETURN(shmem->Map(process, address, size, map_perm));
// We succeeded.
guard.Cancel();
return ResultSuccess;
} }
Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, u64 size) { 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
// Remove the shared memory from the process. // Remove the shared memory from the process.
process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size);
return ResultSuccess; R_SUCCEED();
} }
Result CreateSharedMemory(Core::System& system, Handle* out_handle, uint64_t size, Result CreateSharedMemory(Core::System& system, Handle* out_handle, uint64_t size,

View File

@ -17,7 +17,7 @@ Result CloseHandle(Core::System& system, Handle handle) {
R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle), R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle),
ResultInvalidHandle); ResultInvalidHandle);
return ResultSuccess; R_SUCCEED();
} }
/// Clears the signaled state of an event or process. /// Clears the signaled state of an event or process.
@ -31,7 +31,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
{ {
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(handle); KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(handle);
if (readable_event.IsNotNull()) { if (readable_event.IsNotNull()) {
return readable_event->Reset(); R_RETURN(readable_event->Reset());
} }
} }
@ -39,13 +39,11 @@ Result ResetSignal(Core::System& system, Handle handle) {
{ {
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
if (process.IsNotNull()) { if (process.IsNotNull()) {
return process->Reset(); R_RETURN(process->Reset());
} }
} }
LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle); R_THROW(ResultInvalidHandle);
return ResultInvalidHandle;
} }
static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles, static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles,
@ -109,7 +107,7 @@ Result CancelSynchronization(Core::System& system, Handle handle) {
// Cancel the thread's wait. // Cancel the thread's wait.
thread->WaitCancel(); thread->WaitCancel();
return ResultSuccess; R_SUCCEED();
} }
void SynchronizePreemptionState(Core::System& system) { void SynchronizePreemptionState(Core::System& system) {

View File

@ -34,39 +34,22 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
} }
// Validate arguments. // Validate arguments.
if (!IsValidVirtualCoreId(core_id)) { R_UNLESS(IsValidVirtualCoreId(core_id), ResultInvalidCoreId);
LOG_ERROR(Kernel_SVC, "Invalid Core ID specified (id={})", core_id); R_UNLESS(((1ull << core_id) & process.GetCoreMask()) != 0, ResultInvalidCoreId);
return ResultInvalidCoreId;
}
if (((1ULL << core_id) & process.GetCoreMask()) == 0) {
LOG_ERROR(Kernel_SVC, "Core ID doesn't fall within allowable cores (id={})", core_id);
return ResultInvalidCoreId;
}
if (HighestThreadPriority > priority || priority > LowestThreadPriority) { R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority,
LOG_ERROR(Kernel_SVC, "Invalid priority specified (priority={})", priority); ResultInvalidPriority);
return ResultInvalidPriority; R_UNLESS(process.CheckThreadPriority(priority), ResultInvalidPriority);
}
if (!process.CheckThreadPriority(priority)) {
LOG_ERROR(Kernel_SVC, "Invalid allowable thread priority (priority={})", priority);
return ResultInvalidPriority;
}
// Reserve a new thread from the process resource limit (waiting up to 100ms). // Reserve a new thread from the process resource limit (waiting up to 100ms).
KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1, KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1,
system.CoreTiming().GetGlobalTimeNs().count() + system.CoreTiming().GetGlobalTimeNs().count() +
100000000); 100000000);
if (!thread_reservation.Succeeded()) { R_UNLESS(thread_reservation.Succeeded(), ResultLimitReached);
LOG_ERROR(Kernel_SVC, "Could not reserve a new thread");
return ResultLimitReached;
}
// Create the thread. // Create the thread.
KThread* thread = KThread::Create(kernel); KThread* thread = KThread::Create(kernel);
if (!thread) { R_UNLESS(thread != nullptr, ResultOutOfResource)
LOG_ERROR(Kernel_SVC, "Unable to create new threads. Thread creation limit reached.");
return ResultOutOfResource;
}
SCOPE_EXIT({ thread->Close(); }); SCOPE_EXIT({ thread->Close(); });
// Initialize the thread. // Initialize the thread.
@ -89,9 +72,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
KThread::Register(kernel, thread); KThread::Register(kernel, thread);
// Add the thread to the handle table. // Add the thread to the handle table.
R_TRY(process.GetHandleTable().Add(out_handle, thread)); R_RETURN(process.GetHandleTable().Add(out_handle, thread));
return ResultSuccess;
} }
/// Starts the thread for the provided handle /// Starts the thread for the provided handle
@ -110,7 +91,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
thread->Open(); thread->Open();
system.Kernel().RegisterInUseObject(thread.GetPointerUnsafe()); system.Kernel().RegisterInUseObject(thread.GetPointerUnsafe());
return ResultSuccess; R_SUCCEED();
} }
/// Called when a thread exits /// Called when a thread exits
@ -202,10 +183,8 @@ Result GetThreadContext3(Core::System& system, VAddr out_context, Handle thread_
// Copy the thread context to user space. // Copy the thread context to user space.
system.Memory().WriteBlock(out_context, context.data(), context.size()); system.Memory().WriteBlock(out_context, context.data(), context.size());
return ResultSuccess; R_SUCCEED();
} }
return ResultSuccess;
} }
/// Gets the priority for the specified thread /// Gets the priority for the specified thread
@ -219,7 +198,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle)
// Get the thread's priority. // Get the thread's priority.
*out_priority = thread->GetPriority(); *out_priority = thread->GetPriority();
return ResultSuccess; R_SUCCEED();
} }
/// Sets the priority for the specified thread /// Sets the priority for the specified thread
@ -238,7 +217,7 @@ Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priorit
// Set the thread priority. // Set the thread priority.
thread->SetBasePriority(priority); thread->SetBasePriority(priority);
return ResultSuccess; R_SUCCEED();
} }
Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_thread_ids, 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
if ((out_thread_ids_size & 0xF0000000) != 0) { if ((out_thread_ids_size & 0xF0000000) != 0) {
LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}", LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}",
out_thread_ids_size); out_thread_ids_size);
return ResultOutOfRange; R_THROW(ResultOutOfRange);
} }
auto* const current_process = GetCurrentProcessPointer(system.Kernel()); auto* const current_process = GetCurrentProcessPointer(system.Kernel());
@ -263,7 +242,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa
!current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) { !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) {
LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
out_thread_ids, out_thread_ids + total_copy_size); out_thread_ids, out_thread_ids + total_copy_size);
return ResultInvalidCurrentMemory; R_THROW(ResultInvalidCurrentMemory);
} }
auto& memory = system.Memory(); auto& memory = system.Memory();
@ -278,7 +257,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa
} }
*out_num_threads = static_cast<u32>(num_threads); *out_num_threads = static_cast<u32>(num_threads);
return ResultSuccess; R_SUCCEED();
} }
Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affinity_mask, 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
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the core mask. // Get the core mask.
R_TRY(thread->GetCoreMask(out_core_id, out_affinity_mask)); R_RETURN(thread->GetCoreMask(out_core_id, out_affinity_mask));
return ResultSuccess;
} }
Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id, 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
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Set the core mask. // Set the core mask.
R_TRY(thread->SetCoreMask(core_id, affinity_mask)); R_RETURN(thread->SetCoreMask(core_id, affinity_mask));
return ResultSuccess;
} }
/// Get the ID for the specified thread. /// Get the ID for the specified thread.
@ -337,7 +312,7 @@ Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handl
// Get the thread's id. // Get the thread's id.
*out_thread_id = thread->GetId(); *out_thread_id = thread->GetId();
return ResultSuccess; R_SUCCEED();
} }
Result CreateThread64(Core::System& system, Handle* out_handle, uint64_t func, uint64_t arg, Result CreateThread64(Core::System& system, Handle* out_handle, uint64_t func, uint64_t arg,

View File

@ -67,9 +67,7 @@ Result CreateTransferMemory(Core::System& system, Handle* out, VAddr address, u6
KTransferMemory::Register(kernel, trmem); KTransferMemory::Register(kernel, trmem);
// Add the transfer memory to the handle table. // Add the transfer memory to the handle table.
R_TRY(handle_table.Add(out, trmem)); R_RETURN(handle_table.Add(out, trmem));
return ResultSuccess;
} }
Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size, Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size,