pm: update for new-ipc

This commit is contained in:
Michael Scire
2019-10-14 22:49:06 -07:00
committed by SciresM
parent 8bd2a9a23b
commit aa0826bb70
25 changed files with 239 additions and 219 deletions

View File

@@ -21,7 +21,7 @@
namespace sts::pm::impl {
ProcessInfo::ProcessInfo(Handle h, u64 pid, ldr::PinId pin, const ncm::TitleLocation &l) : process_id(pid), pin_id(pin), loc(l), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) {
ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::TitleLocation &l) : process_id(pid), pin_id(pin), loc(l), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) {
this->waitable_holder.SetUserData(reinterpret_cast<uintptr_t>(this));
}
@@ -32,7 +32,7 @@ namespace sts::pm::impl {
void ProcessInfo::Cleanup() {
if (this->handle != INVALID_HANDLE) {
/* Unregister the process. */
fsprUnregisterProgram(this->process_id);
fsprUnregisterProgram(static_cast<u64>(this->process_id));
sm::manager::UnregisterProcess(this->process_id);
ldr::pm::UnpinTitle(this->pin_id);

View File

@@ -44,7 +44,7 @@ namespace sts::pm::impl {
};
private:
util::IntrusiveListNode list_node;
const u64 process_id;
const os::ProcessId process_id;
const ldr::PinId pin_id;
const ncm::TitleLocation loc;
Handle handle;
@@ -64,7 +64,7 @@ namespace sts::pm::impl {
return (this->flags & flag);
}
public:
ProcessInfo(Handle h, u64 pid, ldr::PinId pin, const ncm::TitleLocation &l);
ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::TitleLocation &l);
~ProcessInfo();
void Cleanup();
@@ -76,7 +76,7 @@ namespace sts::pm::impl {
return this->handle;
}
u64 GetProcessId() const {
os::ProcessId GetProcessId() const {
return this->process_id;
}
@@ -176,7 +176,7 @@ namespace sts::pm::impl {
this->erase(this->iterator_to(*process_info));
}
ProcessInfo *Find(u64 process_id) {
ProcessInfo *Find(os::ProcessId process_id) {
for (auto it = this->begin(); it != this->end(); it++) {
if ((*it).GetProcessId() == process_id) {
return &*it;

View File

@@ -37,7 +37,7 @@ namespace sts::pm::impl {
};
struct LaunchProcessArgs {
u64 *out_process_id;
os::ProcessId *out_process_id;
ncm::TitleLocation location;
u32 flags;
};
@@ -62,38 +62,38 @@ namespace sts::pm::impl {
LaunchFlagsDeprecated_SignalOnStart = (1 << 5),
};
#define GET_FLAG_MASK(flag) (firmware_version >= FirmwareVersion_500 ? static_cast<u32>(LaunchFlags_##flag) : static_cast<u32>(LaunchFlagsDeprecated_##flag))
#define GET_FLAG_MASK(flag) (hos_version >= hos::Version_500 ? static_cast<u32>(LaunchFlags_##flag) : static_cast<u32>(LaunchFlagsDeprecated_##flag))
inline bool ShouldSignalOnExit(u32 launch_flags) {
const auto firmware_version = GetRuntimeFirmwareVersion();
const auto hos_version = hos::GetVersion();
return launch_flags & GET_FLAG_MASK(SignalOnExit);
}
inline bool ShouldSignalOnStart(u32 launch_flags) {
const auto firmware_version = GetRuntimeFirmwareVersion();
if (firmware_version < FirmwareVersion_200) {
const auto hos_version = hos::GetVersion();
if (hos_version < hos::Version_200) {
return false;
}
return launch_flags & GET_FLAG_MASK(SignalOnStart);
}
inline bool ShouldSignalOnException(u32 launch_flags) {
const auto firmware_version = GetRuntimeFirmwareVersion();
const auto hos_version = hos::GetVersion();
return launch_flags & GET_FLAG_MASK(SignalOnException);
}
inline bool ShouldSignalOnDebugEvent(u32 launch_flags) {
const auto firmware_version = GetRuntimeFirmwareVersion();
const auto hos_version = hos::GetVersion();
return launch_flags & GET_FLAG_MASK(SignalOnDebugEvent);
}
inline bool ShouldStartSuspended(u32 launch_flags) {
const auto firmware_version = GetRuntimeFirmwareVersion();
const auto hos_version = hos::GetVersion();
return launch_flags & GET_FLAG_MASK(StartSuspended);
}
inline bool ShouldDisableAslr(u32 launch_flags) {
const auto firmware_version = GetRuntimeFirmwareVersion();
const auto hos_version = hos::GetVersion();
return launch_flags & GET_FLAG_MASK(DisableAslr);
}
@@ -118,7 +118,7 @@ namespace sts::pm::impl {
};
inline u32 GetProcessEventValue(ProcessEvent event) {
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
if (hos::GetVersion() >= hos::Version_500) {
return static_cast<u32>(event);
}
switch (event) {
@@ -194,7 +194,7 @@ namespace sts::pm::impl {
inline u32 GetLoaderCreateProcessFlags(u32 launch_flags) {
u32 ldr_flags = 0;
if (ShouldSignalOnException(launch_flags) || (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 && !ShouldStartSuspended(launch_flags))) {
if (ShouldSignalOnException(launch_flags) || (hos::GetVersion() >= hos::Version_200 && !ShouldStartSuspended(launch_flags))) {
ldr_flags |= ldr::CreateProcessFlag_EnableDebug;
}
if (ShouldDisableAslr(launch_flags)) {
@@ -235,7 +235,7 @@ namespace sts::pm::impl {
ldr::ProgramInfo program_info;
R_TRY(ldr::pm::GetProgramInfo(&program_info, args.location));
const bool is_application = (program_info.flags & ldr::ProgramInfoFlag_ApplicationTypeMask) == ldr::ProgramInfoFlag_Application;
const bool allow_debug = (program_info.flags & ldr::ProgramInfoFlag_AllowDebug) || GetRuntimeFirmwareVersion() < FirmwareVersion_200;
const bool allow_debug = (program_info.flags & ldr::ProgramInfoFlag_AllowDebug) || hos::GetVersion() < hos::Version_200;
/* Ensure we only try to run one application. */
if (is_application && HasApplicationProcess()) {
@@ -259,8 +259,8 @@ namespace sts::pm::impl {
});
/* Get the process id. */
u64 process_id;
R_ASSERT(svcGetProcessId(&process_id, process_handle));
os::ProcessId process_id = os::InvalidProcessId;
R_ASSERT(svcGetProcessId(&process_id.value, process_handle));
/* Make new process info. */
ProcessInfo *process_info = new ProcessInfo(process_handle, process_id, pin_id, location);
@@ -285,7 +285,7 @@ namespace sts::pm::impl {
const u8 *aci_fah = acid_fac + program_info.acid_fac_size;
/* Register with FS and SM. */
R_TRY(fsprRegisterProgram(process_id, static_cast<u64>(location.title_id), static_cast<FsStorageId>(location.storage_id), aci_fah, program_info.aci_fah_size, acid_fac, program_info.acid_fac_size));
R_TRY(fsprRegisterProgram(static_cast<u64>(process_id), static_cast<u64>(location.title_id), static_cast<FsStorageId>(location.storage_id), aci_fah, program_info.aci_fah_size, acid_fac, program_info.acid_fac_size));
R_TRY(sm::manager::RegisterProcess(process_id, location.title_id, acid_sac, program_info.acid_sac_size, aci_sac, program_info.aci_sac_size));
/* Set flags. */
@@ -348,7 +348,7 @@ namespace sts::pm::impl {
process_info->ClearSuspended();
process_info->SetSuspendedStateChanged();
g_process_event.Signal();
} else if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 && process_info->ShouldSignalOnStart()) {
} else if (hos::GetVersion() >= hos::Version_200 && process_info->ShouldSignalOnStart()) {
process_info->SetStartedStateChanged();
process_info->ClearSignalOnStart();
g_process_event.Signal();
@@ -366,14 +366,14 @@ namespace sts::pm::impl {
}
break;
case ProcessState_Exited:
if (GetRuntimeFirmwareVersion() < FirmwareVersion_500 && process_info->ShouldSignalOnExit()) {
if (hos::GetVersion() < hos::Version_500 && process_info->ShouldSignalOnExit()) {
g_process_event.Signal();
} else {
/* Free process resources, unlink from waitable manager. */
process_info->Cleanup();
/* Handle the case where we need to keep the process alive some time longer. */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 && process_info->ShouldSignalOnExit()) {
if (hos::GetVersion() >= hos::Version_500 && process_info->ShouldSignalOnExit()) {
/* Remove from the living list. */
list->Remove(process_info);
@@ -425,7 +425,7 @@ namespace sts::pm::impl {
}
/* Process Management. */
Result LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 flags) {
Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 flags) {
/* Ensure we only try to launch one title at a time. */
static os::Mutex s_lock;
std::scoped_lock lk(s_lock);
@@ -442,7 +442,7 @@ namespace sts::pm::impl {
return g_process_launch_result;
}
Result StartProcess(u64 process_id) {
Result StartProcess(os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
@@ -459,7 +459,7 @@ namespace sts::pm::impl {
return StartProcess(process_info, &program_info);
}
Result TerminateProcess(u64 process_id) {
Result TerminateProcess(os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
@@ -515,7 +515,7 @@ namespace sts::pm::impl {
out->process_id = process.GetProcessId();
return ResultSuccess;
}
if (GetRuntimeFirmwareVersion() < FirmwareVersion_500 && process.ShouldSignalOnExit() && process.HasExited()) {
if (hos::GetVersion() < hos::Version_500 && process.ShouldSignalOnExit() && process.HasExited()) {
out->event = GetProcessEventValue(ProcessEvent::Exited);
out->process_id = process.GetProcessId();
return ResultSuccess;
@@ -524,7 +524,7 @@ namespace sts::pm::impl {
}
/* Check for event from exited process. */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
if (hos::GetVersion() >= hos::Version_500) {
ProcessListAccessor dead_list(g_dead_process_list);
if (!dead_list->empty()) {
@@ -537,12 +537,12 @@ namespace sts::pm::impl {
}
}
out->process_id = 0;
out->process_id = os::ProcessId{};
out->event = GetProcessEventValue(ProcessEvent::None);
return ResultSuccess;
}
Result CleanupProcess(u64 process_id) {
Result CleanupProcess(os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
@@ -558,7 +558,7 @@ namespace sts::pm::impl {
return ResultSuccess;
}
Result ClearExceptionOccurred(u64 process_id) {
Result ClearExceptionOccurred(os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
@@ -577,7 +577,7 @@ namespace sts::pm::impl {
return ResultSuccess;
}
Result GetExceptionProcessIdList(u32 *out_count, u64 *out_process_ids, size_t max_out_count) {
Result GetExceptionProcessIdList(u32 *out_count, os::ProcessId *out_process_ids, size_t max_out_count) {
ProcessListAccessor list(g_process_list);
size_t count = 0;
@@ -590,7 +590,7 @@ namespace sts::pm::impl {
return ResultSuccess;
}
Result GetProcessId(u64 *out, ncm::TitleId title_id) {
Result GetProcessId(os::ProcessId *out, ncm::TitleId title_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(title_id);
@@ -602,7 +602,7 @@ namespace sts::pm::impl {
return ResultSuccess;
}
Result GetTitleId(ncm::TitleId *out, u64 process_id) {
Result GetTitleId(ncm::TitleId *out, os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
@@ -614,7 +614,7 @@ namespace sts::pm::impl {
return ResultSuccess;
}
Result GetApplicationProcessId(u64 *out_process_id) {
Result GetApplicationProcessId(os::ProcessId *out_process_id) {
ProcessListAccessor list(g_process_list);
for (auto &process : *list) {
@@ -627,7 +627,7 @@ namespace sts::pm::impl {
return ResultPmProcessNotFound;
}
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, u64 process_id) {
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);

View File

@@ -26,22 +26,22 @@ namespace sts::pm::impl {
Result InitializeProcessManager();
/* Process Management. */
Result LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 flags);
Result StartProcess(u64 process_id);
Result TerminateProcess(u64 process_id);
Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 flags);
Result StartProcess(os::ProcessId process_id);
Result TerminateProcess(os::ProcessId process_id);
Result TerminateTitle(ncm::TitleId title_id);
Result GetProcessEventHandle(Handle *out);
Result GetProcessEventInfo(ProcessEventInfo *out);
Result CleanupProcess(u64 process_id);
Result ClearExceptionOccurred(u64 process_id);
Result CleanupProcess(os::ProcessId process_id);
Result ClearExceptionOccurred(os::ProcessId process_id);
/* Information Getters. */
Result GetModuleIdList(u32 *out_count, u8 *out_buf, size_t max_out_count, u64 unused);
Result GetExceptionProcessIdList(u32 *out_count, u64 *out_process_ids, size_t max_out_count);
Result GetProcessId(u64 *out, ncm::TitleId title_id);
Result GetTitleId(ncm::TitleId *out, u64 process_id);
Result GetApplicationProcessId(u64 *out_process_id);
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, u64 process_id);
Result GetExceptionProcessIdList(u32 *out_count, os::ProcessId *out_process_ids, size_t max_out_count);
Result GetProcessId(os::ProcessId *out, ncm::TitleId title_id);
Result GetTitleId(ncm::TitleId *out, os::ProcessId process_id);
Result GetApplicationProcessId(os::ProcessId *out_process_id);
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id);
/* Hook API. */
Result HookToCreateProcess(Handle *out_hook, ncm::TitleId title_id);

View File

@@ -182,9 +182,9 @@ namespace sts::pm::resource {
}
}
/* Adjust resource limits based on firmware version. */
const auto firmware_version = GetRuntimeFirmwareVersion();
if (firmware_version >= FirmwareVersion_400) {
/* Adjust resource limits based on hos firmware version. */
const auto hos_version = hos::GetVersion();
if (hos_version >= hos::Version_400) {
/* 4.0.0 increased the system thread limit. */
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] += ExtraSystemThreadCount400;
/* 4.0.0 also took memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */
@@ -193,21 +193,21 @@ namespace sts::pm::resource {
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_System] += ExtraSystemMemorySize400;
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize400;
}
if (firmware_version >= FirmwareVersion_500) {
if (hos_version >= hos::Version_500) {
/* 5.0.0 took more memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_System] += ExtraSystemMemorySize500;
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize500;
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_System] += ExtraSystemMemorySize500;
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize500;
}
if (firmware_version >= FirmwareVersion_600) {
if (hos_version >= hos::Version_600) {
/* 6.0.0 increased the system event and session limits. */
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Events] += ExtraSystemEventCount600;
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Sessions] += ExtraSystemSessionCount600;
}
/* 7.0.0+: Calculate the number of extra application threads available. */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_700) {
if (hos::GetVersion() >= hos::Version_700) {
/* See how many threads we have available. */
u64 total_threads_available = 0;
R_ASSERT(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads));
@@ -225,7 +225,7 @@ namespace sts::pm::resource {
}
/* Choose and initialize memory arrangement. */
if (firmware_version >= FirmwareVersion_600) {
if (hos_version >= hos::Version_600) {
/* 6.0.0 retrieves memory limit information from the kernel, rather than using a hardcoded profile. */
g_memory_arrangement = spl::MemoryArrangement_Dynamic;
@@ -253,7 +253,7 @@ namespace sts::pm::resource {
/* We take memory away from applet normally, but away from application on < 3.0.0 to avoid a rare hang on boot. */
for (size_t i = 0; i < spl::MemoryArrangement_Count; i++) {
g_memory_resource_limits[i][ResourceLimitGroup_System] += ExtraSystemMemorySizeAtmosphere;
if (firmware_version >= FirmwareVersion_300) {
if (hos_version >= hos::Version_300) {
g_memory_resource_limits[i][ResourceLimitGroup_Applet] -= ExtraSystemMemorySizeAtmosphere;
} else {
g_memory_resource_limits[i][ResourceLimitGroup_Application] -= ExtraSystemMemorySizeAtmosphere;
@@ -282,7 +282,7 @@ namespace sts::pm::resource {
{
std::scoped_lock lk(g_resource_limit_lock);
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
if (hos::GetVersion() >= hos::Version_500) {
/* 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) {
R_TRY(svcSetUnsafeLimit(boost_size));
@@ -332,7 +332,7 @@ namespace sts::pm::resource {
void WaitResourceAvailable(const ldr::ProgramInfo *info) {
if (GetResourceLimitGroup(info) == ResourceLimitGroup_Application) {
WaitResourceAvailable(ResourceLimitGroup_Application);
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
if (hos::GetVersion() >= hos::Version_500) {
WaitApplicationMemoryAvailable();
}
}