pm: update for libstratosphere refactor
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
static ProcessList g_process_list;
|
||||
static ProcessList g_dead_process_list;
|
||||
|
||||
static SystemEvent *g_process_launch_start_event = NULL;
|
||||
static IEvent *g_process_launch_start_event = nullptr;
|
||||
static HosSemaphore g_sema_finish_launch;
|
||||
|
||||
static HosMutex g_process_launch_mutex;
|
||||
@@ -34,29 +34,27 @@ static Registration::ProcessLaunchState g_process_launch_state;
|
||||
static std::atomic_bool g_debug_next_application(false);
|
||||
static std::atomic<u64> g_debug_on_launch_tid(0);
|
||||
|
||||
static SystemEvent *g_process_event = NULL;
|
||||
static SystemEvent *g_debug_title_event = NULL;
|
||||
static SystemEvent *g_debug_application_event = NULL;
|
||||
static IEvent *g_process_event = nullptr;
|
||||
static IEvent *g_debug_title_event = nullptr;
|
||||
static IEvent *g_debug_application_event = nullptr;
|
||||
|
||||
std::unique_lock<HosRecursiveMutex> Registration::GetProcessListUniqueLock() {
|
||||
return g_process_list.get_unique_lock();
|
||||
}
|
||||
|
||||
void Registration::SetProcessListManager(WaitableManager *m) {
|
||||
g_process_list.set_manager(m);
|
||||
return g_process_list.GetUniqueLock();
|
||||
}
|
||||
|
||||
void Registration::InitializeSystemResources() {
|
||||
g_process_event = new SystemEvent(NULL, &IEvent::PanicCallback);
|
||||
g_debug_title_event = new SystemEvent(NULL, &IEvent::PanicCallback);
|
||||
g_debug_application_event = new SystemEvent(NULL, &IEvent::PanicCallback);
|
||||
g_process_launch_start_event = new SystemEvent(NULL, &Registration::ProcessLaunchStartCallback);
|
||||
g_process_event = CreateWriteOnlySystemEvent();
|
||||
g_debug_title_event = CreateWriteOnlySystemEvent();
|
||||
g_debug_application_event = CreateWriteOnlySystemEvent();
|
||||
|
||||
/* Auto-clear non-system event. */
|
||||
g_process_launch_start_event = CreateSystemEvent(&Registration::ProcessLaunchStartCallback);
|
||||
|
||||
ResourceLimitUtils::InitializeLimits();
|
||||
}
|
||||
|
||||
Result Registration::ProcessLaunchStartCallback(void *arg, Handle *handles, size_t num_handles, u64 timeout) {
|
||||
svcClearEvent(handles[0]);
|
||||
Result Registration::ProcessLaunchStartCallback(u64 timeout) {
|
||||
g_process_launch_start_event->Clear();
|
||||
Registration::HandleProcessLaunch();
|
||||
return 0;
|
||||
}
|
||||
@@ -138,11 +136,11 @@ void Registration::HandleProcessLaunch() {
|
||||
|
||||
/* Signal, if relevant. */
|
||||
if (new_process.tid_sid.title_id == g_debug_on_launch_tid.load()) {
|
||||
g_debug_title_event->signal_event();
|
||||
g_debug_title_event->Signal();
|
||||
g_debug_on_launch_tid = 0;
|
||||
rc = 0;
|
||||
} else if ((new_process.flags & PROCESSFLAGS_APPLICATION) && g_debug_next_application.load()) {
|
||||
g_debug_application_event->signal_event();
|
||||
g_debug_application_event->Signal();
|
||||
g_debug_next_application = false;
|
||||
rc = 0;
|
||||
} else if (LAUNCHFLAGS_STARTSUSPENDED(launch_flags)) {
|
||||
@@ -181,6 +179,7 @@ HANDLE_PROCESS_LAUNCH_END:
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out_pid = new_process.pid;
|
||||
}
|
||||
|
||||
g_sema_finish_launch.Signal();
|
||||
}
|
||||
|
||||
@@ -220,9 +219,9 @@ Result Registration::LaunchProcess(u64 title_id, FsStorageId storage_id, u64 lau
|
||||
g_process_launch_state.out_pid = out_pid;
|
||||
|
||||
/* Start a launch, and wait for it to exit. */
|
||||
g_process_launch_start_event->signal_event();
|
||||
g_process_launch_start_event->Signal();
|
||||
g_sema_finish_launch.Wait();
|
||||
|
||||
|
||||
return g_process_launch_state.result;
|
||||
}
|
||||
|
||||
@@ -253,7 +252,7 @@ Result Registration::HandleSignaledProcess(std::shared_ptr<Registration::Process
|
||||
if (process->flags & PROCESSFLAGS_NOTIFYDEBUGEVENTS) {
|
||||
process->flags &= ~(PROCESSFLAGS_DEBUGEVENTPENDING | PROCESSFLAGS_DEBUGSUSPENDED);
|
||||
process->flags |= PROCESSFLAGS_DEBUGEVENTPENDING;
|
||||
g_process_event->signal_event();
|
||||
g_process_event->Signal();
|
||||
}
|
||||
if (kernelAbove200() && process->flags & PROCESSFLAGS_NOTIFYDEBUGSPECIAL) {
|
||||
process->flags &= ~(PROCESSFLAGS_NOTIFYDEBUGSPECIAL | PROCESSFLAGS_DEBUGDETACHED);
|
||||
@@ -262,18 +261,18 @@ Result Registration::HandleSignaledProcess(std::shared_ptr<Registration::Process
|
||||
break;
|
||||
case ProcessState_Crashed:
|
||||
process->flags |= (PROCESSFLAGS_CRASHED | PROCESSFLAGS_CRASH_DEBUG);
|
||||
g_process_event->signal_event();
|
||||
g_process_event->Signal();
|
||||
break;
|
||||
case ProcessState_RunningAttached:
|
||||
if (process->flags & PROCESSFLAGS_NOTIFYDEBUGEVENTS) {
|
||||
process->flags &= ~(PROCESSFLAGS_DEBUGEVENTPENDING | PROCESSFLAGS_DEBUGSUSPENDED);
|
||||
process->flags |= PROCESSFLAGS_DEBUGEVENTPENDING;
|
||||
g_process_event->signal_event();
|
||||
g_process_event->Signal();
|
||||
}
|
||||
break;
|
||||
case ProcessState_Exited:
|
||||
if (process->flags & PROCESSFLAGS_NOTIFYWHENEXITED && !kernelAbove500()) {
|
||||
g_process_event->signal_event();
|
||||
g_process_event->Signal();
|
||||
} else {
|
||||
FinalizeExitedProcess(process);
|
||||
}
|
||||
@@ -281,7 +280,7 @@ Result Registration::HandleSignaledProcess(std::shared_ptr<Registration::Process
|
||||
case ProcessState_DebugSuspended:
|
||||
if (process->flags & PROCESSFLAGS_NOTIFYDEBUGEVENTS) {
|
||||
process->flags |= (PROCESSFLAGS_DEBUGEVENTPENDING | PROCESSFLAGS_DEBUGSUSPENDED);
|
||||
g_process_event->signal_event();
|
||||
g_process_event->Signal();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -310,7 +309,7 @@ void Registration::FinalizeExitedProcess(std::shared_ptr<Registration::Process>
|
||||
|
||||
/* Insert into dead process list, if relevant. */
|
||||
if (signal_debug_process_5x) {
|
||||
auto lk = g_dead_process_list.get_unique_lock();
|
||||
auto lk = g_dead_process_list.GetUniqueLock();
|
||||
g_dead_process_list.processes.push_back(process);
|
||||
}
|
||||
|
||||
@@ -319,14 +318,14 @@ void Registration::FinalizeExitedProcess(std::shared_ptr<Registration::Process>
|
||||
|
||||
auto_lock.unlock();
|
||||
if (signal_debug_process_5x) {
|
||||
g_process_event->signal_event();
|
||||
g_process_event->Signal();
|
||||
}
|
||||
}
|
||||
|
||||
void Registration::AddProcessToList(std::shared_ptr<Registration::Process> process) {
|
||||
auto auto_lock = GetProcessListUniqueLock();
|
||||
g_process_list.processes.push_back(process);
|
||||
g_process_list.get_manager()->add_waitable(new ProcessWaiter(process));
|
||||
g_process_launch_start_event->GetManager()->AddWaitable(new ProcessWaiter(process));
|
||||
}
|
||||
|
||||
void Registration::RemoveProcessFromList(u64 pid) {
|
||||
@@ -412,7 +411,7 @@ Result Registration::GetDebugProcessIds(u64 *out_pids, u32 max_out, u32 *num_out
|
||||
}
|
||||
|
||||
Handle Registration::GetProcessEventHandle() {
|
||||
return g_process_event->get_handle();
|
||||
return g_process_event->GetHandle();
|
||||
}
|
||||
|
||||
void Registration::GetProcessEventType(u64 *out_pid, u64 *out_type) {
|
||||
@@ -451,7 +450,7 @@ void Registration::GetProcessEventType(u64 *out_pid, u64 *out_type) {
|
||||
}
|
||||
if (kernelAbove500()) {
|
||||
auto_lock.unlock();
|
||||
auto dead_process_list_lock = g_dead_process_list.get_unique_lock();
|
||||
auto dead_process_list_lock = g_dead_process_list.GetUniqueLock();
|
||||
if (g_dead_process_list.processes.size()) {
|
||||
std::shared_ptr<Registration::Process> process = g_dead_process_list.processes[0];
|
||||
g_dead_process_list.processes.erase(g_dead_process_list.processes.begin());
|
||||
@@ -471,13 +470,13 @@ Result Registration::EnableDebugForTitleId(u64 tid, Handle *out) {
|
||||
g_debug_on_launch_tid = old;
|
||||
return 0x80F;
|
||||
}
|
||||
*out = g_debug_title_event->get_handle();
|
||||
*out = g_debug_title_event->GetHandle();
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
Result Registration::EnableDebugForApplication(Handle *out) {
|
||||
g_debug_next_application = true;
|
||||
*out = g_debug_application_event->get_handle();
|
||||
*out = g_debug_application_event->GetHandle();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user