Fix chainload method used when HM is not launched.
We now wait for custom PM to change our launch flag and ask us to
terminate. We previously had a few issues:
- a potential race condition where we exit before PM changes our
runflags (not observed)
- a kernel deadlock between ExitProcess and TerminateProcess (observed,
this is due to Nintendo's lack of barrier in many of their atomics
code)
- debuggers reporting that we were terminated, instead of exiting
gracefully (not desirable)
- DSP wrapper is now in charge of handling sleep/awake/cancel events
- Added DSP hook mechanism (similar to APT hook)
- The DSP component now gets automatically unloaded/reloaded as needed
- NDSP now uses DSP hook instead of APT hook to manage lifetime
- Moved sleep/wakeup component management logic into NDSP
- APT now calls into DSP wrapper in order to arbitrate access to the DSP
- Launching libapplets no longer relinquishes DSP rights - this means
music can now be played in the background during libapplet activity
- APT parameter handling now follows official sw a bit more closely
(with the APT thread acting as a filter which then relays the
status to the main thread using a LightEvent)
- RUNFLAG_APTREINIT (hax 2.x) handling code has been simplified and
made (hopefully) more robust
- Fixed sleep handling when the app is inactive (i.e. app is suspended)
- APT debug callback now guarded by an #ifdef (LIBCTRU_APT_DEBUG)
- Removed old Citra response cmdheader workaround
- Other miscellaneous fixes I probably forgot to talk about
- Internal logic changes in order to follow official behavior
more closely - the APT state machine has been removed.
- The following functions were removed:
* aptSetStatus/aptGetStatus along with the APT_AppStatus enum
* aptGetStatusPower/aptSetStatusPower
* aptReturnToMenu
* aptWaitStatusEvent, aptSignalReadyForSleep
- Library applet launching is now fully supported on both official
environments (ncch/cia) and homebrew environments (3dsx).
APT_LaunchLibraryApplet has been replaced with aptLaunchLibraryApplet.
- Added aptSetMessageCallback (intended for use with libapplet code)
- Added APT_CancelParameter
- Some other misc changes
- Each service must have xyzInit/xyzExit (with that name)
- xyzInit/xyzExit use reference counting
- xyzExit returns void
- The utilities in <3ds/result.h> are used instead of manual error checking
- The intrinsics in <3ds/synchronization.h> are used instead of inline asm
- Other miscellaneous changes
- APT now uses a lightweight lock instead of a mutex
- Initial handle parameters in PTMU were killed
- Explicit init'ion to 0 or NULL has been removed for global variables
since they end up on .bss anyway
- MIC hasn't been touched because it must be rewritten first
- CFGNOR needs a slight touch before converting
- SOC is still to be cleaned up