diff options
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r-- | src/core/hle/svc.cpp | 518 |
1 files changed, 279 insertions, 239 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 5d71d5619..02b397eba 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -3,16 +3,14 @@ // Refer to the license.txt file included. #include <map> - #include "common/logging/log.h" #include "common/microprofile.h" #include "common/scope_exit.h" #include "common/string_util.h" #include "common/symbols.h" - -#include "core/core_timing.h" #include "core/arm/arm_interface.h" - +#include "core/core_timing.h" +#include "core/hle/function_wrappers.h" #include "core/hle/kernel/address_arbiter.h" #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/event.h" @@ -26,8 +24,6 @@ #include "core/hle/kernel/thread.h" #include "core/hle/kernel/timer.h" #include "core/hle/kernel/vm_manager.h" - -#include "core/hle/function_wrappers.h" #include "core/hle/result.h" #include "core/hle/service/service.h" @@ -40,43 +36,46 @@ using Kernel::ERR_INVALID_HANDLE; namespace SVC { const ResultCode ERR_NOT_FOUND(ErrorDescription::NotFound, ErrorModule::Kernel, - ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA + ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA const ResultCode ERR_PORT_NAME_TOO_LONG(ErrorDescription(30), ErrorModule::OS, - ErrorSummary::InvalidArgument, ErrorLevel::Usage); // 0xE0E0181E - -const ResultCode ERR_MISALIGNED_ADDRESS{ // 0xE0E01BF1 - ErrorDescription::MisalignedAddress, ErrorModule::OS, - ErrorSummary::InvalidArgument, ErrorLevel::Usage}; -const ResultCode ERR_MISALIGNED_SIZE{ // 0xE0E01BF2 - ErrorDescription::MisalignedSize, ErrorModule::OS, - ErrorSummary::InvalidArgument, ErrorLevel::Usage}; -const ResultCode ERR_INVALID_COMBINATION{ // 0xE0E01BEE - ErrorDescription::InvalidCombination, ErrorModule::OS, - ErrorSummary::InvalidArgument, ErrorLevel::Usage}; + ErrorSummary::InvalidArgument, + ErrorLevel::Usage); // 0xE0E0181E + +const ResultCode ERR_MISALIGNED_ADDRESS{// 0xE0E01BF1 + ErrorDescription::MisalignedAddress, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage}; +const ResultCode ERR_MISALIGNED_SIZE{// 0xE0E01BF2 + ErrorDescription::MisalignedSize, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage}; +const ResultCode ERR_INVALID_COMBINATION{// 0xE0E01BEE + ErrorDescription::InvalidCombination, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage}; enum ControlMemoryOperation { - MEMOP_FREE = 1, + MEMOP_FREE = 1, MEMOP_RESERVE = 2, // This operation seems to be unsupported in the kernel - MEMOP_COMMIT = 3, - MEMOP_MAP = 4, - MEMOP_UNMAP = 5, + MEMOP_COMMIT = 3, + MEMOP_MAP = 4, + MEMOP_UNMAP = 5, MEMOP_PROTECT = 6, MEMOP_OPERATION_MASK = 0xFF, - MEMOP_REGION_APP = 0x100, + MEMOP_REGION_APP = 0x100, MEMOP_REGION_SYSTEM = 0x200, - MEMOP_REGION_BASE = 0x300, - MEMOP_REGION_MASK = 0xF00, + MEMOP_REGION_BASE = 0x300, + MEMOP_REGION_MASK = 0xF00, MEMOP_LINEAR = 0x10000, }; /// Map application or GSP heap memory -static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { +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); + 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); if ((addr0 & Memory::PAGE_MASK) != 0 || (addr1 & Memory::PAGE_MASK) != 0) { return ERR_MISALIGNED_ADDRESS; @@ -89,7 +88,8 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add operation &= ~MEMOP_REGION_MASK; if (region != 0) { - LOG_WARNING(Kernel_SVC, "ControlMemory with specified region not supported, region=%X", region); + LOG_WARNING(Kernel_SVC, "ControlMemory with specified region not supported, region=%X", + region); } if ((permissions & (u32)MemoryPermission::ReadWrite) != permissions) { @@ -100,15 +100,17 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add auto& process = *g_current_process; switch (operation & MEMOP_OPERATION_MASK) { - case MEMOP_FREE: - { - // TODO(Subv): What happens if an application tries to FREE a block of memory that has a SharedMemory pointing to it? + case MEMOP_FREE: { + // TODO(Subv): What happens if an application tries to FREE a block of memory that has a + // SharedMemory pointing to it? if (addr0 >= Memory::HEAP_VADDR && addr0 < Memory::HEAP_VADDR_END) { ResultCode result = process.HeapFree(addr0, size); - if (result.IsError()) return result; + if (result.IsError()) + return result; } else if (addr0 >= process.GetLinearHeapBase() && addr0 < process.GetLinearHeapLimit()) { ResultCode result = process.LinearFree(addr0, size); - if (result.IsError()) return result; + if (result.IsError()) + return result; } else { return ERR_INVALID_ADDRESS; } @@ -116,8 +118,7 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add break; } - case MEMOP_COMMIT: - { + case MEMOP_COMMIT: { if (operation & MEMOP_LINEAR) { CASCADE_RESULT(*out_addr, process.LinearAllocate(addr0, size, vma_permissions)); } else { @@ -126,23 +127,26 @@ 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: - { + case MEMOP_PROTECT: { ResultCode result = process.vm_manager.ReprotectRange(addr0, size, vma_permissions); - if (result.IsError()) return result; + if (result.IsError()) + return result; break; } @@ -161,8 +165,9 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o using Kernel::SharedMemory; using Kernel::MemoryPermission; - LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", - handle, addr, permissions, other_permissions); + LOG_TRACE(Kernel_SVC, + "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", + handle, addr, permissions, other_permissions); SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); if (shared_memory == nullptr) @@ -179,12 +184,13 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o case MemoryPermission::ReadWriteExecute: case MemoryPermission::DontCare: return shared_memory->Map(Kernel::g_current_process.get(), addr, permissions_type, - static_cast<MemoryPermission>(other_permissions)); + static_cast<MemoryPermission>(other_permissions)); default: LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); } - return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); + return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); } static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { @@ -249,7 +255,7 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { return ERR_INVALID_HANDLE; LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, - object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds); + object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds); HLE::Reschedule(__func__); @@ -257,7 +263,7 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { if (object->ShouldWait()) { object->AddWaitingThread(thread); - Kernel::WaitCurrentThread_WaitSynchronization({ object }, false, false); + Kernel::WaitCurrentThread_WaitSynchronization({object}, false, false); // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); @@ -272,7 +278,8 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { } /// Wait for the given handles to synchronize, timeout after the specified nanoseconds -static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, s64 nano_seconds) { +static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, + s64 nano_seconds) { bool wait_thread = !wait_all; int handle_index = 0; Kernel::Thread* thread = Kernel::GetCurrentThread(); @@ -281,7 +288,8 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou // Check if 'handles' is invalid if (handles == nullptr) - return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent); + return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, + ErrorSummary::InvalidArgument, ErrorLevel::Permanent); // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If // this happens, the running application will crash. @@ -289,7 +297,8 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou // Check if 'handle_count' is invalid if (handle_count < 0) - return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); + return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); // If 'handle_count' is non-zero, iterate through each handle and wait the current thread if // necessary @@ -329,7 +338,9 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou } } - SCOPE_EXIT({HLE::Reschedule("WaitSynchronizationN");}); // Reschedule after putting the threads to sleep. + SCOPE_EXIT({ + HLE::Reschedule("WaitSynchronizationN"); + }); // Reschedule after putting the threads to sleep. // If thread should wait, then set its state to waiting if (wait_thread) { @@ -386,18 +397,19 @@ static ResultCode CreateAddressArbiter(Handle* out_handle) { } /// Arbitrate address -static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { +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); + address, type, value); SharedPtr<AddressArbiter> arbiter = Kernel::g_handle_table.Get<AddressArbiter>(handle); if (arbiter == nullptr) return ERR_INVALID_HANDLE; - auto res = arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), - address, value, nanoseconds); + auto res = arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), address, value, + nanoseconds); return res; } @@ -406,10 +418,18 @@ static void Break(u8 break_reason) { LOG_CRITICAL(Debug_Emulated, "Emulated program broke execution!"); std::string reason_str; switch (break_reason) { - case 0: reason_str = "PANIC"; break; - case 1: reason_str = "ASSERT"; break; - case 2: reason_str = "USER"; break; - default: reason_str = "UNKNOWN"; break; + case 0: + reason_str = "PANIC"; + break; + case 1: + reason_str = "ASSERT"; + break; + case 2: + reason_str = "USER"; + break; + default: + reason_str = "UNKNOWN"; + break; } LOG_CRITICAL(Debug_Emulated, "Break reason: %s", reason_str.c_str()); } @@ -423,7 +443,8 @@ static void OutputDebugString(const char* string) { static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); - SharedPtr<Kernel::Process> process = Kernel::g_handle_table.Get<Kernel::Process>(process_handle); + SharedPtr<Kernel::Process> process = + Kernel::g_handle_table.Get<Kernel::Process>(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -433,12 +454,13 @@ static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle } /// Get resource limit current values -static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit_handle, u32* names, - u32 name_count) { +static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit_handle, + u32* names, u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", - resource_limit_handle, names, name_count); + resource_limit_handle, names, name_count); - SharedPtr<Kernel::ResourceLimit> resource_limit = Kernel::g_handle_table.Get<Kernel::ResourceLimit>(resource_limit_handle); + SharedPtr<Kernel::ResourceLimit> resource_limit = + Kernel::g_handle_table.Get<Kernel::ResourceLimit>(resource_limit_handle); if (resource_limit == nullptr) return ERR_INVALID_HANDLE; @@ -450,11 +472,12 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim /// Get resource limit max values static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit_handle, u32* names, - u32 name_count) { + u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", - resource_limit_handle, names, name_count); + resource_limit_handle, names, name_count); - SharedPtr<Kernel::ResourceLimit> resource_limit = Kernel::g_handle_table.Get<Kernel::ResourceLimit>(resource_limit_handle); + SharedPtr<Kernel::ResourceLimit> resource_limit = + Kernel::g_handle_table.Get<Kernel::ResourceLimit>(resource_limit_handle); if (resource_limit == nullptr) return ERR_INVALID_HANDLE; @@ -465,7 +488,8 @@ static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit } /// Creates a new thread -static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { +static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, + u32 stack_top, s32 processor_id) { using Kernel::Thread; std::string name; @@ -499,20 +523,23 @@ static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point } if (processor_id == THREADPROCESSORID_1 || processor_id == THREADPROCESSORID_ALL || - (processor_id == THREADPROCESSORID_DEFAULT && Kernel::g_current_process->ideal_processor == THREADPROCESSORID_1)) { - LOG_WARNING(Kernel_SVC, "Newly created thread is allowed to be run in the SysCore, unimplemented."); + (processor_id == THREADPROCESSORID_DEFAULT && + Kernel::g_current_process->ideal_processor == THREADPROCESSORID_1)) { + LOG_WARNING(Kernel_SVC, + "Newly created thread is allowed to be run in the SysCore, unimplemented."); } - CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create( - name, entry_point, priority, arg, processor_id, stack_top)); + CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create(name, entry_point, priority, + arg, processor_id, stack_top)); - thread->context.fpscr = FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000 + 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))); LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " - "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, - name.c_str(), arg, stack_top, priority, processor_id, *out_handle); + "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", + entry_point, name.c_str(), arg, stack_top, priority, processor_id, *out_handle); return RESULT_SUCCESS; } @@ -552,7 +579,7 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { CASCADE_RESULT(*out_handle, Kernel::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); + initial_locked ? "true" : "false", *out_handle); return RESULT_SUCCESS; } @@ -576,7 +603,8 @@ static ResultCode ReleaseMutex(Handle handle) { static ResultCode GetProcessId(u32* process_id, Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); - const SharedPtr<Kernel::Process> process = Kernel::g_handle_table.Get<Kernel::Process>(process_handle); + const SharedPtr<Kernel::Process> process = + Kernel::g_handle_table.Get<Kernel::Process>(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -588,7 +616,8 @@ static ResultCode GetProcessId(u32* process_id, Handle process_handle) { static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); - const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(thread_handle); + const SharedPtr<Kernel::Thread> thread = + Kernel::g_handle_table.Get<Kernel::Thread>(thread_handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -620,7 +649,7 @@ static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max CASCADE_RESULT(*out_handle, Kernel::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); + initial_count, max_count, *out_handle); return RESULT_SUCCESS; } @@ -640,7 +669,8 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) } /// Query process memory -static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, Handle process_handle, u32 addr) { +static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, + Handle process_handle, u32 addr) { using Kernel::Process; Kernel::SharedPtr<Process> process = Kernel::g_handle_table.Get<Process>(process_handle); if (process == nullptr) @@ -649,7 +679,8 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_inf auto vma = process->vm_manager.FindVMA(addr); if (vma == Kernel::g_current_process->vm_manager.vma_map.end()) - return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); + return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); memory_info->base_address = vma->second.base; memory_info->permission = static_cast<u32>(vma->second.permissions); @@ -673,8 +704,8 @@ static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { SharedPtr<Event> evt = Event::Create(static_cast<Kernel::ResetType>(reset_type)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); - LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", - reset_type, *out_handle); + LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, + *out_handle); return RESULT_SUCCESS; } @@ -719,8 +750,8 @@ static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { SharedPtr<Timer> timer = Timer::Create(static_cast<Kernel::ResetType>(reset_type)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); - LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", - reset_type, *out_handle); + LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, + *out_handle); return RESULT_SUCCESS; } @@ -783,17 +814,19 @@ static void SleepThread(s64 nanoseconds) { static s64 GetSystemTick() { s64 result = CoreTiming::GetTicks(); // Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end. - Core::g_app_core->AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b + Core::g_app_core->AddTicks( + 150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b return result; } /// Creates a memory block at the specified address with the specified permissions and size static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, - u32 other_permission) { + u32 other_permission) { using Kernel::SharedMemory; if (size % Memory::PAGE_SIZE != 0) - return ResultCode(ErrorDescription::MisalignedSize, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); + return ResultCode(ErrorDescription::MisalignedSize, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); SharedPtr<SharedMemory> shared_memory = nullptr; @@ -818,25 +851,29 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 ErrorSummary::InvalidArgument, ErrorLevel::Usage); if (addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) { - return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); + return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); } // 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. + // 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; - shared_memory = SharedMemory::Create(Kernel::g_current_process, size, - static_cast<MemoryPermission>(my_permission), static_cast<MemoryPermission>(other_permission), addr, region); + shared_memory = SharedMemory::Create( + Kernel::g_current_process, size, static_cast<MemoryPermission>(my_permission), + static_cast<MemoryPermission>(other_permission), addr, region); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); LOG_WARNING(Kernel_SVC, "called addr=0x%08X", addr); return RESULT_SUCCESS; } -static ResultCode CreatePort(Handle* server_port, Handle* client_port, const char* name, u32 max_sessions) { +static ResultCode CreatePort(Handle* server_port, Handle* client_port, const char* name, + u32 max_sessions) { // TODO(Subv): Implement named ports. ASSERT_MSG(name == nullptr, "Named ports are currently unimplemented"); @@ -845,9 +882,12 @@ static ResultCode CreatePort(Handle* server_port, Handle* client_port, const cha using Kernel::SharedPtr; auto ports = ServerPort::CreatePortPair(max_sessions); - CASCADE_RESULT(*client_port, Kernel::g_handle_table.Create(std::move(std::get<SharedPtr<ClientPort>>(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<SharedPtr<ServerPort>>(ports)))); + CASCADE_RESULT(*client_port, Kernel::g_handle_table.Create( + std::move(std::get<SharedPtr<ClientPort>>(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<SharedPtr<ServerPort>>(ports)))); LOG_TRACE(Kernel_SVC, "called max_sessions=%u", max_sessions); return RESULT_SUCCESS; @@ -862,9 +902,9 @@ static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { 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 = Kernel::GetMemoryRegion(Kernel::MemoryRegion::APPLICATION)->used + + Kernel::GetMemoryRegion(Kernel::MemoryRegion::SYSTEM)->used + + Kernel::GetMemoryRegion(Kernel::MemoryRegion::BASE)->used; break; case SystemInfoMemUsageRegion::APPLICATION: *out = Kernel::GetMemoryRegion(Kernel::MemoryRegion::APPLICATION)->used; @@ -912,7 +952,7 @@ static ResultCode GetProcessInfo(s64* out, Handle process_handle, u32 type) { // TODO(yuriks): Type 0 returns a slightly higher number than type 2, but I'm not sure // what's the difference between them. *out = process->heap_used + process->linear_heap_used + process->misc_memory_used; - if(*out % Memory::PAGE_SIZE != 0) { + if (*out % Memory::PAGE_SIZE != 0) { LOG_ERROR(Kernel_SVC, "called, memory size not page-aligned"); return ERR_MISALIGNED_SIZE; } @@ -935,12 +975,12 @@ static ResultCode GetProcessInfo(s64* out, Handle process_handle, u32 type) { if (type >= 21 && type <= 23) { return ResultCode( // 0xE0E01BF4 - ErrorDescription::NotImplemented, ErrorModule::OS, - ErrorSummary::InvalidArgument, ErrorLevel::Usage); + ErrorDescription::NotImplemented, ErrorModule::OS, ErrorSummary::InvalidArgument, + ErrorLevel::Usage); } else { return ResultCode( // 0xD8E007ED - ErrorDescription::InvalidEnumValue, ErrorModule::Kernel, - ErrorSummary::InvalidArgument, ErrorLevel::Permanent); + ErrorDescription::InvalidEnumValue, ErrorModule::Kernel, + ErrorSummary::InvalidArgument, ErrorLevel::Permanent); } break; } @@ -949,142 +989,142 @@ static ResultCode GetProcessInfo(s64* out, Handle process_handle, u32 type) { } namespace { - struct FunctionDef { - using Func = void(); +struct FunctionDef { + using Func = void(); - u32 id; - Func* func; - const char* name; - }; + u32 id; + Func* func; + const char* name; +}; } static const FunctionDef SVC_Table[] = { - {0x00, nullptr, "Unknown"}, - {0x01, HLE::Wrap<ControlMemory>, "ControlMemory"}, - {0x02, HLE::Wrap<QueryMemory>, "QueryMemory"}, - {0x03, nullptr, "ExitProcess"}, - {0x04, nullptr, "GetProcessAffinityMask"}, - {0x05, nullptr, "SetProcessAffinityMask"}, - {0x06, nullptr, "GetProcessIdealProcessor"}, - {0x07, nullptr, "SetProcessIdealProcessor"}, - {0x08, HLE::Wrap<CreateThread>, "CreateThread"}, - {0x09, ExitThread, "ExitThread"}, - {0x0A, HLE::Wrap<SleepThread>, "SleepThread"}, - {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"}, - {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"}, - {0x0D, nullptr, "GetThreadAffinityMask"}, - {0x0E, nullptr, "SetThreadAffinityMask"}, - {0x0F, nullptr, "GetThreadIdealProcessor"}, - {0x10, nullptr, "SetThreadIdealProcessor"}, - {0x11, nullptr, "GetCurrentProcessorNumber"}, - {0x12, nullptr, "Run"}, - {0x13, HLE::Wrap<CreateMutex>, "CreateMutex"}, - {0x14, HLE::Wrap<ReleaseMutex>, "ReleaseMutex"}, - {0x15, HLE::Wrap<CreateSemaphore>, "CreateSemaphore"}, - {0x16, HLE::Wrap<ReleaseSemaphore>, "ReleaseSemaphore"}, - {0x17, HLE::Wrap<CreateEvent>, "CreateEvent"}, - {0x18, HLE::Wrap<SignalEvent>, "SignalEvent"}, - {0x19, HLE::Wrap<ClearEvent>, "ClearEvent"}, - {0x1A, HLE::Wrap<CreateTimer>, "CreateTimer"}, - {0x1B, HLE::Wrap<SetTimer>, "SetTimer"}, - {0x1C, HLE::Wrap<CancelTimer>, "CancelTimer"}, - {0x1D, HLE::Wrap<ClearTimer>, "ClearTimer"}, - {0x1E, HLE::Wrap<CreateMemoryBlock>, "CreateMemoryBlock"}, - {0x1F, HLE::Wrap<MapMemoryBlock>, "MapMemoryBlock"}, - {0x20, HLE::Wrap<UnmapMemoryBlock>, "UnmapMemoryBlock"}, + {0x00, nullptr, "Unknown"}, + {0x01, HLE::Wrap<ControlMemory>, "ControlMemory"}, + {0x02, HLE::Wrap<QueryMemory>, "QueryMemory"}, + {0x03, nullptr, "ExitProcess"}, + {0x04, nullptr, "GetProcessAffinityMask"}, + {0x05, nullptr, "SetProcessAffinityMask"}, + {0x06, nullptr, "GetProcessIdealProcessor"}, + {0x07, nullptr, "SetProcessIdealProcessor"}, + {0x08, HLE::Wrap<CreateThread>, "CreateThread"}, + {0x09, ExitThread, "ExitThread"}, + {0x0A, HLE::Wrap<SleepThread>, "SleepThread"}, + {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"}, + {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"}, + {0x0D, nullptr, "GetThreadAffinityMask"}, + {0x0E, nullptr, "SetThreadAffinityMask"}, + {0x0F, nullptr, "GetThreadIdealProcessor"}, + {0x10, nullptr, "SetThreadIdealProcessor"}, + {0x11, nullptr, "GetCurrentProcessorNumber"}, + {0x12, nullptr, "Run"}, + {0x13, HLE::Wrap<CreateMutex>, "CreateMutex"}, + {0x14, HLE::Wrap<ReleaseMutex>, "ReleaseMutex"}, + {0x15, HLE::Wrap<CreateSemaphore>, "CreateSemaphore"}, + {0x16, HLE::Wrap<ReleaseSemaphore>, "ReleaseSemaphore"}, + {0x17, HLE::Wrap<CreateEvent>, "CreateEvent"}, + {0x18, HLE::Wrap<SignalEvent>, "SignalEvent"}, + {0x19, HLE::Wrap<ClearEvent>, "ClearEvent"}, + {0x1A, HLE::Wrap<CreateTimer>, "CreateTimer"}, + {0x1B, HLE::Wrap<SetTimer>, "SetTimer"}, + {0x1C, HLE::Wrap<CancelTimer>, "CancelTimer"}, + {0x1D, HLE::Wrap<ClearTimer>, "ClearTimer"}, + {0x1E, HLE::Wrap<CreateMemoryBlock>, "CreateMemoryBlock"}, + {0x1F, HLE::Wrap<MapMemoryBlock>, "MapMemoryBlock"}, + {0x20, HLE::Wrap<UnmapMemoryBlock>, "UnmapMemoryBlock"}, {0x21, HLE::Wrap<CreateAddressArbiter>, "CreateAddressArbiter"}, - {0x22, HLE::Wrap<ArbitrateAddress>, "ArbitrateAddress"}, - {0x23, HLE::Wrap<CloseHandle>, "CloseHandle"}, + {0x22, HLE::Wrap<ArbitrateAddress>, "ArbitrateAddress"}, + {0x23, HLE::Wrap<CloseHandle>, "CloseHandle"}, {0x24, HLE::Wrap<WaitSynchronization1>, "WaitSynchronization1"}, {0x25, HLE::Wrap<WaitSynchronizationN>, "WaitSynchronizationN"}, - {0x26, nullptr, "SignalAndWait"}, - {0x27, HLE::Wrap<DuplicateHandle>, "DuplicateHandle"}, - {0x28, HLE::Wrap<GetSystemTick>, "GetSystemTick"}, - {0x29, nullptr, "GetHandleInfo"}, - {0x2A, HLE::Wrap<GetSystemInfo>, "GetSystemInfo"}, - {0x2B, HLE::Wrap<GetProcessInfo>, "GetProcessInfo"}, - {0x2C, nullptr, "GetThreadInfo"}, - {0x2D, HLE::Wrap<ConnectToPort>, "ConnectToPort"}, - {0x2E, nullptr, "SendSyncRequest1"}, - {0x2F, nullptr, "SendSyncRequest2"}, - {0x30, nullptr, "SendSyncRequest3"}, - {0x31, nullptr, "SendSyncRequest4"}, - {0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"}, - {0x33, nullptr, "OpenProcess"}, - {0x34, nullptr, "OpenThread"}, - {0x35, HLE::Wrap<GetProcessId>, "GetProcessId"}, + {0x26, nullptr, "SignalAndWait"}, + {0x27, HLE::Wrap<DuplicateHandle>, "DuplicateHandle"}, + {0x28, HLE::Wrap<GetSystemTick>, "GetSystemTick"}, + {0x29, nullptr, "GetHandleInfo"}, + {0x2A, HLE::Wrap<GetSystemInfo>, "GetSystemInfo"}, + {0x2B, HLE::Wrap<GetProcessInfo>, "GetProcessInfo"}, + {0x2C, nullptr, "GetThreadInfo"}, + {0x2D, HLE::Wrap<ConnectToPort>, "ConnectToPort"}, + {0x2E, nullptr, "SendSyncRequest1"}, + {0x2F, nullptr, "SendSyncRequest2"}, + {0x30, nullptr, "SendSyncRequest3"}, + {0x31, nullptr, "SendSyncRequest4"}, + {0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"}, + {0x33, nullptr, "OpenProcess"}, + {0x34, nullptr, "OpenThread"}, + {0x35, HLE::Wrap<GetProcessId>, "GetProcessId"}, {0x36, HLE::Wrap<GetProcessIdOfThread>, "GetProcessIdOfThread"}, - {0x37, HLE::Wrap<GetThreadId>, "GetThreadId"}, - {0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"}, + {0x37, HLE::Wrap<GetThreadId>, "GetThreadId"}, + {0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"}, {0x39, HLE::Wrap<GetResourceLimitLimitValues>, "GetResourceLimitLimitValues"}, {0x3A, HLE::Wrap<GetResourceLimitCurrentValues>, "GetResourceLimitCurrentValues"}, - {0x3B, nullptr, "GetThreadContext"}, - {0x3C, HLE::Wrap<Break>, "Break"}, - {0x3D, HLE::Wrap<OutputDebugString>, "OutputDebugString"}, - {0x3E, nullptr, "ControlPerformanceCounter"}, - {0x3F, nullptr, "Unknown"}, - {0x40, nullptr, "Unknown"}, - {0x41, nullptr, "Unknown"}, - {0x42, nullptr, "Unknown"}, - {0x43, nullptr, "Unknown"}, - {0x44, nullptr, "Unknown"}, - {0x45, nullptr, "Unknown"}, - {0x46, nullptr, "Unknown"}, - {0x47, HLE::Wrap<CreatePort>, "CreatePort"}, - {0x48, nullptr, "CreateSessionToPort"}, - {0x49, nullptr, "CreateSession"}, - {0x4A, nullptr, "AcceptSession"}, - {0x4B, nullptr, "ReplyAndReceive1"}, - {0x4C, nullptr, "ReplyAndReceive2"}, - {0x4D, nullptr, "ReplyAndReceive3"}, - {0x4E, nullptr, "ReplyAndReceive4"}, - {0x4F, nullptr, "ReplyAndReceive"}, - {0x50, nullptr, "BindInterrupt"}, - {0x51, nullptr, "UnbindInterrupt"}, - {0x52, nullptr, "InvalidateProcessDataCache"}, - {0x53, nullptr, "StoreProcessDataCache"}, - {0x54, nullptr, "FlushProcessDataCache"}, - {0x55, nullptr, "StartInterProcessDma"}, - {0x56, nullptr, "StopDma"}, - {0x57, nullptr, "GetDmaState"}, - {0x58, nullptr, "RestartDma"}, - {0x59, nullptr, "Unknown"}, - {0x5A, nullptr, "Unknown"}, - {0x5B, nullptr, "Unknown"}, - {0x5C, nullptr, "Unknown"}, - {0x5D, nullptr, "Unknown"}, - {0x5E, nullptr, "Unknown"}, - {0x5F, nullptr, "Unknown"}, - {0x60, nullptr, "DebugActiveProcess"}, - {0x61, nullptr, "BreakDebugProcess"}, - {0x62, nullptr, "TerminateDebugProcess"}, - {0x63, nullptr, "GetProcessDebugEvent"}, - {0x64, nullptr, "ContinueDebugEvent"}, - {0x65, nullptr, "GetProcessList"}, - {0x66, nullptr, "GetThreadList"}, - {0x67, nullptr, "GetDebugThreadContext"}, - {0x68, nullptr, "SetDebugThreadContext"}, - {0x69, nullptr, "QueryDebugProcessMemory"}, - {0x6A, nullptr, "ReadProcessMemory"}, - {0x6B, nullptr, "WriteProcessMemory"}, - {0x6C, nullptr, "SetHardwareBreakPoint"}, - {0x6D, nullptr, "GetDebugThreadParam"}, - {0x6E, nullptr, "Unknown"}, - {0x6F, nullptr, "Unknown"}, - {0x70, nullptr, "ControlProcessMemory"}, - {0x71, nullptr, "MapProcessMemory"}, - {0x72, nullptr, "UnmapProcessMemory"}, - {0x73, nullptr, "CreateCodeSet"}, - {0x74, nullptr, "RandomStub"}, - {0x75, nullptr, "CreateProcess"}, - {0x76, nullptr, "TerminateProcess"}, - {0x77, nullptr, "SetProcessResourceLimits"}, - {0x78, nullptr, "CreateResourceLimit"}, - {0x79, nullptr, "SetResourceLimitValues"}, - {0x7A, nullptr, "AddCodeSegment"}, - {0x7B, nullptr, "Backdoor"}, - {0x7C, nullptr, "KernelSetState"}, - {0x7D, HLE::Wrap<QueryProcessMemory>, "QueryProcessMemory"}, + {0x3B, nullptr, "GetThreadContext"}, + {0x3C, HLE::Wrap<Break>, "Break"}, + {0x3D, HLE::Wrap<OutputDebugString>, "OutputDebugString"}, + {0x3E, nullptr, "ControlPerformanceCounter"}, + {0x3F, nullptr, "Unknown"}, + {0x40, nullptr, "Unknown"}, + {0x41, nullptr, "Unknown"}, + {0x42, nullptr, "Unknown"}, + {0x43, nullptr, "Unknown"}, + {0x44, nullptr, "Unknown"}, + {0x45, nullptr, "Unknown"}, + {0x46, nullptr, "Unknown"}, + {0x47, HLE::Wrap<CreatePort>, "CreatePort"}, + {0x48, nullptr, "CreateSessionToPort"}, + {0x49, nullptr, "CreateSession"}, + {0x4A, nullptr, "AcceptSession"}, + {0x4B, nullptr, "ReplyAndReceive1"}, + {0x4C, nullptr, "ReplyAndReceive2"}, + {0x4D, nullptr, "ReplyAndReceive3"}, + {0x4E, nullptr, "ReplyAndReceive4"}, + {0x4F, nullptr, "ReplyAndReceive"}, + {0x50, nullptr, "BindInterrupt"}, + {0x51, nullptr, "UnbindInterrupt"}, + {0x52, nullptr, "InvalidateProcessDataCache"}, + {0x53, nullptr, "StoreProcessDataCache"}, + {0x54, nullptr, "FlushProcessDataCache"}, + {0x55, nullptr, "StartInterProcessDma"}, + {0x56, nullptr, "StopDma"}, + {0x57, nullptr, "GetDmaState"}, + {0x58, nullptr, "RestartDma"}, + {0x59, nullptr, "Unknown"}, + {0x5A, nullptr, "Unknown"}, + {0x5B, nullptr, "Unknown"}, + {0x5C, nullptr, "Unknown"}, + {0x5D, nullptr, "Unknown"}, + {0x5E, nullptr, "Unknown"}, + {0x5F, nullptr, "Unknown"}, + {0x60, nullptr, "DebugActiveProcess"}, + {0x61, nullptr, "BreakDebugProcess"}, + {0x62, nullptr, "TerminateDebugProcess"}, + {0x63, nullptr, "GetProcessDebugEvent"}, + {0x64, nullptr, "ContinueDebugEvent"}, + {0x65, nullptr, "GetProcessList"}, + {0x66, nullptr, "GetThreadList"}, + {0x67, nullptr, "GetDebugThreadContext"}, + {0x68, nullptr, "SetDebugThreadContext"}, + {0x69, nullptr, "QueryDebugProcessMemory"}, + {0x6A, nullptr, "ReadProcessMemory"}, + {0x6B, nullptr, "WriteProcessMemory"}, + {0x6C, nullptr, "SetHardwareBreakPoint"}, + {0x6D, nullptr, "GetDebugThreadParam"}, + {0x6E, nullptr, "Unknown"}, + {0x6F, nullptr, "Unknown"}, + {0x70, nullptr, "ControlProcessMemory"}, + {0x71, nullptr, "MapProcessMemory"}, + {0x72, nullptr, "UnmapProcessMemory"}, + {0x73, nullptr, "CreateCodeSet"}, + {0x74, nullptr, "RandomStub"}, + {0x75, nullptr, "CreateProcess"}, + {0x76, nullptr, "TerminateProcess"}, + {0x77, nullptr, "SetProcessResourceLimits"}, + {0x78, nullptr, "CreateResourceLimit"}, + {0x79, nullptr, "SetResourceLimitValues"}, + {0x7A, nullptr, "AddCodeSegment"}, + {0x7B, nullptr, "Backdoor"}, + {0x7C, nullptr, "KernelSetState"}, + {0x7D, HLE::Wrap<QueryProcessMemory>, "QueryProcessMemory"}, }; static const FunctionDef* GetSVCInfo(u32 func_num) { |