Changes

no edit summary
Line 1: Line 1:  +
= Process Tracker thread =
 
PM has a separate thread that is waiting for synchronization on process handles.
 
PM has a separate thread that is waiting for synchronization on process handles.
    +
== State changes ==
 
When the kernel signals a process handle, it uses svcResetSignal on the process handle and then it uses svcGetProcessInfo to read out the ProcessState.
 
When the kernel signals a process handle, it uses svcResetSignal on the process handle and then it uses svcGetProcessInfo to read out the ProcessState.
   Line 14: Line 16:     
If mask 1 is not set, it immediately does what is otherwise done by the [[#FinalizeDeadProcess]] command.
 
If mask 1 is not set, it immediately does what is otherwise done by the [[#FinalizeDeadProcess]] command.
 +
 +
== Process launch ==
 +
This thread can also be triggered by the pm:shell [[#LaunchProcess]] cmd.
 +
 +
It uses [[Loader_services|ldr:pm]] GetProgramInfo with the supplied title-id.
 +
 +
If ((*(u8*) (info_output+2)) & 3) is == 1, it goes through the process list and errors if any has bit 0x40 set. Thus only one process can have bit 0x40 set at a time.
 +
 +
It calls [[Loader_services|ldr:pm]] RegisterTitle, then [[Loader_services|ldr:pm]] CreateProcess, then [[Filesystem_services|fsp-pr]] RegisterTitle, then [[Services_API|sm:m]] RegisterTitle.
 +
 +
The second input argument for [[Loader_services|ldr:pm]] CreateProcess is (launch_flags >> 2) & 3.
 +
 +
If launch_flags has mask 1 set, it sets mask 1 in process flags.
 +
 +
If launch_flags flags has mask 0x10 set, it sets mask 8 in process flags.
 +
 +
If ((*(u8*) (info_output+2)) & 3) is == 1, it sets 0x40 in the process flags, and signals the event returned by [[#EnableDebug]].
 +
 +
Finally it does svcStartProcess on the process handle that was returned by [[Loader_services|ldr:pm]] CreateProcess.
 +
 +
Thus at the point of launch, the pid is already registered in ldr, fs, sm, and pm.
    
= pm:bm =
 
= pm:bm =
Line 38: Line 61:  
| 3 || GetProcessTitleIdByPid
 
| 3 || GetProcessTitleIdByPid
 
|-
 
|-
| 4 || .. Returns a handle.
+
| 4 || [[#EnableDebugForTitleId]]
 
|-
 
|-
 
| 5 || GetCrashingProcessPid
 
| 5 || GetCrashingProcessPid
 
|-
 
|-
| 6 || .. Returns a handle.
+
| 6 || [[#EnableDebug]]
 
|}
 
|}
   Line 55: Line 78:     
After that, it sets process state to 2.
 
After that, it sets process state to 2.
 +
 +
== EnableDebugForTitleId ==
 +
Takes a title-id of the program to debug. Sets this to a global field. Next time it gets launched it will be handled differently.
 +
 +
Returns an event handle that is signaled when the requested title is launched.
 +
 +
== EnableDebug ==
 +
Does *not* take a specific title-id as input.
 +
 +
Returns an event handle that is triggered for debug titles.
    
= pm:info =
 
= pm:info =
Line 69: Line 102:  
! Cmd || Name
 
! Cmd || Name
 
|-
 
|-
| 0 || LaunchProcess
+
| 0 || [[#LaunchProcess]]
 
|-
 
|-
 
| 1 || TerminateProcessByPid
 
| 1 || TerminateProcessByPid
Line 87: Line 120:  
| 8 || [[#GetCrashingProcessPid]]
 
| 8 || [[#GetCrashingProcessPid]]
 
|}
 
|}
 +
 +
== LaunchProcess ==
 +
Takes a title-id and launch_flags. See [[#Process launch]].
    
== FinalizeDeadProcess ==
 
== FinalizeDeadProcess ==