From d3634d4bf4b1cbd8cc4fe6f22178054803b41e23 Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 12 May 2015 15:25:15 -0500 Subject: Core/ResourceLimits: Implemented the basic structure of ResourceLimits. Implemented svcs GetResourceLimit, GetResourceLimitCurrentValues and GetResourceLimitLimitValues. Note that the resource limits do not currently keep track of used objects, since we have no way to distinguish between an object created by the application, and an object created by some HLE module once we're inside Kernel::T::Create. --- src/core/hle/svc.cpp | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 9bf886256..654ee2bf6 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -17,6 +17,7 @@ #include "core/hle/kernel/event.h" #include "core/hle/kernel/mutex.h" #include "core/hle/kernel/process.h" +#include "core/hle/kernel/resource_limit.h" #include "core/hle/kernel/semaphore.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/thread.h" @@ -301,21 +302,47 @@ static void OutputDebugString(const char* string) { } /// Get resource limit -static ResultCode GetResourceLimit(Handle* resource_limit, Handle process) { - // With regards to proceess values: - // 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for - // the current KThread. - *resource_limit = 0xDEADBEEF; - LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called process=0x%08X", process); +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); + if (process == nullptr) + return ERR_INVALID_HANDLE; + + CASCADE_RESULT(*resource_limit, Kernel::g_handle_table.Create(process->resource_limit)); + return RESULT_SUCCESS; } /// Get resource limit current values -static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit, void* names, +static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit_handle, u32* names, + s32 name_count) { + LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", + resource_limit_handle, names, name_count); + + SharedPtr resource_limit = Kernel::g_handle_table.Get(resource_limit_handle); + if (resource_limit == nullptr) + return ERR_INVALID_HANDLE; + + for (unsigned int i = 0; i < name_count; ++i) + values[i] = resource_limit->GetCurrentResourceValue(names[i]); + + return RESULT_SUCCESS; +} + +/// Get resource limit max values +static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit_handle, u32* names, s32 name_count) { - LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%p, name_count=%d", - resource_limit, names, name_count); - values[0] = 0; // Normmatt: Set used memory to 0 for now + LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", + resource_limit_handle, names, name_count); + + SharedPtr resource_limit = Kernel::g_handle_table.Get(resource_limit_handle); + if (resource_limit == nullptr) + return ERR_INVALID_HANDLE; + + for (unsigned int i = 0; i < name_count; ++i) + values[i] = resource_limit->GetMaxResourceValue(names[i]); + return RESULT_SUCCESS; } @@ -707,7 +734,7 @@ static const FunctionDef SVC_Table[] = { {0x36, HLE::Wrap, "GetProcessIdOfThread"}, {0x37, HLE::Wrap, "GetThreadId"}, {0x38, HLE::Wrap, "GetResourceLimit"}, - {0x39, nullptr, "GetResourceLimitLimitValues"}, + {0x39, HLE::Wrap, "GetResourceLimitLimitValues"}, {0x3A, HLE::Wrap, "GetResourceLimitCurrentValues"}, {0x3B, nullptr, "GetThreadContext"}, {0x3C, nullptr, "Break"}, -- cgit v1.2.3