yuzu-emu
/
yuzu
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();
}
return ResultSuccess;
R_SUCCEED();
}
Result KReadableEvent::Clear() {
this->Reset();
return ResultSuccess;
R_SUCCEED();
}
Result KReadableEvent::Reset() {
KScopedSchedulerLock lk{kernel};
if (!m_is_signaled) {
return ResultInvalidState;
}
R_UNLESS(m_is_signaled, ResultInvalidState);
m_is_signaled = false;
return ResultSuccess;
R_SUCCEED();
}
} // namespace Kernel

View File

@ -82,7 +82,7 @@ Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) {
limit_values[index] = value;
peak_values[index] = current_values[index];
return ResultSuccess;
R_SUCCEED();
}
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,
@ -339,7 +339,7 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext
}
// We succeeded.
return ResultSuccess;
R_SUCCEED();
}
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);
// Validate input.
if (IsKernelAddress(address)) {
LOG_ERROR(Kernel_SVC, "Attempting to wait on kernel address (address={:08X})", address);
return ResultInvalidCurrentMemory;
}
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;
}
R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress);
R_UNLESS(IsValidArbitrationType(arb_type), ResultInvalidEnumValue);
// Convert timeout from nanoseconds to ticks.
s64 timeout{};
@ -72,7 +63,8 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t
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)
@ -82,41 +74,32 @@ Result SignalToAddress(Core::System& system, VAddr address, SignalType signal_ty
address, signal_type, value, count);
// Validate input.
if (IsKernelAddress(address)) {
LOG_ERROR(Kernel_SVC, "Attempting to signal to a kernel address (address={:08X})", address);
return ResultInvalidCurrentMemory;
}
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;
}
R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress);
R_UNLESS(IsValidSignalType(signal_type), ResultInvalidEnumValue);
return GetCurrentProcess(system.Kernel())
.SignalAddressArbiter(address, signal_type, value, count);
R_RETURN(GetCurrentProcess(system.Kernel())
.SignalAddressArbiter(address, signal_type, value, count));
}
Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, 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 SignalToAddress64(Core::System& system, VAddr address, SignalType signal_type, s32 value,
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,
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,
s32 count) {
return SignalToAddress(system, address, signal_type, value, count);
R_RETURN(SignalToAddress(system, address, signal_type, value, count));
}
} // namespace Kernel::Svc

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/scope_exit.h"
#include "core/core.h"
#include "core/hle/kernel/k_code_memory.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);
R_UNLESS(code_mem != nullptr, ResultOutOfResource);
SCOPE_EXIT({ code_mem->Close(); });
// Verify that the region is in range.
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.
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem));
code_mem->Close();
return ResultSuccess;
R_SUCCEED();
}
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));
} break;
default:
return ResultInvalidEnumValue;
R_THROW(ResultInvalidEnumValue);
}
return ResultSuccess;
R_SUCCEED();
}
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);
// Validate input.
if (IsKernelAddress(address)) {
LOG_ERROR(Kernel_SVC, "Attempted to wait on kernel address (address={:08X})", address);
return ResultInvalidCurrentMemory;
}
if (!Common::IsAligned(address, sizeof(s32))) {
LOG_ERROR(Kernel_SVC, "Address must be 4 byte aligned (address={:08X})", address);
return ResultInvalidAddress;
}
R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
R_UNLESS(Common::IsAligned(address, sizeof(s32)), ResultInvalidAddress);
// Convert timeout from nanoseconds to ticks.
s64 timeout{};
@ -43,8 +37,9 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke
}
// Wait on the condition variable.
return GetCurrentProcess(system.Kernel())
.WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout);
R_RETURN(
GetCurrentProcess(system.Kernel())
.WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout));
}
/// 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);
R_UNLESS(event.IsNotNull(), ResultInvalidHandle);
return event->Signal();
R_RETURN(event->Signal());
}
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);
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);
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);
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
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));
// 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.
R_TRY(handle_table.Add(out_read, std::addressof(event->GetReadableEvent())));
// We succeeded.
handle_guard.Cancel();
return ResultSuccess;
R_RETURN(handle_table.Add(out_read, std::addressof(event->GetReadableEvent())));
}
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::IsApplication:
case InfoType::FreeThreadCount: {
if (info_sub_id != 0) {
LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,
info_sub_id);
return ResultInvalidEnumValue;
}
R_UNLESS(info_sub_id == 0, ResultInvalidEnumValue);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}",
info_id, info_sub_id, handle);
return ResultInvalidHandle;
}
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
switch (info_id_type) {
case InfoType::CoreMask:
*result = process->GetCoreMask();
return ResultSuccess;
R_SUCCEED();
case InfoType::PriorityMask:
*result = process->GetPriorityMask();
return ResultSuccess;
R_SUCCEED();
case InfoType::AliasRegionAddress:
*result = process->PageTable().GetAliasRegionStart();
return ResultSuccess;
R_SUCCEED();
case InfoType::AliasRegionSize:
*result = process->PageTable().GetAliasRegionSize();
return ResultSuccess;
R_SUCCEED();
case InfoType::HeapRegionAddress:
*result = process->PageTable().GetHeapRegionStart();
return ResultSuccess;
R_SUCCEED();
case InfoType::HeapRegionSize:
*result = process->PageTable().GetHeapRegionSize();
return ResultSuccess;
R_SUCCEED();
case InfoType::AslrRegionAddress:
*result = process->PageTable().GetAliasCodeRegionStart();
return ResultSuccess;
R_SUCCEED();
case InfoType::AslrRegionSize:
*result = process->PageTable().GetAliasCodeRegionSize();
return ResultSuccess;
R_SUCCEED();
case InfoType::StackRegionAddress:
*result = process->PageTable().GetStackRegionStart();
return ResultSuccess;
R_SUCCEED();
case InfoType::StackRegionSize:
*result = process->PageTable().GetStackRegionSize();
return ResultSuccess;
R_SUCCEED();
case InfoType::TotalMemorySize:
*result = process->GetTotalPhysicalMemoryAvailable();
return ResultSuccess;
R_SUCCEED();
case InfoType::UsedMemorySize:
*result = process->GetTotalPhysicalMemoryUsed();
return ResultSuccess;
R_SUCCEED();
case InfoType::SystemResourceSizeTotal:
*result = process->GetSystemResourceSize();
return ResultSuccess;
R_SUCCEED();
case InfoType::SystemResourceSizeUsed:
LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage");
*result = process->GetSystemResourceUsage();
return ResultSuccess;
R_SUCCEED();
case InfoType::ProgramId:
*result = process->GetProgramID();
return ResultSuccess;
R_SUCCEED();
case InfoType::UserExceptionContextAddress:
*result = process->GetProcessLocalRegionAddress();
return ResultSuccess;
R_SUCCEED();
case InfoType::TotalNonSystemMemorySize:
*result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource();
return ResultSuccess;
R_SUCCEED();
case InfoType::UsedNonSystemMemorySize:
*result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource();
return ResultSuccess;
R_SUCCEED();
case InfoType::IsApplication:
LOG_WARNING(Kernel_SVC, "(STUBBED) Assuming process is application");
*result = true;
return ResultSuccess;
R_SUCCEED();
case InfoType::FreeThreadCount:
*result = process->GetFreeThreadCount();
return ResultSuccess;
R_SUCCEED();
default:
break;
}
LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
return ResultInvalidEnumValue;
R_THROW(ResultInvalidEnumValue);
}
case InfoType::DebuggerAttached:
*result = 0;
return ResultSuccess;
R_SUCCEED();
case InfoType::ResourceLimit: {
if (handle != 0) {
LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle);
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;
}
R_UNLESS(handle == 0, ResultInvalidHandle);
R_UNLESS(info_sub_id == 0, ResultInvalidCombination);
KProcess* const current_process = GetCurrentProcessPointer(system.Kernel());
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) {
*result = Svc::InvalidHandle;
// Yes, the kernel considers this a successful operation.
return ResultSuccess;
R_SUCCEED();
}
Handle resource_handle{};
R_TRY(handle_table.Add(&resource_handle, resource_limit));
*result = resource_handle;
return ResultSuccess;
R_SUCCEED();
}
case InfoType::RandomEntropy:
if (handle != 0) {
LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}",
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;
}
R_UNLESS(handle == 0, ResultInvalidHandle);
R_UNLESS(info_sub_id < KProcess::RANDOM_ENTROPY_SIZE, ResultInvalidCombination);
*result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id);
return ResultSuccess;
R_SUCCEED();
case InfoType::InitialProcessIdRange:
LOG_WARNING(Kernel_SVC,
"(STUBBED) Attempted to query privileged process id bounds, returned 0");
*result = 0;
return ResultSuccess;
R_SUCCEED();
case InfoType::ThreadTickCount: {
constexpr u64 num_cpus = 4;
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,
info_sub_id);
return ResultInvalidCombination;
R_THROW(ResultInvalidCombination);
}
KScopedAutoObject thread = GetCurrentProcess(system.Kernel())
@ -211,7 +186,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
if (thread.IsNull()) {
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}",
static_cast<Handle>(handle));
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
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;
return ResultSuccess;
R_SUCCEED();
}
case InfoType::IdleTickCount: {
// 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.
*result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime();
return ResultSuccess;
R_SUCCEED();
}
case InfoType::MesosphereCurrentProcess: {
// Verify the input handle is invalid.
@ -265,11 +240,11 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
*result = tmp;
// We succeeded.
return ResultSuccess;
R_SUCCEED();
}
default:
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());
return session->SendSyncRequest();
R_RETURN(session->SendSyncRequest());
}
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(),
static_cast<s32>(objs.size()), timeout_ns);
if (result == ResultTimedOut) {
return result;
R_RETURN(result);
}
// Receive the request.
@ -97,7 +97,7 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad
}
*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);
// Validate the input address.
if (IsKernelAddress(address)) {
LOG_ERROR(Kernel_SVC, "Attempting to arbitrate a lock 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;
}
R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress);
return GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag);
R_RETURN(GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag));
}
/// Unlock a mutex
@ -32,18 +25,10 @@ Result ArbitrateUnlock(Core::System& system, VAddr address) {
LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address);
// Validate the input address.
if (IsKernelAddress(address)) {
LOG_ERROR(Kernel_SVC,
"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;
}
R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
R_UNLESS(Common::IsAligned(address, sizeof(u32)), 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) {

View File

@ -33,49 +33,49 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAd
u64 size) {
if (!Common::Is4KBAligned(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)) {
LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr);
return ResultInvalidSize;
R_THROW(ResultInvalidSize);
}
if (size == 0) {
LOG_ERROR(Kernel_SVC, "Size is 0");
return ResultInvalidSize;
R_THROW(ResultInvalidSize);
}
if (!Common::Is4KBAligned(size)) {
LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size);
return ResultInvalidSize;
R_THROW(ResultInvalidSize);
}
if (!IsValidAddressRange(dst_addr, size)) {
LOG_ERROR(Kernel_SVC,
"Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}",
dst_addr, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
if (!IsValidAddressRange(src_addr, size)) {
LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}",
src_addr, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
if (!manager.IsInsideAddressSpace(src_addr, size)) {
LOG_ERROR(Kernel_SVC,
"Source is not within the address space, addr=0x{:016X}, size=0x{:016X}",
src_addr, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
if (manager.IsOutsideStackRegion(dst_addr, size)) {
LOG_ERROR(Kernel_SVC,
"Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}",
dst_addr, size);
return ResultInvalidMemoryRegion;
R_THROW(ResultInvalidMemoryRegion);
}
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}, "
"size=0x{:016X}",
dst_addr, size);
return ResultInvalidMemoryRegion;
R_THROW(ResultInvalidMemoryRegion);
}
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}, "
"size=0x{:016X}",
dst_addr, size);
return ResultInvalidMemoryRegion;
R_THROW(ResultInvalidMemoryRegion);
}
return ResultSuccess;
R_SUCCEED();
}
} // namespace
@ -117,7 +117,7 @@ Result SetMemoryPermission(Core::System& system, VAddr address, u64 size, Memory
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// 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) {
@ -141,7 +141,7 @@ Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mas
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// 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.
@ -156,7 +156,7 @@ Result MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size)
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
@ -171,7 +171,7 @@ Result UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 siz
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,

