| 369 | } |
| 370 | |
| 371 | void 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; |
no test coverage detected