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

kernel/svc: Implement the resource limit svcGetInfo option

Allows a process to register the resource limit as part of its handle
table.
This commit is contained in:
Lioncash 2018-12-04 00:29:15 -05:00
parent adc4d332fc
commit 312690b450
4 changed files with 34 additions and 9 deletions

View File

@ -13,6 +13,7 @@
namespace Kernel { namespace Kernel {
enum KernelHandle : Handle { enum KernelHandle : Handle {
InvalidHandle = 0,
CurrentThread = 0xFFFF8000, CurrentThread = 0xFFFF8000,
CurrentProcess = 0xFFFF8001, CurrentProcess = 0xFFFF8001,
}; };

View File

@ -44,6 +44,10 @@ SharedPtr<Process> Process::Create(KernelCore& kernel, std::string&& name) {
return process; return process;
} }
SharedPtr<ResourceLimit> Process::GetResourceLimit() const {
return resource_limit;
}
void Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { void Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) {
program_id = metadata.GetTitleID(); program_id = metadata.GetTitleID();
is_64bit_process = metadata.Is64BitProgram(); is_64bit_process = metadata.Is64BitProgram();

View File

@ -171,14 +171,7 @@ public:
} }
/// Gets the resource limit descriptor for this process /// Gets the resource limit descriptor for this process
ResourceLimit& GetResourceLimit() { SharedPtr<ResourceLimit> GetResourceLimit() const;
return *resource_limit;
}
/// Gets the resource limit descriptor for this process
const ResourceLimit& GetResourceLimit() const {
return *resource_limit;
}
/// Gets the default CPU ID for this process /// Gets the default CPU ID for this process
u8 GetDefaultProcessorID() const { u8 GetDefaultProcessorID() const {

View File

@ -663,7 +663,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
TotalMemoryUsage = 6, TotalMemoryUsage = 6,
TotalHeapUsage = 7, TotalHeapUsage = 7,
IsCurrentProcessBeingDebugged = 8, IsCurrentProcessBeingDebugged = 8,
ResourceHandleLimit = 9, RegisterResourceLimit = 9,
IdleTickCount = 10, IdleTickCount = 10,
RandomEntropy = 11, RandomEntropy = 11,
PerformanceCounter = 0xF0000002, PerformanceCounter = 0xF0000002,
@ -787,6 +787,33 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
*result = 0; *result = 0;
return RESULT_SUCCESS; return RESULT_SUCCESS;
case GetInfoType::RegisterResourceLimit: {
if (handle != 0) {
return ERR_INVALID_HANDLE;
}
if (info_sub_id != 0) {
return ERR_INVALID_COMBINATION;
}
Process* const current_process = Core::CurrentProcess();
HandleTable& handle_table = current_process->GetHandleTable();
const auto resource_limit = current_process->GetResourceLimit();
if (!resource_limit) {
*result = KernelHandle::InvalidHandle;
// Yes, the kernel considers this a successful operation.
return RESULT_SUCCESS;
}
const auto table_result = handle_table.Create(resource_limit);
if (table_result.Failed()) {
return table_result.Code();
}
*result = *table_result;
return RESULT_SUCCESS;
}
case GetInfoType::RandomEntropy: case GetInfoType::RandomEntropy:
if (handle != 0) { if (handle != 0) {
LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}",