View File

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

View File

@ -47,7 +47,7 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) {
// Get the process id.
*out_process_id = process->GetId();
return ResultSuccess;
R_SUCCEED();
}
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,
"Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}",
out_process_ids_size);
return ResultOutOfRange;
R_THROW(ResultOutOfRange);
}
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)) {
LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
out_process_ids, out_process_ids + total_copy_size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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);
return ResultSuccess;
R_SUCCEED();
}
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()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle);
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
if (info_type != ProcessInfoType::ProcessState) {
LOG_ERROR(Kernel_SVC, "Expected info_type to be ProcessState but got {} instead",
info_type);
return ResultInvalidEnumValue;
R_THROW(ResultInvalidEnumValue);
}
*out = static_cast<s64>(process->GetState());
return ResultSuccess;
R_SUCCEED();
}
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);
// 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,
@ -93,10 +93,8 @@ Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_
KMemoryAttribute::All, KMemoryAttribute::None));
// Map the group.
R_TRY(dst_pt.MapPageGroup(dst_address, pg, KMemoryState::SharedCode,
KMemoryPermission::UserReadWrite));
return ResultSuccess;
R_RETURN(dst_pt.MapPageGroup(dst_address, pg, KMemoryState::SharedCode,
KMemoryPermission::UserReadWrite));
}
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);
// Unmap the memory.
R_TRY(dst_pt.UnmapProcessMemory(dst_address, size, src_pt, src_address));
return ResultSuccess;
R_RETURN(dst_pt.UnmapProcessMemory(dst_address, size, src_pt, src_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)) {
LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).",
src_address);
return ResultInvalidAddress;
R_THROW(ResultInvalidAddress);
}
if (!Common::Is4KBAligned(dst_address)) {
LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).",
dst_address);
return ResultInvalidAddress;
R_THROW(ResultInvalidAddress);
}
if (size == 0 || !Common::Is4KBAligned(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)) {
@ -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}, "
"size=0x{:016X}).",
dst_address, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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}, "
"size=0x{:016X}).",
src_address, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle);
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
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}, "
"size=0x{:016X}).",
src_address, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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}, "
"size=0x{:016X}).",
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,
@ -212,18 +208,18 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
if (!Common::Is4KBAligned(dst_address)) {
LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).",
dst_address);
return ResultInvalidAddress;
R_THROW(ResultInvalidAddress);
}
if (!Common::Is4KBAligned(src_address)) {
LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).",
src_address);
return ResultInvalidAddress;
R_THROW(ResultInvalidAddress);
}
if (size == 0 || !Common::Is4KBAligned(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)) {
@ -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}, "
"size=0x{:016X}).",
dst_address, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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}, "
"size=0x{:016X}).",
src_address, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle);
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
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}, "
"size=0x{:016X}).",
src_address, size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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}, "
"size=0x{:016X}).",
dst_address, size);
return ResultInvalidMemoryRegion;
R_THROW(ResultInvalidMemoryRegion);
}
return page_table.UnmapCodeMemory(dst_address, src_address, size,
KPageTable::ICacheInvalidationStrategy::InvalidateAll);
R_RETURN(page_table.UnmapCodeMemory(dst_address, src_address, size,
KPageTable::ICacheInvalidationStrategy::InvalidateAll));
}
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);
// Query memory is just QueryProcessMemory on the current process.
return QueryProcessMemory(system, out_memory_info, out_page_info, CurrentProcess,
query_address);
R_RETURN(
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,
@ -27,7 +27,7 @@ Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageIn
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle);
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
auto& memory{system.Memory()};

