From 21188f568369277b562bd13f562c7355fcac85bb Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 Dec 2017 18:05:43 -0800 Subject: [PATCH] HLE: Move SVC handlers to the Kernel namespace --- src/core/arm/dynarmic/arm_dynarmic.cpp | 2 +- .../arm/dyncom/arm_dyncom_interpreter.cpp | 2 +- src/core/hle/function_wrappers.h | 12 +- src/core/hle/kernel/svc.cpp | 464 ++++++++---------- src/core/hle/kernel/svc.h | 10 +- 5 files changed, 209 insertions(+), 281 deletions(-) diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 2708d8d337..1890e7c5f4 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -54,7 +54,7 @@ static Dynarmic::UserCallbacks GetUserCallbacks( Dynarmic::UserCallbacks user_callbacks{}; user_callbacks.InterpreterFallback = &InterpreterFallback; user_callbacks.user_arg = static_cast(interpreter_state.get()); - user_callbacks.CallSVC = &SVC::CallSVC; + user_callbacks.CallSVC = &Kernel::CallSVC; user_callbacks.memory.IsReadOnlyMemory = &IsReadOnlyMemory; user_callbacks.memory.ReadCode = &Memory::Read32; user_callbacks.memory.Read8 = &Memory::Read8; diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp index c45bdbf5eb..47315c3ebf 100644 --- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp +++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp @@ -3863,7 +3863,7 @@ SWI_INST : { cpu->NumInstrsToExecute = num_instrs >= cpu->NumInstrsToExecute ? 0 : cpu->NumInstrsToExecute - num_instrs; num_instrs = 0; - SVC::CallSVC(inst_cream->num & 0xFFFF); + Kernel::CallSVC(inst_cream->num & 0xFFFF); } cpu->Reg[15] += cpu->GetInstructionSize(); diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index f3a02158b8..51994dc193 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -99,10 +99,10 @@ void Wrap() { FuncReturn(retval); } -template +template void Wrap() { - MemoryInfo memory_info = {}; - PageInfo page_info = {}; + Kernel::MemoryInfo memory_info = {}; + Kernel::PageInfo page_info = {}; u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; Core::CPU().SetReg(1, memory_info.base_address); Core::CPU().SetReg(2, memory_info.size); @@ -112,10 +112,10 @@ void Wrap() { FuncReturn(retval); } -template +template void Wrap() { - MemoryInfo memory_info = {}; - PageInfo page_info = {}; + Kernel::MemoryInfo memory_info = {}; + Kernel::PageInfo page_info = {}; u32 retval = func(&memory_info, &page_info, PARAM(2), PARAM(3)).raw; Core::CPU().SetReg(1, memory_info.base_address); Core::CPU().SetReg(2, memory_info.size); diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 7e637b4267..06c9052848 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -36,14 +36,7 @@ #include "core/hle/result.h" #include "core/hle/service/service.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Namespace SVC - -using Kernel::ERR_INVALID_HANDLE; -using Kernel::Handle; -using Kernel::SharedPtr; - -namespace SVC { +namespace Kernel { enum ControlMemoryOperation { MEMOP_FREE = 1, @@ -65,8 +58,6 @@ enum ControlMemoryOperation { /// Map application or GSP heap memory static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { - using namespace Kernel; - LOG_DEBUG(Kernel_SVC, "called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=0x%X, permissions=0x%08X", operation, addr0, addr1, size, permissions); @@ -121,21 +112,19 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add break; } - case MEMOP_MAP: // TODO: This is just a hack to avoid regressions until memory aliasing is - // implemented - { - CASCADE_RESULT(*out_addr, process.HeapAllocate(addr0, size, vma_permissions)); - break; - } + case MEMOP_MAP: { + // TODO: This is just a hack to avoid regressions until memory aliasing is implemented + CASCADE_RESULT(*out_addr, process.HeapAllocate(addr0, size, vma_permissions)); + break; + } - case MEMOP_UNMAP: // TODO: This is just a hack to avoid regressions until memory aliasing is - // implemented - { - ResultCode result = process.HeapFree(addr0, size); - if (result.IsError()) - return result; - break; - } + case MEMOP_UNMAP: { + // TODO: This is just a hack to avoid regressions until memory aliasing is implemented + ResultCode result = process.HeapFree(addr0, size); + if (result.IsError()) + return result; + break; + } case MEMOP_PROTECT: { ResultCode result = process.vm_manager.ReprotectRange(addr0, size, vma_permissions); @@ -155,16 +144,12 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add } /// Maps a memory block to specified address -static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permissions, - u32 other_permissions) { - using Kernel::SharedMemory; - using Kernel::MemoryPermission; - +static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", handle, addr, permissions, other_permissions); - SharedPtr shared_memory = Kernel::g_handle_table.Get(handle); + SharedPtr shared_memory = g_handle_table.Get(handle); if (shared_memory == nullptr) return ERR_INVALID_HANDLE; @@ -178,62 +163,59 @@ static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permission case MemoryPermission::WriteExecute: case MemoryPermission::ReadWriteExecute: case MemoryPermission::DontCare: - return shared_memory->Map(Kernel::g_current_process.get(), addr, permissions_type, + return shared_memory->Map(g_current_process.get(), addr, permissions_type, static_cast(other_permissions)); default: LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); } - return Kernel::ERR_INVALID_COMBINATION; + return ERR_INVALID_COMBINATION; } -static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) { - using Kernel::SharedMemory; - +static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X", handle, addr); // TODO(Subv): Return E0A01BF5 if the address is not in the application's heap - SharedPtr shared_memory = Kernel::g_handle_table.Get(handle); + SharedPtr shared_memory = g_handle_table.Get(handle); if (shared_memory == nullptr) return ERR_INVALID_HANDLE; - return shared_memory->Unmap(Kernel::g_current_process.get(), addr); + return shared_memory->Unmap(g_current_process.get(), addr); } /// Connect to an OS service given the port name, returns the handle to the port to out -static ResultCode ConnectToPort(Kernel::Handle* out_handle, VAddr port_name_address) { +static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) { if (!Memory::IsValidVirtualAddress(port_name_address)) - return Kernel::ERR_NOT_FOUND; + return ERR_NOT_FOUND; static constexpr std::size_t PortNameMaxLength = 11; // Read 1 char beyond the max allowed port name to detect names that are too long. std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); if (port_name.size() > PortNameMaxLength) - return Kernel::ERR_PORT_NAME_TOO_LONG; + return ERR_PORT_NAME_TOO_LONG; LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name.c_str()); auto it = Service::g_kernel_named_ports.find(port_name); if (it == Service::g_kernel_named_ports.end()) { LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name.c_str()); - return Kernel::ERR_NOT_FOUND; + return ERR_NOT_FOUND; } auto client_port = it->second; - SharedPtr client_session; + SharedPtr client_session; CASCADE_RESULT(client_session, client_port->Connect()); // Return the client session - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(client_session)); + CASCADE_RESULT(*out_handle, g_handle_table.Create(client_session)); return RESULT_SUCCESS; } /// Makes a blocking IPC call to an OS service. -static ResultCode SendSyncRequest(Kernel::Handle handle) { - SharedPtr session = - Kernel::g_handle_table.Get(handle); +static ResultCode SendSyncRequest(Handle handle) { + SharedPtr session = g_handle_table.Get(handle); if (session == nullptr) { return ERR_INVALID_HANDLE; } @@ -242,19 +224,19 @@ static ResultCode SendSyncRequest(Kernel::Handle handle) { Core::System::GetInstance().PrepareReschedule(); - return session->SendSyncRequest(Kernel::GetCurrentThread()); + return session->SendSyncRequest(GetCurrentThread()); } /// Close a handle -static ResultCode CloseHandle(Kernel::Handle handle) { +static ResultCode CloseHandle(Handle handle) { LOG_TRACE(Kernel_SVC, "Closing handle 0x%08X", handle); - return Kernel::g_handle_table.Close(handle); + return g_handle_table.Close(handle); } /// Wait for a handle to synchronize, timeout after the specified nanoseconds -static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) { - auto object = Kernel::g_handle_table.Get(handle); - Kernel::Thread* thread = Kernel::GetCurrentThread(); +static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { + auto object = g_handle_table.Get(handle); + Thread* thread = GetCurrentThread(); if (object == nullptr) return ERR_INVALID_HANDLE; @@ -265,7 +247,7 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) if (object->ShouldWait(thread)) { if (nano_seconds == 0) - return Kernel::RESULT_TIMEOUT; + return RESULT_TIMEOUT; thread->wait_objects = {object}; object->AddWaitingThread(thread); @@ -274,14 +256,13 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); - thread->wakeup_callback = [](ThreadWakeupReason reason, - Kernel::SharedPtr thread, - Kernel::SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, + SharedPtr object) { ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ANY); if (reason == ThreadWakeupReason::Timeout) { - thread->SetWaitSynchronizationResult(Kernel::RESULT_TIMEOUT); + thread->SetWaitSynchronizationResult(RESULT_TIMEOUT); return; } @@ -297,7 +278,7 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) // Note: The output of this SVC will be set to RESULT_SUCCESS if the thread // resumes due to a signal in its wait objects. // Otherwise we retain the default value of timeout. - return Kernel::RESULT_TIMEOUT; + return RESULT_TIMEOUT; } object->Acquire(thread); @@ -308,10 +289,10 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) /// Wait for the given handles to synchronize, timeout after the specified nanoseconds static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle_count, bool wait_all, s64 nano_seconds) { - Kernel::Thread* thread = Kernel::GetCurrentThread(); + Thread* thread = GetCurrentThread(); if (!Memory::IsValidVirtualAddress(handles_address)) - return Kernel::ERR_INVALID_POINTER; + return ERR_INVALID_POINTER; // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If // this happens, the running application will crash. @@ -319,14 +300,14 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand // Check if 'handle_count' is invalid if (handle_count < 0) - return Kernel::ERR_OUT_OF_RANGE; + return ERR_OUT_OF_RANGE; - using ObjectPtr = Kernel::SharedPtr; + using ObjectPtr = SharedPtr; std::vector objects(handle_count); for (int i = 0; i < handle_count; ++i) { - Kernel::Handle handle = Memory::Read32(handles_address + i * sizeof(Kernel::Handle)); - auto object = Kernel::g_handle_table.Get(handle); + Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); + auto object = g_handle_table.Get(handle); if (object == nullptr) return ERR_INVALID_HANDLE; objects[i] = object; @@ -350,7 +331,7 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand // If a timeout value of 0 was provided, just return the Timeout error code instead of // suspending the thread. if (nano_seconds == 0) - return Kernel::RESULT_TIMEOUT; + return RESULT_TIMEOUT; // Put the thread to sleep thread->status = THREADSTATUS_WAIT_SYNCH_ALL; @@ -365,14 +346,13 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); - thread->wakeup_callback = [](ThreadWakeupReason reason, - Kernel::SharedPtr thread, - Kernel::SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, + SharedPtr object) { ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ALL); if (reason == ThreadWakeupReason::Timeout) { - thread->SetWaitSynchronizationResult(Kernel::RESULT_TIMEOUT); + thread->SetWaitSynchronizationResult(RESULT_TIMEOUT); return; } @@ -388,7 +368,7 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand *out = -1; // Note: The output of this SVC will be set to RESULT_SUCCESS if the thread resumes due to // a signal in one of its wait objects. - return Kernel::RESULT_TIMEOUT; + return RESULT_TIMEOUT; } else { // Find the first object that is acquirable in the provided list of objects auto itr = std::find_if(objects.begin(), objects.end(), [thread](const ObjectPtr& object) { @@ -397,7 +377,7 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand if (itr != objects.end()) { // We found a ready object, acquire it and set the result value - Kernel::WaitObject* object = itr->get(); + WaitObject* object = itr->get(); object->Acquire(thread); *out = static_cast(std::distance(objects.begin(), itr)); return RESULT_SUCCESS; @@ -408,14 +388,14 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand // If a timeout value of 0 was provided, just return the Timeout error code instead of // suspending the thread. if (nano_seconds == 0) - return Kernel::RESULT_TIMEOUT; + return RESULT_TIMEOUT; // Put the thread to sleep thread->status = THREADSTATUS_WAIT_SYNCH_ANY; // Add the thread to each of the objects' waiting threads. for (size_t i = 0; i < objects.size(); ++i) { - Kernel::WaitObject* object = objects[i].get(); + WaitObject* object = objects[i].get(); object->AddWaitingThread(thread); } @@ -427,14 +407,13 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); - thread->wakeup_callback = [](ThreadWakeupReason reason, - Kernel::SharedPtr thread, - Kernel::SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, + SharedPtr object) { ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ANY); if (reason == ThreadWakeupReason::Timeout) { - thread->SetWaitSynchronizationResult(Kernel::RESULT_TIMEOUT); + thread->SetWaitSynchronizationResult(RESULT_TIMEOUT); return; } @@ -450,21 +429,21 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand // signal in one of its wait objects. // Otherwise we retain the default value of timeout, and -1 in the out parameter *out = -1; - return Kernel::RESULT_TIMEOUT; + return RESULT_TIMEOUT; } } -static ResultCode ReceiveIPCRequest(Kernel::SharedPtr server_session, - Kernel::SharedPtr thread) { +static ResultCode ReceiveIPCRequest(SharedPtr server_session, + SharedPtr thread) { if (server_session->parent->client == nullptr) { - return Kernel::ERR_SESSION_CLOSED_BY_REMOTE; + return ERR_SESSION_CLOSED_BY_REMOTE; } VAddr target_address = thread->GetCommandBufferAddress(); VAddr source_address = server_session->currently_handling->GetCommandBufferAddress(); - ResultCode translation_result = Kernel::TranslateCommandBuffer( - server_session->currently_handling, thread, source_address, target_address); + ResultCode translation_result = TranslateCommandBuffer(server_session->currently_handling, + thread, source_address, target_address); // If a translation error occurred, immediately resume the client thread. if (translation_result.IsError()) { @@ -483,20 +462,20 @@ static ResultCode ReceiveIPCRequest(Kernel::SharedPtr ser /// In a single operation, sends a IPC reply and waits for a new request. static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_count, - Kernel::Handle reply_target) { + Handle reply_target) { if (!Memory::IsValidVirtualAddress(handles_address)) - return Kernel::ERR_INVALID_POINTER; + return ERR_INVALID_POINTER; // Check if 'handle_count' is invalid if (handle_count < 0) - return Kernel::ERR_OUT_OF_RANGE; + return ERR_OUT_OF_RANGE; - using ObjectPtr = SharedPtr; + using ObjectPtr = SharedPtr; std::vector objects(handle_count); for (int i = 0; i < handle_count; ++i) { - Kernel::Handle handle = Memory::Read32(handles_address + i * sizeof(Kernel::Handle)); - auto object = Kernel::g_handle_table.Get(handle); + Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); + auto object = g_handle_table.Get(handle); if (object == nullptr) return ERR_INVALID_HANDLE; objects[i] = object; @@ -504,10 +483,10 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ // We are also sending a command reply. // Do not send a reply if the command id in the command buffer is 0xFFFF. - u32* cmd_buff = Kernel::GetCommandBuffer(); + u32* cmd_buff = GetCommandBuffer(); IPC::Header header{cmd_buff[0]}; if (reply_target != 0 && header.command_id != 0xFFFF) { - auto session = Kernel::g_handle_table.Get(reply_target); + auto session = g_handle_table.Get(reply_target); if (session == nullptr) return ERR_INVALID_HANDLE; @@ -520,14 +499,14 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ // TODO(Subv): Is the same error code (ClosedByRemote) returned for both of these cases? if (request_thread == nullptr || session->parent->client == nullptr) { *index = -1; - return Kernel::ERR_SESSION_CLOSED_BY_REMOTE; + return ERR_SESSION_CLOSED_BY_REMOTE; } - VAddr source_address = Kernel::GetCurrentThread()->GetCommandBufferAddress(); + VAddr source_address = GetCurrentThread()->GetCommandBufferAddress(); VAddr target_address = request_thread->GetCommandBufferAddress(); - ResultCode translation_result = Kernel::TranslateCommandBuffer( - Kernel::GetCurrentThread(), request_thread, source_address, target_address); + ResultCode translation_result = TranslateCommandBuffer(GetCurrentThread(), request_thread, + source_address, target_address); // Note: The real kernel seems to always panic if the Server->Client buffer translation // fails for whatever reason. @@ -547,7 +526,7 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ return RESULT_SUCCESS; } - auto thread = Kernel::GetCurrentThread(); + auto thread = GetCurrentThread(); // Find the first object that is acquirable in the provided list of objects auto itr = std::find_if(objects.begin(), objects.end(), [thread](const ObjectPtr& object) { @@ -556,15 +535,15 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ if (itr != objects.end()) { // We found a ready object, acquire it and set the result value - Kernel::WaitObject* object = itr->get(); + WaitObject* object = itr->get(); object->Acquire(thread); *index = static_cast(std::distance(objects.begin(), itr)); - if (object->GetHandleType() != Kernel::HandleType::ServerSession) + if (object->GetHandleType() != HandleType::ServerSession) return RESULT_SUCCESS; - auto server_session = static_cast(object); - return ReceiveIPCRequest(server_session, Kernel::GetCurrentThread()); + auto server_session = static_cast(object); + return ReceiveIPCRequest(server_session, GetCurrentThread()); } // No objects were ready to be acquired, prepare to suspend the thread. @@ -574,23 +553,22 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ // Add the thread to each of the objects' waiting threads. for (size_t i = 0; i < objects.size(); ++i) { - Kernel::WaitObject* object = objects[i].get(); + WaitObject* object = objects[i].get(); object->AddWaitingThread(thread); } thread->wait_objects = std::move(objects); - thread->wakeup_callback = [](ThreadWakeupReason reason, - Kernel::SharedPtr thread, - Kernel::SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, + SharedPtr object) { ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ANY); ASSERT(reason == ThreadWakeupReason::Signal); ResultCode result = RESULT_SUCCESS; - if (object->GetHandleType() == Kernel::HandleType::ServerSession) { - auto server_session = Kernel::DynamicObjectCast(object); + if (object->GetHandleType() == HandleType::ServerSession) { + auto server_session = DynamicObjectCast(object); result = ReceiveIPCRequest(server_session, thread); } @@ -608,30 +586,25 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ } /// Create an address arbiter (to allocate access to shared resources) -static ResultCode CreateAddressArbiter(Kernel::Handle* out_handle) { - using Kernel::AddressArbiter; - +static ResultCode CreateAddressArbiter(Handle* out_handle) { SharedPtr arbiter = AddressArbiter::Create(); - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(arbiter))); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(arbiter))); LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *out_handle); return RESULT_SUCCESS; } /// Arbitrate address -static ResultCode ArbitrateAddress(Kernel::Handle handle, u32 address, u32 type, u32 value, +static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { - using Kernel::AddressArbiter; - LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle, address, type, value); - SharedPtr arbiter = Kernel::g_handle_table.Get(handle); + SharedPtr arbiter = g_handle_table.Get(handle); if (arbiter == nullptr) return ERR_INVALID_HANDLE; - auto res = arbiter->ArbitrateAddress(Kernel::GetCurrentThread(), - static_cast(type), address, value, - nanoseconds); + auto res = arbiter->ArbitrateAddress(GetCurrentThread(), static_cast(type), + address, value, nanoseconds); // TODO(Subv): Identify in which specific cases this call should cause a reschedule. Core::System::GetInstance().PrepareReschedule(); @@ -667,27 +640,26 @@ static void OutputDebugString(VAddr address, int len) { } /// Get resource limit -static ResultCode GetResourceLimit(Kernel::Handle* resource_limit, Kernel::Handle process_handle) { +static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); - SharedPtr process = - Kernel::g_handle_table.Get(process_handle); + SharedPtr process = g_handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; - CASCADE_RESULT(*resource_limit, Kernel::g_handle_table.Create(process->resource_limit)); + CASCADE_RESULT(*resource_limit, g_handle_table.Create(process->resource_limit)); return RESULT_SUCCESS; } /// Get resource limit current values -static ResultCode GetResourceLimitCurrentValues(VAddr values, Kernel::Handle resource_limit_handle, +static ResultCode GetResourceLimitCurrentValues(VAddr values, Handle resource_limit_handle, VAddr names, u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%08X, name_count=%d", resource_limit_handle, names, name_count); - SharedPtr resource_limit = - Kernel::g_handle_table.Get(resource_limit_handle); + SharedPtr resource_limit = + g_handle_table.Get(resource_limit_handle); if (resource_limit == nullptr) return ERR_INVALID_HANDLE; @@ -701,13 +673,13 @@ static ResultCode GetResourceLimitCurrentValues(VAddr values, Kernel::Handle res } /// Get resource limit max values -static ResultCode GetResourceLimitLimitValues(VAddr values, Kernel::Handle resource_limit_handle, +static ResultCode GetResourceLimitLimitValues(VAddr values, Handle resource_limit_handle, VAddr names, u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%08X, name_count=%d", resource_limit_handle, names, name_count); - SharedPtr resource_limit = - Kernel::g_handle_table.Get(resource_limit_handle); + SharedPtr resource_limit = + g_handle_table.Get(resource_limit_handle); if (resource_limit == nullptr) return ERR_INVALID_HANDLE; @@ -721,25 +693,22 @@ static ResultCode GetResourceLimitLimitValues(VAddr values, Kernel::Handle resou } /// Creates a new thread -static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 entry_point, u32 arg, +static ResultCode CreateThread(Handle* out_handle, u32 priority, u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { - using Kernel::Thread; - std::string name = Common::StringFromFormat("unknown-%08" PRIX32, entry_point); if (priority > THREADPRIO_LOWEST) { - return Kernel::ERR_OUT_OF_RANGE; + return ERR_OUT_OF_RANGE; } - using Kernel::ResourceLimit; - Kernel::SharedPtr& resource_limit = Kernel::g_current_process->resource_limit; - if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { - return Kernel::ERR_NOT_AUTHORIZED; + SharedPtr& resource_limit = g_current_process->resource_limit; + if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { + return ERR_NOT_AUTHORIZED; } if (processor_id == THREADPROCESSORID_DEFAULT) { // Set the target CPU to the one specified in the process' exheader. - processor_id = Kernel::g_current_process->ideal_processor; + processor_id = g_current_process->ideal_processor; ASSERT(processor_id != THREADPROCESSORID_DEFAULT); } @@ -761,13 +730,13 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 ent } CASCADE_RESULT(SharedPtr thread, - Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, - Kernel::g_current_process)); + Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, + g_current_process)); thread->context.fpscr = FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000 - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(thread))); Core::System::GetInstance().PrepareReschedule(); @@ -782,13 +751,13 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 ent static void ExitThread() { LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::CPU().GetPC()); - Kernel::ExitCurrentThread(); + ExitCurrentThread(); Core::System::GetInstance().PrepareReschedule(); } /// Gets the priority for the specified thread -static ResultCode GetThreadPriority(u32* priority, Kernel::Handle handle) { - const SharedPtr thread = Kernel::g_handle_table.Get(handle); +static ResultCode GetThreadPriority(u32* priority, Handle handle) { + const SharedPtr thread = g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -797,21 +766,20 @@ static ResultCode GetThreadPriority(u32* priority, Kernel::Handle handle) { } /// Sets the priority for the specified thread -static ResultCode SetThreadPriority(Kernel::Handle handle, u32 priority) { +static ResultCode SetThreadPriority(Handle handle, u32 priority) { if (priority > THREADPRIO_LOWEST) { - return Kernel::ERR_OUT_OF_RANGE; + return ERR_OUT_OF_RANGE; } - SharedPtr thread = Kernel::g_handle_table.Get(handle); + SharedPtr thread = g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; - using Kernel::ResourceLimit; // Note: The kernel uses the current process's resource limit instead of // the one from the thread owner's resource limit. - Kernel::SharedPtr& resource_limit = Kernel::g_current_process->resource_limit; - if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { - return Kernel::ERR_NOT_AUTHORIZED; + SharedPtr& resource_limit = g_current_process->resource_limit; + if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { + return ERR_NOT_AUTHORIZED; } thread->SetPriority(priority); @@ -826,12 +794,10 @@ static ResultCode SetThreadPriority(Kernel::Handle handle, u32 priority) { } /// Create a mutex -static ResultCode CreateMutex(Kernel::Handle* out_handle, u32 initial_locked) { - using Kernel::Mutex; - +static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { SharedPtr mutex = Mutex::Create(initial_locked != 0); mutex->name = Common::StringFromFormat("mutex-%08x", Core::CPU().GetReg(14)); - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(mutex))); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", initial_locked ? "true" : "false", *out_handle); @@ -840,24 +806,21 @@ static ResultCode CreateMutex(Kernel::Handle* out_handle, u32 initial_locked) { } /// Release a mutex -static ResultCode ReleaseMutex(Kernel::Handle handle) { - using Kernel::Mutex; - +static ResultCode ReleaseMutex(Handle handle) { LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle); - SharedPtr mutex = Kernel::g_handle_table.Get(handle); + SharedPtr mutex = g_handle_table.Get(handle); if (mutex == nullptr) return ERR_INVALID_HANDLE; - return mutex->Release(Kernel::GetCurrentThread()); + return mutex->Release(GetCurrentThread()); } /// Get the ID of the specified process -static ResultCode GetProcessId(u32* process_id, Kernel::Handle process_handle) { +static ResultCode GetProcessId(u32* process_id, Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); - const SharedPtr process = - Kernel::g_handle_table.Get(process_handle); + const SharedPtr process = g_handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -866,15 +829,14 @@ static ResultCode GetProcessId(u32* process_id, Kernel::Handle process_handle) { } /// Get the ID of the process that owns the specified thread -static ResultCode GetProcessIdOfThread(u32* process_id, Kernel::Handle thread_handle) { +static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); - const SharedPtr thread = - Kernel::g_handle_table.Get(thread_handle); + const SharedPtr thread = g_handle_table.Get(thread_handle); if (thread == nullptr) return ERR_INVALID_HANDLE; - const SharedPtr process = thread->owner_process; + const SharedPtr process = thread->owner_process; ASSERT_MSG(process != nullptr, "Invalid parent process for thread=0x%08X", thread_handle); @@ -883,10 +845,10 @@ static ResultCode GetProcessIdOfThread(u32* process_id, Kernel::Handle thread_ha } /// Get the ID for the specified thread. -static ResultCode GetThreadId(u32* thread_id, Kernel::Handle handle) { +static ResultCode GetThreadId(u32* thread_id, Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); - const SharedPtr thread = Kernel::g_handle_table.Get(handle); + const SharedPtr thread = g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -895,12 +857,10 @@ static ResultCode GetThreadId(u32* thread_id, Kernel::Handle handle) { } /// Creates a semaphore -static ResultCode CreateSemaphore(Kernel::Handle* out_handle, s32 initial_count, s32 max_count) { - using Kernel::Semaphore; - +static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) { CASCADE_RESULT(SharedPtr semaphore, Semaphore::Create(initial_count, max_count)); semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::CPU().GetReg(14)); - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore))); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(semaphore))); LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", initial_count, max_count, *out_handle); @@ -908,12 +868,10 @@ static ResultCode CreateSemaphore(Kernel::Handle* out_handle, s32 initial_count, } /// Releases a certain number of slots in a semaphore -static ResultCode ReleaseSemaphore(s32* count, Kernel::Handle handle, s32 release_count) { - using Kernel::Semaphore; - +static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle); - SharedPtr semaphore = Kernel::g_handle_table.Get(handle); + SharedPtr semaphore = g_handle_table.Get(handle); if (semaphore == nullptr) return ERR_INVALID_HANDLE; @@ -924,16 +882,15 @@ static ResultCode ReleaseSemaphore(s32* count, Kernel::Handle handle, s32 releas /// Query process memory static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, - Kernel::Handle process_handle, u32 addr) { - using Kernel::Process; - Kernel::SharedPtr process = Kernel::g_handle_table.Get(process_handle); + Handle process_handle, u32 addr) { + SharedPtr process = g_handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; auto vma = process->vm_manager.FindVMA(addr); - if (vma == Kernel::g_current_process->vm_manager.vma_map.end()) - return Kernel::ERR_INVALID_ADDRESS; + if (vma == g_current_process->vm_manager.vma_map.end()) + return ERR_INVALID_ADDRESS; memory_info->base_address = vma->second.base; memory_info->permission = static_cast(vma->second.permissions); @@ -947,16 +904,14 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_inf /// Query memory static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, u32 addr) { - return QueryProcessMemory(memory_info, page_info, Kernel::CurrentProcess, addr); + return QueryProcessMemory(memory_info, page_info, CurrentProcess, addr); } /// Create an event -static ResultCode CreateEvent(Kernel::Handle* out_handle, u32 reset_type) { - using Kernel::Event; - - SharedPtr evt = Event::Create(static_cast(reset_type)); +static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { + SharedPtr evt = Event::Create(static_cast(reset_type)); evt->name = Common::StringFromFormat("event-%08x", Core::CPU().GetReg(14)); - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(evt))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *out_handle); @@ -964,18 +919,17 @@ static ResultCode CreateEvent(Kernel::Handle* out_handle, u32 reset_type) { } /// Duplicates a kernel handle -static ResultCode DuplicateHandle(Kernel::Handle* out, Kernel::Handle handle) { - CASCADE_RESULT(*out, Kernel::g_handle_table.Duplicate(handle)); +static ResultCode DuplicateHandle(Handle* out, Handle handle) { + CASCADE_RESULT(*out, g_handle_table.Duplicate(handle)); LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out); return RESULT_SUCCESS; } /// Signals an event -static ResultCode SignalEvent(Kernel::Handle handle) { - using Kernel::Event; +static ResultCode SignalEvent(Handle handle) { LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); - SharedPtr evt = Kernel::g_handle_table.Get(handle); + SharedPtr evt = g_handle_table.Get(handle); if (evt == nullptr) return ERR_INVALID_HANDLE; @@ -985,11 +939,10 @@ static ResultCode SignalEvent(Kernel::Handle handle) { } /// Clears an event -static ResultCode ClearEvent(Kernel::Handle handle) { - using Kernel::Event; +static ResultCode ClearEvent(Handle handle) { LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); - SharedPtr evt = Kernel::g_handle_table.Get(handle); + SharedPtr evt = g_handle_table.Get(handle); if (evt == nullptr) return ERR_INVALID_HANDLE; @@ -998,12 +951,10 @@ static ResultCode ClearEvent(Kernel::Handle handle) { } /// Creates a timer -static ResultCode CreateTimer(Kernel::Handle* out_handle, u32 reset_type) { - using Kernel::Timer; - - SharedPtr timer = Timer::Create(static_cast(reset_type)); +static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { + SharedPtr timer = Timer::Create(static_cast(reset_type)); timer->name = Common::StringFromFormat("timer-%08x", Core::CPU().GetReg(14)); - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(timer))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *out_handle); @@ -1011,12 +962,10 @@ static ResultCode CreateTimer(Kernel::Handle* out_handle, u32 reset_type) { } /// Clears a timer -static ResultCode ClearTimer(Kernel::Handle handle) { - using Kernel::Timer; - +static ResultCode ClearTimer(Handle handle) { LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); - SharedPtr timer = Kernel::g_handle_table.Get(handle); + SharedPtr timer = g_handle_table.Get(handle); if (timer == nullptr) return ERR_INVALID_HANDLE; @@ -1025,16 +974,14 @@ static ResultCode ClearTimer(Kernel::Handle handle) { } /// Starts a timer -static ResultCode SetTimer(Kernel::Handle handle, s64 initial, s64 interval) { - using Kernel::Timer; - +static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); if (initial < 0 || interval < 0) { - return Kernel::ERR_OUT_OF_RANGE_KERNEL; + return ERR_OUT_OF_RANGE_KERNEL; } - SharedPtr timer = Kernel::g_handle_table.Get(handle); + SharedPtr timer = g_handle_table.Get(handle); if (timer == nullptr) return ERR_INVALID_HANDLE; @@ -1044,12 +991,10 @@ static ResultCode SetTimer(Kernel::Handle handle, s64 initial, s64 interval) { } /// Cancels a timer -static ResultCode CancelTimer(Kernel::Handle handle) { - using Kernel::Timer; - +static ResultCode CancelTimer(Handle handle) { LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); - SharedPtr timer = Kernel::g_handle_table.Get(handle); + SharedPtr timer = g_handle_table.Get(handle); if (timer == nullptr) return ERR_INVALID_HANDLE; @@ -1064,14 +1009,14 @@ static void SleepThread(s64 nanoseconds) { // Don't attempt to yield execution if there are no available threads to run, // this way we avoid a useless reschedule to the idle thread. - if (nanoseconds == 0 && !Kernel::HaveReadyThreads()) + if (nanoseconds == 0 && !HaveReadyThreads()) return; // Sleep current thread and check for next thread to schedule - Kernel::WaitCurrentThread_Sleep(); + WaitCurrentThread_Sleep(); // Create an event to wake the thread up after the specified nanosecond delay has passed - Kernel::GetCurrentThread()->WakeAfterDelay(nanoseconds); + GetCurrentThread()->WakeAfterDelay(nanoseconds); Core::System::GetInstance().PrepareReschedule(); } @@ -1085,16 +1030,13 @@ static s64 GetSystemTick() { } /// Creates a memory block at the specified address with the specified permissions and size -static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 size, - u32 my_permission, u32 other_permission) { - using Kernel::SharedMemory; - +static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, + u32 other_permission) { if (size % Memory::PAGE_SIZE != 0) - return Kernel::ERR_MISALIGNED_SIZE; + return ERR_MISALIGNED_SIZE; SharedPtr shared_memory = nullptr; - using Kernel::MemoryPermission; auto VerifyPermissions = [](MemoryPermission permission) { // SharedMemory blocks can not be created with Execute permissions switch (permission) { @@ -1111,109 +1053,102 @@ static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 si if (!VerifyPermissions(static_cast(my_permission)) || !VerifyPermissions(static_cast(other_permission))) - return Kernel::ERR_INVALID_COMBINATION; + return ERR_INVALID_COMBINATION; // TODO(Subv): Processes with memory type APPLICATION are not allowed // to create memory blocks with addr = 0, any attempts to do so // should return error 0xD92007EA. if ((addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) && addr != 0) { - return Kernel::ERR_INVALID_ADDRESS; + return ERR_INVALID_ADDRESS; } // When trying to create a memory block with address = 0, // if the process has the Shared Device Memory flag in the exheader, // then we have to allocate from the same region as the caller process instead of the BASE // region. - Kernel::MemoryRegion region = Kernel::MemoryRegion::BASE; - if (addr == 0 && Kernel::g_current_process->flags.shared_device_mem) - region = Kernel::g_current_process->flags.memory_region; + MemoryRegion region = MemoryRegion::BASE; + if (addr == 0 && g_current_process->flags.shared_device_mem) + region = g_current_process->flags.memory_region; - shared_memory = SharedMemory::Create( - Kernel::g_current_process, size, static_cast(my_permission), - static_cast(other_permission), addr, region); - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); + shared_memory = + SharedMemory::Create(g_current_process, size, static_cast(my_permission), + static_cast(other_permission), addr, region); + CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(shared_memory))); LOG_WARNING(Kernel_SVC, "called addr=0x%08X", addr); return RESULT_SUCCESS; } -static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client_port, - VAddr name_address, u32 max_sessions) { +static ResultCode CreatePort(Handle* server_port, Handle* client_port, VAddr name_address, + u32 max_sessions) { // TODO(Subv): Implement named ports. ASSERT_MSG(name_address == 0, "Named ports are currently unimplemented"); - using Kernel::ServerPort; - using Kernel::ClientPort; - auto ports = ServerPort::CreatePortPair(max_sessions); - CASCADE_RESULT(*client_port, Kernel::g_handle_table.Create( - std::move(std::get>(ports)))); + CASCADE_RESULT(*client_port, + g_handle_table.Create(std::move(std::get>(ports)))); // Note: The 3DS kernel also leaks the client port handle if the server port handle fails to be // created. - CASCADE_RESULT(*server_port, Kernel::g_handle_table.Create( - std::move(std::get>(ports)))); + CASCADE_RESULT(*server_port, + g_handle_table.Create(std::move(std::get>(ports)))); LOG_TRACE(Kernel_SVC, "called max_sessions=%u", max_sessions); return RESULT_SUCCESS; } static ResultCode CreateSessionToPort(Handle* out_client_session, Handle client_port_handle) { - using Kernel::ClientPort; - SharedPtr client_port = Kernel::g_handle_table.Get(client_port_handle); + SharedPtr client_port = g_handle_table.Get(client_port_handle); if (client_port == nullptr) return ERR_INVALID_HANDLE; CASCADE_RESULT(auto session, client_port->Connect()); - CASCADE_RESULT(*out_client_session, Kernel::g_handle_table.Create(std::move(session))); + CASCADE_RESULT(*out_client_session, g_handle_table.Create(std::move(session))); return RESULT_SUCCESS; } static ResultCode CreateSession(Handle* server_session, Handle* client_session) { - auto sessions = Kernel::ServerSession::CreateSessionPair(); + auto sessions = ServerSession::CreateSessionPair(); - auto& server = std::get>(sessions); - CASCADE_RESULT(*server_session, Kernel::g_handle_table.Create(std::move(server))); + auto& server = std::get>(sessions); + CASCADE_RESULT(*server_session, g_handle_table.Create(std::move(server))); - auto& client = std::get>(sessions); - CASCADE_RESULT(*client_session, Kernel::g_handle_table.Create(std::move(client))); + auto& client = std::get>(sessions); + CASCADE_RESULT(*client_session, g_handle_table.Create(std::move(client))); LOG_TRACE(Kernel_SVC, "called"); return RESULT_SUCCESS; } static ResultCode AcceptSession(Handle* out_server_session, Handle server_port_handle) { - using Kernel::ServerPort; - SharedPtr server_port = Kernel::g_handle_table.Get(server_port_handle); + SharedPtr server_port = g_handle_table.Get(server_port_handle); if (server_port == nullptr) return ERR_INVALID_HANDLE; CASCADE_RESULT(auto session, server_port->Accept()); - CASCADE_RESULT(*out_server_session, Kernel::g_handle_table.Create(std::move(session))); + CASCADE_RESULT(*out_server_session, g_handle_table.Create(std::move(session))); return RESULT_SUCCESS; } static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { - using Kernel::MemoryRegion; - LOG_TRACE(Kernel_SVC, "called type=%u param=%d", type, param); switch ((SystemInfoType)type) { case SystemInfoType::REGION_MEMORY_USAGE: switch ((SystemInfoMemUsageRegion)param) { case SystemInfoMemUsageRegion::ALL: - *out = Kernel::GetMemoryRegion(Kernel::MemoryRegion::APPLICATION)->used + - Kernel::GetMemoryRegion(Kernel::MemoryRegion::SYSTEM)->used + - Kernel::GetMemoryRegion(Kernel::MemoryRegion::BASE)->used; + *out = GetMemoryRegion(MemoryRegion::APPLICATION)->used + + GetMemoryRegion(MemoryRegion::SYSTEM)->used + + GetMemoryRegion(MemoryRegion::BASE)->used; break; case SystemInfoMemUsageRegion::APPLICATION: - *out = Kernel::GetMemoryRegion(Kernel::MemoryRegion::APPLICATION)->used; + *out = GetMemoryRegion(MemoryRegion::APPLICATION)->used; break; case SystemInfoMemUsageRegion::SYSTEM: - *out = Kernel::GetMemoryRegion(Kernel::MemoryRegion::SYSTEM)->used; + *out = GetMemoryRegion(MemoryRegion::SYSTEM)->used; break; case SystemInfoMemUsageRegion::BASE: - *out = Kernel::GetMemoryRegion(Kernel::MemoryRegion::BASE)->used; + *out = GetMemoryRegion(MemoryRegion::BASE)->used; break; default: LOG_ERROR(Kernel_SVC, "unknown GetSystemInfo type=0 region: param=%d", param); @@ -1238,11 +1173,10 @@ static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { return RESULT_SUCCESS; } -static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 type) { +static ResultCode GetProcessInfo(s64* out, Handle process_handle, u32 type) { LOG_TRACE(Kernel_SVC, "called process=0x%08X type=%u", process_handle, type); - using Kernel::Process; - Kernel::SharedPtr process = Kernel::g_handle_table.Get(process_handle); + SharedPtr process = g_handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -1254,7 +1188,7 @@ static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 ty *out = process->heap_used + process->linear_heap_used + process->misc_memory_used; if (*out % Memory::PAGE_SIZE != 0) { LOG_ERROR(Kernel_SVC, "called, memory size not page-aligned"); - return Kernel::ERR_MISALIGNED_SIZE; + return ERR_MISALIGNED_SIZE; } break; case 1: @@ -1275,10 +1209,10 @@ static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 ty case 23: // These return a different error value than higher invalid values LOG_ERROR(Kernel_SVC, "unknown GetProcessInfo type=%u", type); - return Kernel::ERR_NOT_IMPLEMENTED; + return ERR_NOT_IMPLEMENTED; default: LOG_ERROR(Kernel_SVC, "unknown GetProcessInfo type=%u", type); - return Kernel::ERR_INVALID_ENUM_VALUE; + return ERR_INVALID_ENUM_VALUE; } return RESULT_SUCCESS; @@ -1449,4 +1383,4 @@ void CallSVC(u32 immediate) { } } -} // namespace SVC +} // namespace Kernel diff --git a/src/core/hle/kernel/svc.h b/src/core/hle/kernel/svc.h index 818973eb67..94f1933f51 100644 --- a/src/core/hle/kernel/svc.h +++ b/src/core/hle/kernel/svc.h @@ -6,8 +6,7 @@ #include "common/common_types.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// SVC types +namespace Kernel { struct MemoryInfo { u32 base_address; @@ -20,11 +19,6 @@ struct PageInfo { u32 flags; }; -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Namespace SVC - -namespace SVC { - /// Values accepted by svcGetSystemInfo's type parameter. enum class SystemInfoType { /** @@ -56,4 +50,4 @@ enum class SystemInfoMemUsageRegion { void CallSVC(u32 immediate); -} // namespace +} // namespace Kernel