PGL services

Revision as of 23:43, 15 April 2020 by SciresM (talk | contribs)

PGL (Program Loader) is a sysmodule designed for encapsulating all program loading logic.

pgl

Cmd Name
0 #LaunchProgram
1 #TerminateProcess
2 #LaunchProgramFromHost
4 #GetHostContentMetaInfo
5 #GetApplicationProcessId
6 #BoostSystemMemoryResourceLimit
7 #IsProcessTracked
8 #EnableApplicationCrashReport
9 #IsApplicationCrashReportEnabled
10 #EnableApplicationAllThreadDumpOnCrash
12 #TriggerSnapShotDumper
20 #GetShellEventObserver

LaunchFlags

The LaunchFlags enum looks like this:

Bit Mask Name
0 1 LaunchFlags_EnableDetailedCrashReport
1 2 LaunchFlags_EnableCrashReportScreenShotForProduction
2 4 LaunchFlags_EnableCrashReportScreenShotForDevelop

ContentMetaInfo

Offset Size Description
0x0 0x8 ProgramId
0x8 0x4 Version
0xC 0x1 ContentType
0xD 0x1 ID Offset
0xE 0x2 Padding


LaunchProgram

Takes a ProgramLocation, a u32 Process_Manager_services#LaunchFlags pm launch_flags, and a u8 LaunchFlags pgl launch_flags.

This calls pm:shell->LaunchProgram with the program location and the input launch flags. If jit_debug!enable_jit_debug is true, LaunchFlags_SignalOnCrash is ORRd into the flags sent to PM.

This then creates a new process tracking structure for the new process id and with the pgl launch flags. If an empty process struct is not allocated from the 0x20 slab heap, pgl aborts.

If settings::GetDebugModeFlag() returns 1, then LaunchFlags_EnableCrashReportScreenShotForDevelop is used to enable crash report screenshot, otherwise LaunchFlags_EnableCrashReportScreenShotForProduction is used.

It returns a u64 process id.

TerminateProcess

This just calls pm:shell->TerminateProcess with the input process id.

GetEventObserver

No input. Returns an #IEventObserver.

LaunchProgramFromHost

This takes an input u32 Process_Manager_services#LaunchFlags pm launch_flags and a MapAlias input buffer "content path".

The content path must be to an ".nsp" file or a ".nspd" folder. "*.nspd/program0.ncd/" is also allowed.

This calls fs::MountApplicationPackage on the input content path, and reads content meta from "meta0.ncd" or ".cnmt.nca" extension folder/file depending on whether it is a .nspd or .nsp content path.

A location resolver for the Host storage is opened, and EraseProgramRedirection is called for the parsed program id.

RedierectProgramPath is then called for the program ID to set it to the input content path.

This then calls the implementation function for #LaunchProgram with the input pm launch flags and pgl launch flags = 0.

GetHostContentMetaInfo

This takes an input MapAlias buffer "content path", and does the same parsing as #LaunchProgramFromHost.

Instead of launching the program, it instead returns an 0x10 output #ContentMetaInfo from the parsed info.

GetApplicationProcessId

This calls pm:shell->GetApplicationProcessIdForShell, and returns the output process id.

Error 0x6E4 is returned when there is no application process.

BoostSystemMemoryResourceLimit

This takes in a u64 mem_size, and uses it as input to pm:shell->BoostSystemMemoryResourceLimit

EnableApplicationCrashReport

This calls pm:shell->GetApplicationProcessId. If the returned process ID is tracked, this sets or clears bit 1 (value 0x2) in the tracked process's flags.

When a process crash event occurs and pgl launches crash report, the second argument is "%d" formatted with the bitwise AND of this bit and bit 0 (value 0x1).

LaunchFlags_EnableDetailedCrashReport causes the process to have both of these flags set, otherwise they are both zero.

Thus this command is only useful for disabling/toggling detailed crash reports for applications launched with LaunchFlags_EnableDetailedCrashReport, as processes without the launch flag will always send "0" for the creport argument.

IsApplicationCrashReportEnabled

This returns the value of the bit set or cleared by #EnableApplicationCrashReport

EnableApplicationAllThreadDumpOnCrash

TriggerSnapShotDumper

IEventObserver

Cmd Name
0 #GetProcessEventHandle
1 #GetProcessEventInfo

GetProcessEventHandle

This takes no input and returns an output copy event handle.

GetProcessEventInfo

This takes no input and attempts to receive a #ProcessEventInfo from the observer's message queue.

Every time a process event occurs, pgl receives the event from PM (it does pm:shell->GetProcessEventHandle() during startup and has a thread looping pm:shell->GetProcessEventInfo() to track process events.

PGL sends to all observers' message queues a #ProcessEventInfo for each event it receives, thus allowing for multiple subscribers to process events.


ProcessEventInfo

Offset Size Description
0x0 0x8 ProcessId
0x8 0x4 ProcessEvent
0xC 0x4 Padding/Reserved