View File

@ -27,9 +27,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
KResourceLimit::Register(kernel, resource_limit);
// Add the limit to the handle table.
R_TRY(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit));
return ResultSuccess;
R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit));
}
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.
*out_limit_value = resource_limit->GetLimitValue(which);
return ResultSuccess;
R_SUCCEED();
}
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.
*out_current_value = resource_limit->GetCurrentValue(which);
return ResultSuccess;
R_SUCCEED();
}
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);
// Set the limit value.
R_TRY(resource_limit->SetLimitValue(which, limit_value));
return ResultSuccess;
R_RETURN(resource_limit->SetLimitValue(which, limit_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()) {
session = T::Create(system.Kernel());
} else {
return ResultLimitReached;
R_THROW(ResultLimitReached);
// // We couldn't reserve a session. Check that we support dynamically expanding the
// // 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.
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);
}
};
return result;
// Add the client session to the handle table.
R_RETURN(handle_table.Add(out_client, &session->GetClientSession()));
}
} // namespace
@ -94,9 +92,9 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
u64 name) {
if (is_light) {
// return CreateSession<KLightSession>(system, out_server, out_client, name);
return ResultNotImplemented;
R_THROW(ResultNotImplemented);
} 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));
// Ensure that we clean up the shared memory if we fail to map it.
auto guard =
SCOPE_GUARD({ process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size); });
ON_RESULT_FAILURE {
process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size);
};
// Map the shared memory.
R_TRY(shmem->Map(process, address, size, map_perm));
// We succeeded.
guard.Cancel();
return ResultSuccess;
R_RETURN(shmem->Map(process, address, size, map_perm));
}
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.
process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size);
return ResultSuccess;
R_SUCCEED();
}
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),
ResultInvalidHandle);
return ResultSuccess;
R_SUCCEED();
}
/// 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);
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);
if (process.IsNotNull()) {
return process->Reset();
R_RETURN(process->Reset());
}
}
LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle);
return ResultInvalidHandle;
R_THROW(ResultInvalidHandle);
}
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.
thread->WaitCancel();
return ResultSuccess;
R_SUCCEED();
}
void SynchronizePreemptionState(Core::System& system) {

View File

@ -34,39 +34,22 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
}
// Validate arguments.
if (!IsValidVirtualCoreId(core_id)) {
LOG_ERROR(Kernel_SVC, "Invalid Core ID specified (id={})", core_id);
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;
}
R_UNLESS(IsValidVirtualCoreId(core_id), ResultInvalidCoreId);
R_UNLESS(((1ull << core_id) & process.GetCoreMask()) != 0, ResultInvalidCoreId);
if (HighestThreadPriority > priority || priority > LowestThreadPriority) {
LOG_ERROR(Kernel_SVC, "Invalid priority specified (priority={})", priority);
return ResultInvalidPriority;
}
if (!process.CheckThreadPriority(priority)) {
LOG_ERROR(Kernel_SVC, "Invalid allowable thread priority (priority={})", priority);
return ResultInvalidPriority;
}
R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority,
ResultInvalidPriority);
R_UNLESS(process.CheckThreadPriority(priority), ResultInvalidPriority);
// Reserve a new thread from the process resource limit (waiting up to 100ms).
KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1,
system.CoreTiming().GetGlobalTimeNs().count() +
100000000);
if (!thread_reservation.Succeeded()) {
LOG_ERROR(Kernel_SVC, "Could not reserve a new thread");
return ResultLimitReached;
}
R_UNLESS(thread_reservation.Succeeded(), ResultLimitReached);
// Create the thread.
KThread* thread = KThread::Create(kernel);
if (!thread) {
LOG_ERROR(Kernel_SVC, "Unable to create new threads. Thread creation limit reached.");
return ResultOutOfResource;
}
R_UNLESS(thread != nullptr, ResultOutOfResource)
SCOPE_EXIT({ thread->Close(); });
// Initialize the thread.
@ -89,9 +72,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
KThread::Register(kernel, thread);
// Add the thread to the handle table.
R_TRY(process.GetHandleTable().Add(out_handle, thread));
return ResultSuccess;
R_RETURN(process.GetHandleTable().Add(out_handle, thread));
}
/// Starts the thread for the provided handle
@ -110,7 +91,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
thread->Open();
system.Kernel().RegisterInUseObject(thread.GetPointerUnsafe());
return ResultSuccess;
R_SUCCEED();
}
/// 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.
system.Memory().WriteBlock(out_context, context.data(), context.size());
return ResultSuccess;
R_SUCCEED();
}
return ResultSuccess;
}
/// 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.
*out_priority = thread->GetPriority();
return ResultSuccess;
R_SUCCEED();
}
/// 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.
thread->SetBasePriority(priority);
return ResultSuccess;
R_SUCCEED();
}
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) {
LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}",
out_thread_ids_size);
return ResultOutOfRange;
R_THROW(ResultOutOfRange);
}
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)) {
LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
out_thread_ids, out_thread_ids + total_copy_size);
return ResultInvalidCurrentMemory;
R_THROW(ResultInvalidCurrentMemory);
}
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);
return ResultSuccess;
R_SUCCEED();
}
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);
// Get the core mask.
R_TRY(thread->GetCoreMask(out_core_id, out_affinity_mask));
return ResultSuccess;
R_RETURN(thread->GetCoreMask(out_core_id, out_affinity_mask));
}
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);
// Set the core mask.
R_TRY(thread->SetCoreMask(core_id, affinity_mask));
return ResultSuccess;
R_RETURN(thread->SetCoreMask(core_id, affinity_mask));
}
/// 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.
*out_thread_id = thread->GetId();
return ResultSuccess;
R_SUCCEED();
}
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);
// Add the transfer memory to the handle table.
R_TRY(handle_table.Add(out, trmem));
return ResultSuccess;
R_RETURN(handle_table.Add(out, trmem));
}
Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size,