MCPcopy Create free account
hub / github.com/devkitPro/libctru / aptExit

Function aptExit

libctru/source/services/apt.c:371–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369}
370
371void aptExit(void)
372{
373 if (AtomicDecrement(&aptRefCount)) return;
374
375 bool closeAptLock = true;
376 bool doDirtyChainload = false;
377
378 if (!aptIsCrippled())
379 {
380 bool doClose;
381 if (aptShouldClose())
382 {
383 // The system instructed us to close, so do just that
384 aptCallHook(APTHOOK_ONEXIT);
385 doClose = true;
386 }
387 else if (aptIsReinit())
388 {
389 // The homebrew environment expects APT to be reinitializable, so unregister ourselves without closing
390 APT_Finalize(envGetAptAppId());
391 doClose = false;
392 }
393 else if (aptFlags & FLAG_CHAINLOAD)
394 {
395 // A chainload target is configured, so perform a jump to it
396 // Doing this requires help from HOME menu, so ensure that it is running
397 bool hmRegistered;
398 if (R_SUCCEEDED(APT_IsRegistered(aptGetMenuAppID(), &hmRegistered)) && hmRegistered)
399 {
400 // Normal, sane chainload
401 APT_PrepareToDoApplicationJump(aptChainloadFlags, aptChainloadTid, aptChainloadMediatype);
402 APT_DoApplicationJump(aptChainloadDeliverArg, aptChainloadDeliverArgSize, aptChainloadHmac);
403 }
404 else
405 {
406 // XX: HOME menu doesn't exist, so we need to use a workaround provided by Luma3DS
407 APT_Finalize(envGetAptAppId());
408 doDirtyChainload = true;
409 }
410
411 // After a chainload has been applied, we don't need to manually close
412 doClose = false;
413 __system_retAddr = NULL;
414 }
415 else
416 {
417 // None of the other situations apply, so close anyway by default
418 doClose = true;
419 }
420
421 // If needed, perform the APT application closing sequence
422 if (doClose)
423 {
424 APT_PrepareToCloseApplication(true);
425
426 // APT_CloseApplication kills us if we aren't signed up for srv closing notifications, so
427 // defer APT_CloseApplication for as long as possible (TODO: actually use srv notif instead)
428 __system_retAddr = aptExitProcess;

Callers 1

__appExitFunction · 0.85

Calls 15

aptIsCrippledFunction · 0.85
aptShouldCloseFunction · 0.85
aptCallHookFunction · 0.85
aptIsReinitFunction · 0.85
APT_FinalizeFunction · 0.85
envGetAptAppIdFunction · 0.85
APT_IsRegisteredFunction · 0.85
aptGetMenuAppIDFunction · 0.85
APT_DoApplicationJumpFunction · 0.85
srvInitFunction · 0.85

Tested by

no test coverage detected