stratosphere: fix building with latest libnx

This commit is contained in:
Michael Scire 2020-03-29 15:24:40 -07:00
parent 87ec045a98
commit 7fc1e86bf5
12 changed files with 109 additions and 110 deletions

View file

@ -23,7 +23,7 @@ namespace ams::pm {
R_DEFINE_ERROR_RESULT(ProcessNotFound, 1); R_DEFINE_ERROR_RESULT(ProcessNotFound, 1);
R_DEFINE_ERROR_RESULT(AlreadyStarted, 2); R_DEFINE_ERROR_RESULT(AlreadyStarted, 2);
R_DEFINE_ERROR_RESULT(NotExited, 3); R_DEFINE_ERROR_RESULT(NotTerminated, 3);
R_DEFINE_ERROR_RESULT(DebugHookInUse, 4); R_DEFINE_ERROR_RESULT(DebugHookInUse, 4);
R_DEFINE_ERROR_RESULT(ApplicationRunning, 5); R_DEFINE_ERROR_RESULT(ApplicationRunning, 5);
R_DEFINE_ERROR_RESULT(InvalidSize, 6); R_DEFINE_ERROR_RESULT(InvalidSize, 6);

View file

@ -246,17 +246,17 @@ namespace ams::creport {
this->thread_count = 0; this->thread_count = 0;
/* Get thread list. */ /* Get thread list. */
u32 num_threads; s32 num_threads;
u64 thread_ids[ThreadCountMax]; u64 thread_ids[ThreadCountMax];
{ {
if (R_FAILED(svcGetThreadList(&num_threads, thread_ids, ThreadCountMax, debug_handle))) { if (R_FAILED(svc::GetThreadList(&num_threads, thread_ids, ThreadCountMax, debug_handle))) {
return; return;
} }
num_threads = std::min(size_t(num_threads), ThreadCountMax); num_threads = std::min(size_t(num_threads), ThreadCountMax);
} }
/* Parse thread infos. */ /* Parse thread infos. */
for (size_t i = 0; i < num_threads; i++) { for (s32 i = 0; i < num_threads; i++) {
if (this->threads[this->thread_count].ReadFromProcess(debug_handle, tls_map, thread_ids[i], is_64_bit)) { if (this->threads[this->thread_count].ReadFromProcess(debug_handle, tls_map, thread_ids[i], is_64_bit)) {
this->thread_count++; this->thread_count++;
} }

View file

@ -213,14 +213,14 @@ namespace ams::fatal::srv {
ThreadContext thread_ctx; ThreadContext thread_ctx;
{ {
/* We start by trying to get a list of threads. */ /* We start by trying to get a list of threads. */
u32 thread_count; s32 thread_count;
u64 thread_ids[0x60]; u64 thread_ids[0x60];
if (R_FAILED(svcGetThreadList(&thread_count, thread_ids, 0x60, debug_handle.Get()))) { if (R_FAILED(svc::GetThreadList(&thread_count, thread_ids, 0x60, debug_handle.Get()))) {
return; return;
} }
/* We need to locate the thread that's called fatal. */ /* We need to locate the thread that's called fatal. */
for (u32 i = 0; i < thread_count; i++) { for (s32 i = 0; i < thread_count; i++) {
const u64 cur_thread_id = thread_ids[i]; const u64 cur_thread_id = thread_ids[i];
if (thread_id_to_tls.find(cur_thread_id) == thread_id_to_tls.end()) { if (thread_id_to_tls.find(cur_thread_id) == thread_id_to_tls.end()) {
continue; continue;

View file

@ -17,7 +17,7 @@
namespace ams::pm::impl { namespace ams::pm::impl {
ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : process_id(pid), pin_id(pin), loc(l), status(s), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) { ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : process_id(pid), pin_id(pin), loc(l), status(s), handle(h), state(svc::ProcessState_Created), flags(0), waitable_holder(h) {
this->waitable_holder.SetUserData(reinterpret_cast<uintptr_t>(this)); this->waitable_holder.SetUserData(reinterpret_cast<uintptr_t>(this));
} }

View file

@ -43,7 +43,7 @@ namespace ams::pm::impl {
const ncm::ProgramLocation loc; const ncm::ProgramLocation loc;
const cfg::OverrideStatus status; const cfg::OverrideStatus status;
Handle handle; Handle handle;
ProcessState state; svc::ProcessState state;
u32 flags; u32 flags;
os::WaitableHolder waitable_holder; os::WaitableHolder waitable_holder;
private: private:
@ -87,20 +87,20 @@ namespace ams::pm::impl {
return this->status; return this->status;
} }
ProcessState GetState() const { svc::ProcessState GetState() const {
return this->state; return this->state;
} }
void SetState(ProcessState state) { void SetState(svc::ProcessState state) {
this->state = state; this->state = state;
} }
bool HasStarted() const { bool HasStarted() const {
return this->state != ProcessState_Created && this->state != ProcessState_CreatedAttached; return this->state != svc::ProcessState_Created && this->state != svc::ProcessState_CreatedAttached;
} }
bool HasExited() const { bool HasTerminated() const {
return this->state == ProcessState_Exited; return this->state == svc::ProcessState_Terminated;
} }
#define DEFINE_FLAG_SET(flag) \ #define DEFINE_FLAG_SET(flag) \

View file

@ -97,7 +97,7 @@ namespace ams::pm::impl {
Started = 2, Started = 2,
Exception = 3, Exception = 3,
DebugRunning = 4, DebugRunning = 4,
DebugSuspended = 5, DebugBreak = 5,
}; };
enum class ProcessEventDeprecated { enum class ProcessEventDeprecated {
@ -105,7 +105,7 @@ namespace ams::pm::impl {
Exception = 1, Exception = 1,
Exited = 2, Exited = 2,
DebugRunning = 3, DebugRunning = 3,
DebugSuspended = 4, DebugBreak = 4,
Started = 5, Started = 5,
}; };
@ -124,8 +124,8 @@ namespace ams::pm::impl {
return static_cast<u32>(ProcessEventDeprecated::Exception); return static_cast<u32>(ProcessEventDeprecated::Exception);
case ProcessEvent::DebugRunning: case ProcessEvent::DebugRunning:
return static_cast<u32>(ProcessEventDeprecated::DebugRunning); return static_cast<u32>(ProcessEventDeprecated::DebugRunning);
case ProcessEvent::DebugSuspended: case ProcessEvent::DebugBreak:
return static_cast<u32>(ProcessEventDeprecated::DebugSuspended); return static_cast<u32>(ProcessEventDeprecated::DebugBreak);
AMS_UNREACHABLE_DEFAULT_CASE(); AMS_UNREACHABLE_DEFAULT_CASE();
} }
} }
@ -263,7 +263,7 @@ namespace ams::pm::impl {
Result StartProcess(ProcessInfo *process_info, const ldr::ProgramInfo *program_info) { Result StartProcess(ProcessInfo *process_info, const ldr::ProgramInfo *program_info) {
R_TRY(svcStartProcess(process_info->GetHandle(), program_info->main_thread_priority, program_info->default_cpu_id, program_info->main_thread_stack_size)); R_TRY(svcStartProcess(process_info->GetHandle(), program_info->main_thread_priority, program_info->default_cpu_id, program_info->main_thread_stack_size));
process_info->SetState(ProcessState_Running); process_info->SetState(svc::ProcessState_Running);
return ResultSuccess(); return ResultSuccess();
} }
@ -372,25 +372,25 @@ namespace ams::pm::impl {
svcResetSignal(process_info->GetHandle()); svcResetSignal(process_info->GetHandle());
/* Update the process's state. */ /* Update the process's state. */
const ProcessState old_state = process_info->GetState(); const svc::ProcessState old_state = process_info->GetState();
{ {
u64 tmp = 0; s64 tmp = 0;
R_ABORT_UNLESS(svcGetProcessInfo(&tmp, process_info->GetHandle(), ProcessInfoType_ProcessState)); R_ABORT_UNLESS(svc::GetProcessInfo(&tmp, process_info->GetHandle(), svc::ProcessInfoType_ProcessState));
process_info->SetState(static_cast<ProcessState>(tmp)); process_info->SetState(static_cast<svc::ProcessState>(tmp));
} }
const ProcessState new_state = process_info->GetState(); const svc::ProcessState new_state = process_info->GetState();
/* If we're transitioning away from crashed, clear waiting attached. */ /* If we're transitioning away from crashed, clear waiting attached. */
if (old_state == ProcessState_Crashed && new_state != ProcessState_Crashed) { if (old_state == svc::ProcessState_Crashed && new_state != svc::ProcessState_Crashed) {
process_info->ClearExceptionWaitingAttach(); process_info->ClearExceptionWaitingAttach();
} }
switch (new_state) { switch (new_state) {
case ProcessState_Created: case svc::ProcessState_Created:
case ProcessState_CreatedAttached: case svc::ProcessState_CreatedAttached:
case ProcessState_Exiting: case svc::ProcessState_Terminating:
break; break;
case ProcessState_Running: case svc::ProcessState_Running:
if (process_info->ShouldSignalOnDebugEvent()) { if (process_info->ShouldSignalOnDebugEvent()) {
process_info->ClearSuspended(); process_info->ClearSuspended();
process_info->SetSuspendedStateChanged(); process_info->SetSuspendedStateChanged();
@ -401,18 +401,18 @@ namespace ams::pm::impl {
g_process_event.Signal(); g_process_event.Signal();
} }
break; break;
case ProcessState_Crashed: case svc::ProcessState_Crashed:
process_info->SetExceptionOccurred(); process_info->SetExceptionOccurred();
g_process_event.Signal(); g_process_event.Signal();
break; break;
case ProcessState_RunningAttached: case svc::ProcessState_RunningAttached:
if (process_info->ShouldSignalOnDebugEvent()) { if (process_info->ShouldSignalOnDebugEvent()) {
process_info->ClearSuspended(); process_info->ClearSuspended();
process_info->SetSuspendedStateChanged(); process_info->SetSuspendedStateChanged();
g_process_event.Signal(); g_process_event.Signal();
} }
break; break;
case ProcessState_Exited: case svc::ProcessState_Terminated:
/* Free process resources, unlink from waitable manager. */ /* Free process resources, unlink from waitable manager. */
process_info->Cleanup(); process_info->Cleanup();
@ -438,7 +438,7 @@ namespace ams::pm::impl {
} }
} }
break; break;
case ProcessState_DebugSuspended: case svc::ProcessState_DebugBreak:
if (process_info->ShouldSignalOnDebugEvent()) { if (process_info->ShouldSignalOnDebugEvent()) {
process_info->SetSuspended(); process_info->SetSuspended();
process_info->SetSuspendedStateChanged(); process_info->SetSuspendedStateChanged();
@ -535,7 +535,7 @@ namespace ams::pm::impl {
if (process.HasSuspendedStateChanged()) { if (process.HasSuspendedStateChanged()) {
process.ClearSuspendedStateChanged(); process.ClearSuspendedStateChanged();
if (process.IsSuspended()) { if (process.IsSuspended()) {
out->event = GetProcessEventValue(ProcessEvent::DebugSuspended); out->event = GetProcessEventValue(ProcessEvent::DebugBreak);
} else { } else {
out->event = GetProcessEventValue(ProcessEvent::DebugRunning); out->event = GetProcessEventValue(ProcessEvent::DebugRunning);
} }
@ -548,7 +548,7 @@ namespace ams::pm::impl {
out->process_id = process.GetProcessId(); out->process_id = process.GetProcessId();
return ResultSuccess(); return ResultSuccess();
} }
if (hos::GetVersion() < hos::Version_500 && process.ShouldSignalOnExit() && process.HasExited()) { if (hos::GetVersion() < hos::Version_500 && process.ShouldSignalOnExit() && process.HasTerminated()) {
out->event = GetProcessEventValue(ProcessEvent::Exited); out->event = GetProcessEventValue(ProcessEvent::Exited);
out->process_id = process.GetProcessId(); out->process_id = process.GetProcessId();
return ResultSuccess(); return ResultSuccess();
@ -580,7 +580,7 @@ namespace ams::pm::impl {
auto process_info = list->Find(process_id); auto process_info = list->Find(process_id);
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound()); R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
R_UNLESS(process_info->HasExited(), pm::ResultNotExited()); R_UNLESS(process_info->HasTerminated(), pm::ResultNotTerminated());
CleanupProcessInfo(list, process_info); CleanupProcessInfo(list, process_info);
return ResultSuccess(); return ResultSuccess();
@ -725,8 +725,8 @@ namespace ams::pm::impl {
return resource::BoostApplicationThreadResourceLimit(); return resource::BoostApplicationThreadResourceLimit();
} }
Result AtmosphereGetCurrentLimitInfo(u64 *out_cur_val, u64 *out_lim_val, u32 group, u32 resource) { Result AtmosphereGetCurrentLimitInfo(s64 *out_cur_val, s64 *out_lim_val, u32 group, u32 resource) {
return resource::GetResourceLimitValues(out_cur_val, out_lim_val, static_cast<ResourceLimitGroup>(group), static_cast<LimitableResource>(resource)); return resource::GetResourceLimitValues(out_cur_val, out_lim_val, static_cast<ResourceLimitGroup>(group), static_cast<svc::LimitableResource>(resource));
} }
} }

View file

@ -51,6 +51,6 @@ namespace ams::pm::impl {
/* Resource Limit API. */ /* Resource Limit API. */
Result BoostSystemMemoryResourceLimit(u64 boost_size); Result BoostSystemMemoryResourceLimit(u64 boost_size);
Result BoostApplicationThreadResourceLimit(); Result BoostApplicationThreadResourceLimit();
Result AtmosphereGetCurrentLimitInfo(u64 *out_cur_val, u64 *out_lim_val, u32 group, u32 resource); Result AtmosphereGetCurrentLimitInfo(s64 *out_cur_val, s64 *out_lim_val, u32 group, u32 resource);
} }

View file

@ -19,14 +19,13 @@ namespace ams::pm::resource {
namespace { namespace {
constexpr LimitableResource LimitableResources[] = { constexpr svc::LimitableResource LimitableResources[] = {
LimitableResource_Memory, svc::LimitableResource_PhysicalMemoryMax,
LimitableResource_Threads, svc::LimitableResource_ThreadCountMax,
LimitableResource_Events, svc::LimitableResource_EventCountMax,
LimitableResource_TransferMemories, svc::LimitableResource_TransferMemoryCountMax,
LimitableResource_Sessions, svc::LimitableResource_SessionCountMax,
}; };
constexpr size_t LimitableResource_Count = util::size(LimitableResources);
/* Definitions for limit differences over time. */ /* Definitions for limit differences over time. */
constexpr size_t ExtraSystemThreadCount400 = 100; constexpr size_t ExtraSystemThreadCount400 = 100;
@ -48,27 +47,27 @@ namespace ams::pm::resource {
u64 g_system_memory_boost_size = 0; u64 g_system_memory_boost_size = 0;
u64 g_extra_application_threads_available = 0; u64 g_extra_application_threads_available = 0;
u64 g_resource_limits[ResourceLimitGroup_Count][LimitableResource_Count] = { u64 g_resource_limits[ResourceLimitGroup_Count][svc::LimitableResource_Count] = {
[ResourceLimitGroup_System] = { [ResourceLimitGroup_System] = {
[LimitableResource_Memory] = 0, /* Initialized by more complicated logic later. */ [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized by more complicated logic later. */
[LimitableResource_Threads] = 508, [svc::LimitableResource_ThreadCountMax] = 508,
[LimitableResource_Events] = 600, [svc::LimitableResource_EventCountMax] = 600,
[LimitableResource_TransferMemories] = 128, [svc::LimitableResource_TransferMemoryCountMax] = 128,
[LimitableResource_Sessions] = 794, [svc::LimitableResource_SessionCountMax] = 794,
}, },
[ResourceLimitGroup_Application] = { [ResourceLimitGroup_Application] = {
[LimitableResource_Memory] = 0, /* Initialized by more complicated logic later. */ [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized by more complicated logic later. */
[LimitableResource_Threads] = 96, [svc::LimitableResource_ThreadCountMax] = 96,
[LimitableResource_Events] = 0, [svc::LimitableResource_EventCountMax] = 0,
[LimitableResource_TransferMemories] = 32, [svc::LimitableResource_TransferMemoryCountMax] = 32,
[LimitableResource_Sessions] = 1, [svc::LimitableResource_SessionCountMax] = 1,
}, },
[ResourceLimitGroup_Applet] = { [ResourceLimitGroup_Applet] = {
[LimitableResource_Memory] = 0, /* Initialized by more complicated logic later. */ [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized by more complicated logic later. */
[LimitableResource_Threads] = 96, [svc::LimitableResource_ThreadCountMax] = 96,
[LimitableResource_Events] = 0, [svc::LimitableResource_EventCountMax] = 0,
[LimitableResource_TransferMemories] = 32, [svc::LimitableResource_TransferMemoryCountMax] = 32,
[LimitableResource_Sessions] = 5, [svc::LimitableResource_SessionCountMax] = 5,
}, },
}; };
@ -102,13 +101,13 @@ namespace ams::pm::resource {
/* Helpers. */ /* Helpers. */
Result SetMemoryResourceLimitLimitValue(ResourceLimitGroup group, u64 new_memory_limit) { Result SetMemoryResourceLimitLimitValue(ResourceLimitGroup group, u64 new_memory_limit) {
const u64 old_memory_limit = g_resource_limits[group][LimitableResource_Memory]; const u64 old_memory_limit = g_resource_limits[group][svc::LimitableResource_PhysicalMemoryMax];
g_resource_limits[group][LimitableResource_Memory] = new_memory_limit; g_resource_limits[group][svc::LimitableResource_PhysicalMemoryMax] = new_memory_limit;
{ {
/* If we fail, restore the old memory limit. */ /* If we fail, restore the old memory limit. */
auto limit_guard = SCOPE_GUARD { g_resource_limits[group][LimitableResource_Memory] = old_memory_limit; }; auto limit_guard = SCOPE_GUARD { g_resource_limits[group][svc::LimitableResource_PhysicalMemoryMax] = old_memory_limit; };
R_TRY(svcSetResourceLimitLimitValue(GetResourceLimitHandle(group), LimitableResource_Memory, g_resource_limits[group][LimitableResource_Memory])); R_TRY(svc::SetResourceLimitLimitValue(GetResourceLimitHandle(group), svc::LimitableResource_PhysicalMemoryMax, g_resource_limits[group][svc::LimitableResource_PhysicalMemoryMax]));
limit_guard.Cancel(); limit_guard.Cancel();
} }
@ -120,12 +119,12 @@ namespace ams::pm::resource {
R_TRY(SetMemoryResourceLimitLimitValue(group, new_memory_limit)); R_TRY(SetMemoryResourceLimitLimitValue(group, new_memory_limit));
/* Set other limit values. */ /* Set other limit values. */
for (size_t i = 0; i < LimitableResource_Count; i++) { for (size_t i = 0; i < svc::LimitableResource_Count; i++) {
const auto resource = LimitableResources[i]; const auto resource = LimitableResources[i];
if (resource == LimitableResource_Memory) { if (resource == svc::LimitableResource_PhysicalMemoryMax) {
continue; continue;
} }
R_TRY(svcSetResourceLimitLimitValue(GetResourceLimitHandle(group), resource, g_resource_limits[group][resource])); R_TRY(svc::SetResourceLimitLimitValue(GetResourceLimitHandle(group), resource, g_resource_limits[group][resource]));
} }
return ResultSuccess(); return ResultSuccess();
} }
@ -143,16 +142,16 @@ namespace ams::pm::resource {
void WaitResourceAvailable(ResourceLimitGroup group) { void WaitResourceAvailable(ResourceLimitGroup group) {
const Handle reslimit_hnd = GetResourceLimitHandle(group); const Handle reslimit_hnd = GetResourceLimitHandle(group);
for (size_t i = 0; i < LimitableResource_Count; i++) { for (size_t i = 0; i < svc::LimitableResource_Count; i++) {
const auto resource = LimitableResources[i]; const auto resource = LimitableResources[i];
u64 value = 0; s64 value = 0;
while (true) { while (true) {
R_ABORT_UNLESS(svcGetResourceLimitCurrentValue(&value, reslimit_hnd, resource)); R_ABORT_UNLESS(svc::GetResourceLimitCurrentValue(&value, reslimit_hnd, resource));
if (value == 0) { if (value == 0) {
break; break;
} }
svcSleepThread(1'000'000ul); svc::SleepThread(1'000'000ul);
} }
} }
} }
@ -160,11 +159,11 @@ namespace ams::pm::resource {
void WaitApplicationMemoryAvailable() { void WaitApplicationMemoryAvailable() {
u64 value = 0; u64 value = 0;
while (true) { while (true) {
R_ABORT_UNLESS(svcGetSystemInfo(&value, SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application)); R_ABORT_UNLESS(svc::GetSystemInfo(&value, svc::SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, svc::PhysicalMemorySystemInfo_Application));
if (value == 0) { if (value == 0) {
break; break;
} }
svcSleepThread(1'000'000ul); svc::SleepThread(1'000'000ul);
} }
} }
@ -176,10 +175,10 @@ namespace ams::pm::resource {
for (size_t i = 0; i < ResourceLimitGroup_Count; i++) { for (size_t i = 0; i < ResourceLimitGroup_Count; i++) {
if (i == ResourceLimitGroup_System) { if (i == ResourceLimitGroup_System) {
u64 value = 0; u64 value = 0;
R_ABORT_UNLESS(svcGetInfo(&value, InfoType_ResourceLimit, INVALID_HANDLE, 0)); R_ABORT_UNLESS(svc::GetInfo(&value, svc::InfoType_ResourceLimit, svc::InvalidHandle, 0));
g_resource_limit_handles[i] = static_cast<Handle>(value); g_resource_limit_handles[i] = static_cast<svc::Handle>(value);
} else { } else {
R_ABORT_UNLESS(svcCreateResourceLimit(&g_resource_limit_handles[i])); R_ABORT_UNLESS(svc::CreateResourceLimit(&g_resource_limit_handles[i]));
} }
} }
@ -187,7 +186,7 @@ namespace ams::pm::resource {
const auto hos_version = hos::GetVersion(); const auto hos_version = hos::GetVersion();
if (hos_version >= hos::Version_400) { if (hos_version >= hos::Version_400) {
/* 4.0.0 increased the system thread limit. */ /* 4.0.0 increased the system thread limit. */
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] += ExtraSystemThreadCount400; g_resource_limits[ResourceLimitGroup_System][svc::LimitableResource_ThreadCountMax] += ExtraSystemThreadCount400;
/* 4.0.0 also took memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */ /* 4.0.0 also took memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_System] += ExtraSystemMemorySize400; g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_System] += ExtraSystemMemorySize400;
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize400; g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize400;
@ -203,26 +202,26 @@ namespace ams::pm::resource {
} }
if (hos_version >= hos::Version_600) { if (hos_version >= hos::Version_600) {
/* 6.0.0 increased the system event and session limits. */ /* 6.0.0 increased the system event and session limits. */
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Events] += ExtraSystemEventCount600; g_resource_limits[ResourceLimitGroup_System][svc::LimitableResource_EventCountMax] += ExtraSystemEventCount600;
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Sessions] += ExtraSystemSessionCount600; g_resource_limits[ResourceLimitGroup_System][svc::LimitableResource_SessionCountMax] += ExtraSystemSessionCount600;
} }
if (hos_version >= hos::Version_900) { if (hos_version >= hos::Version_900) {
/* 9.2.0 increased the system session limit. */ /* 9.2.0 increased the system session limit. */
/* NOTE: We don't currently support detection of minor version, so we will provide this increase on 9.0.0+. */ /* NOTE: We don't currently support detection of minor version, so we will provide this increase on 9.0.0+. */
/* This shouldn't impact any existing behavior in undesirable ways. */ /* This shouldn't impact any existing behavior in undesirable ways. */
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Sessions] += ExtraSystemSessionCount920; g_resource_limits[ResourceLimitGroup_System][svc::LimitableResource_SessionCountMax] += ExtraSystemSessionCount920;
} }
/* 7.0.0+: Calculate the number of extra application threads available. */ /* 7.0.0+: Calculate the number of extra application threads available. */
if (hos::GetVersion() >= hos::Version_700) { if (hos::GetVersion() >= hos::Version_700) {
/* See how many threads we have available. */ /* See how many threads we have available. */
u64 total_threads_available = 0; s64 total_threads_available = 0;
R_ABORT_UNLESS(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads)); R_ABORT_UNLESS(svc::GetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), svc::LimitableResource_ThreadCountMax));
/* See how many threads we're expecting. */ /* See how many threads we're expecting. */
const size_t total_threads_allocated = g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] - const s64 total_threads_allocated = g_resource_limits[ResourceLimitGroup_System][svc::LimitableResource_ThreadCountMax] -
g_resource_limits[ResourceLimitGroup_Application][LimitableResource_Threads] - g_resource_limits[ResourceLimitGroup_Application][svc::LimitableResource_ThreadCountMax] -
g_resource_limits[ResourceLimitGroup_Applet][LimitableResource_Threads]; g_resource_limits[ResourceLimitGroup_Applet][svc::LimitableResource_ThreadCountMax];
/* Ensure we don't over-commit threads. */ /* Ensure we don't over-commit threads. */
AMS_ABORT_UNLESS(total_threads_allocated <= total_threads_available); AMS_ABORT_UNLESS(total_threads_allocated <= total_threads_available);
@ -237,16 +236,16 @@ namespace ams::pm::resource {
g_memory_arrangement = spl::MemoryArrangement_Dynamic; g_memory_arrangement = spl::MemoryArrangement_Dynamic;
/* Get total memory available. */ /* Get total memory available. */
u64 total_memory = 0; s64 total_memory = 0;
R_ABORT_UNLESS(svcGetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Memory)); R_ABORT_UNLESS(svc::GetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), svc::LimitableResource_PhysicalMemoryMax));
/* Get and save application + applet memory. */ /* Get and save application + applet memory. */
R_ABORT_UNLESS(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application)); R_ABORT_UNLESS(svc::GetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], svc::SystemInfoType_TotalPhysicalMemorySize, svc::InvalidHandle, svc::PhysicalMemorySystemInfo_Application));
R_ABORT_UNLESS(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Applet)); R_ABORT_UNLESS(svc::GetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], svc::SystemInfoType_TotalPhysicalMemorySize, svc::InvalidHandle, svc::PhysicalMemorySystemInfo_Applet));
const u64 application_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application]; const s64 application_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application];
const u64 applet_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet]; const s64 applet_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet];
const u64 reserved_non_system_size = (application_size + applet_size + ReservedMemorySize600); const s64 reserved_non_system_size = (application_size + applet_size + ReservedMemorySize600);
/* Ensure there's enough memory for the system region. */ /* Ensure there's enough memory for the system region. */
AMS_ABORT_UNLESS(reserved_non_system_size < total_memory); AMS_ABORT_UNLESS(reserved_non_system_size < total_memory);
@ -292,11 +291,11 @@ namespace ams::pm::resource {
if (hos::GetVersion() >= hos::Version_500) { if (hos::GetVersion() >= hos::Version_500) {
/* Starting in 5.0.0, PM does not allow for only one of the sets to fail. */ /* Starting in 5.0.0, PM does not allow for only one of the sets to fail. */
if (boost_size < g_system_memory_boost_size) { if (boost_size < g_system_memory_boost_size) {
R_TRY(svcSetUnsafeLimit(boost_size)); R_TRY(svc::SetUnsafeLimit(boost_size));
R_ABORT_UNLESS(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size)); R_ABORT_UNLESS(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
} else { } else {
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size)); R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
R_ABORT_UNLESS(svcSetUnsafeLimit(boost_size)); R_ABORT_UNLESS(svc::SetUnsafeLimit(boost_size));
} }
} else { } else {
const u64 new_sys_size = g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_System] + boost_size; const u64 new_sys_size = g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_System] + boost_size;
@ -318,11 +317,11 @@ namespace ams::pm::resource {
Result BoostApplicationThreadResourceLimit() { Result BoostApplicationThreadResourceLimit() {
std::scoped_lock lk(g_resource_limit_lock); std::scoped_lock lk(g_resource_limit_lock);
/* Set new limit. */ /* Set new limit. */
const u64 new_thread_count = g_resource_limits[ResourceLimitGroup_Application][LimitableResource_Threads] + g_extra_application_threads_available; const s64 new_thread_count = g_resource_limits[ResourceLimitGroup_Application][svc::LimitableResource_ThreadCountMax] + g_extra_application_threads_available;
R_TRY(svcSetResourceLimitLimitValue(GetResourceLimitHandle(ResourceLimitGroup_Application), LimitableResource_Threads, new_thread_count)); R_TRY(svc::SetResourceLimitLimitValue(GetResourceLimitHandle(ResourceLimitGroup_Application), svc::LimitableResource_ThreadCountMax, new_thread_count));
/* Record that we did so. */ /* Record that we did so. */
g_resource_limits[ResourceLimitGroup_Application][LimitableResource_Threads] = new_thread_count; g_resource_limits[ResourceLimitGroup_Application][svc::LimitableResource_ThreadCountMax] = new_thread_count;
g_extra_application_threads_available = 0; g_extra_application_threads_available = 0;
return ResultSuccess(); return ResultSuccess();
@ -345,14 +344,14 @@ namespace ams::pm::resource {
} }
} }
Result GetResourceLimitValues(u64 *out_cur, u64 *out_lim, ResourceLimitGroup group, LimitableResource resource) { Result GetResourceLimitValues(s64 *out_cur, s64 *out_lim, ResourceLimitGroup group, svc::LimitableResource resource) {
/* Do not allow out of bounds access. */ /* Do not allow out of bounds access. */
AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count); AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count);
AMS_ABORT_UNLESS(resource < LimitableResource_Count); AMS_ABORT_UNLESS(resource < svc::LimitableResource_Count);
const Handle reslimit_hnd = GetResourceLimitHandle(group); const Handle reslimit_hnd = GetResourceLimitHandle(group);
R_TRY(svcGetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource)); R_TRY(svc::GetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource));
R_TRY(svcGetResourceLimitLimitValue(out_lim, reslimit_hnd, resource)); R_TRY(svc::GetResourceLimitLimitValue(out_lim, reslimit_hnd, resource));
return ResultSuccess(); return ResultSuccess();
} }

View file

@ -26,6 +26,6 @@ namespace ams::pm::resource {
Handle GetResourceLimitHandle(const ldr::ProgramInfo *info); Handle GetResourceLimitHandle(const ldr::ProgramInfo *info);
void WaitResourceAvailable(const ldr::ProgramInfo *info); void WaitResourceAvailable(const ldr::ProgramInfo *info);
Result GetResourceLimitValues(u64 *out_cur, u64 *out_lim, ResourceLimitGroup group, LimitableResource resource); Result GetResourceLimitValues(s64 *out_cur, s64 *out_lim, ResourceLimitGroup group, svc::LimitableResource resource);
} }

View file

@ -58,7 +58,7 @@ namespace ams::pm::dmnt {
return impl::AtmosphereGetProcessInfo(out_process_handle.GetHandlePointer(), out_loc.GetPointer(), out_status.GetPointer(), process_id); return impl::AtmosphereGetProcessInfo(out_process_handle.GetHandlePointer(), out_loc.GetPointer(), out_status.GetPointer(), process_id);
} }
Result DebugMonitorServiceBase::AtmosphereGetCurrentLimitInfo(sf::Out<u64> out_cur_val, sf::Out<u64> out_lim_val, u32 group, u32 resource) { Result DebugMonitorServiceBase::AtmosphereGetCurrentLimitInfo(sf::Out<s64> out_cur_val, sf::Out<s64> out_lim_val, u32 group, u32 resource) {
return impl::AtmosphereGetCurrentLimitInfo(out_cur_val.GetPointer(), out_lim_val.GetPointer(), group, resource); return impl::AtmosphereGetCurrentLimitInfo(out_cur_val.GetPointer(), out_lim_val.GetPointer(), group, resource);
} }

View file

@ -32,7 +32,7 @@ namespace ams::pm::dmnt {
/* Atmosphere extension commands. */ /* Atmosphere extension commands. */
virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out<ncm::ProgramLocation> out_loc, sf::Out<cfg::OverrideStatus> out_status, os::ProcessId process_id); virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out<ncm::ProgramLocation> out_loc, sf::Out<cfg::OverrideStatus> out_status, os::ProcessId process_id);
virtual Result AtmosphereGetCurrentLimitInfo(sf::Out<u64> out_cur_val, sf::Out<u64> out_lim_val, u32 group, u32 resource); virtual Result AtmosphereGetCurrentLimitInfo(sf::Out<s64> out_cur_val, sf::Out<s64> out_lim_val, u32 group, u32 resource);
}; };
/* This represents modern DebugMonitorService (5.0.0+). */ /* This represents modern DebugMonitorService (5.0.0+). */

View file

@ -115,10 +115,10 @@ namespace {
cfg::GetInitialProcessRange(&min_priv_process_id, &max_priv_process_id); cfg::GetInitialProcessRange(&min_priv_process_id, &max_priv_process_id);
/* Get list of processes, register all privileged ones. */ /* Get list of processes, register all privileged ones. */
u32 num_pids; s32 num_pids;
os::ProcessId pids[ProcessCountMax]; os::ProcessId pids[ProcessCountMax];
R_ABORT_UNLESS(svcGetProcessList(&num_pids, reinterpret_cast<u64 *>(pids), ProcessCountMax)); R_ABORT_UNLESS(svc::GetProcessList(&num_pids, reinterpret_cast<u64 *>(pids), ProcessCountMax));
for (size_t i = 0; i < num_pids; i++) { for (s32 i = 0; i < num_pids; i++) {
if (min_priv_process_id <= pids[i] && pids[i] <= max_priv_process_id) { if (min_priv_process_id <= pids[i] && pids[i] <= max_priv_process_id) {
RegisterPrivilegedProcess(pids[i]); RegisterPrivilegedProcess(pids[i]);
} }