mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-06 00:19:22 +02:00
Added automatic process exit handling with applet cmds, see __nx_applet_exit_mode. appletSelfExit is no longer user-accessible, see __nx_applet_exit_mode instead. Added envSetExitFuncPtr. Added disabled _appletSetTerminateResult func.
This commit is contained in:
parent
beef09a27e
commit
16bbf3411e
@ -76,6 +76,9 @@ Handle envGetOwnProcessHandle(void);
|
|||||||
/// Returns the loader's return function, to be called on program exit.
|
/// Returns the loader's return function, to be called on program exit.
|
||||||
LoaderReturnFn envGetExitFuncPtr(void);
|
LoaderReturnFn envGetExitFuncPtr(void);
|
||||||
|
|
||||||
|
/// Sets the return function to be called on program exit.
|
||||||
|
void envSetExitFuncPtr(LoaderReturnFn addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configures the next homebrew application to load.
|
* @brief Configures the next homebrew application to load.
|
||||||
* @param path Path to the next homebrew application to load (.nro).
|
* @param path Path to the next homebrew application to load (.nro).
|
||||||
|
@ -71,12 +71,6 @@ Result appletSetScreenShotPermission(s32 val);
|
|||||||
|
|
||||||
Result appletSetScreenShotImageOrientation(s32 val);
|
Result appletSetScreenShotImageOrientation(s32 val);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Exits the application.
|
|
||||||
* @note Can only be used with AppletType_Application.
|
|
||||||
*/
|
|
||||||
Result appletSelfExit(void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Processes the current applet status. Generally used within a main loop.
|
* @brief Processes the current applet status. Generally used within a main loop.
|
||||||
* @return Whether the application should continue running.
|
* @return Whether the application should continue running.
|
||||||
|
@ -148,6 +148,10 @@ LoaderReturnFn envGetExitFuncPtr(void) {
|
|||||||
return g_loaderRetAddr;
|
return g_loaderRetAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void envSetExitFuncPtr(LoaderReturnFn addr) {
|
||||||
|
g_loaderRetAddr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
Result envSetNextLoad(const char* path, const char* argv)
|
Result envSetNextLoad(const char* path, const char* argv)
|
||||||
{
|
{
|
||||||
if (g_nextLoadPath == NULL)
|
if (g_nextLoadPath == NULL)
|
||||||
|
@ -8,15 +8,19 @@
|
|||||||
#include "services/applet.h"
|
#include "services/applet.h"
|
||||||
#include "services/apm.h"
|
#include "services/apm.h"
|
||||||
#include "services/sm.h"
|
#include "services/sm.h"
|
||||||
|
#include "runtime/env.h"
|
||||||
|
|
||||||
__attribute__((weak)) u32 __nx_applet_type = AppletType_Default;
|
__attribute__((weak)) u32 __nx_applet_type = AppletType_Default;
|
||||||
__attribute__((weak)) bool __nx_applet_auto_notifyrunning = true;
|
__attribute__((weak)) bool __nx_applet_auto_notifyrunning = true;
|
||||||
__attribute__((weak)) u8 __nx_applet_AppletAttribute[0x80];
|
__attribute__((weak)) u8 __nx_applet_AppletAttribute[0x80];
|
||||||
__attribute__((weak)) u32 __nx_applet_PerformanceConfiguration[2] = {/*0x92220008*//*0x20004*//*0x92220007*/0, 0};
|
__attribute__((weak)) u32 __nx_applet_PerformanceConfiguration[2] = {/*0x92220008*//*0x20004*//*0x92220007*/0, 0};
|
||||||
|
//// Controls whether to use applet exit cmds during \ref appletExit. 0 (default): Only run exit cmds when running under a NSO. 1: Use exit cmds regardless. >1: Skip exit cmds.
|
||||||
|
__attribute__((weak)) u32 __nx_applet_exit_mode = 0;
|
||||||
|
|
||||||
static Service g_appletSrv;
|
static Service g_appletSrv;
|
||||||
static Service g_appletProxySession;
|
static Service g_appletProxySession;
|
||||||
static u64 g_refCnt;
|
static u64 g_refCnt;
|
||||||
|
static bool g_appletExitProcessFlag;
|
||||||
|
|
||||||
// From Get*Functions.
|
// From Get*Functions.
|
||||||
static Service g_appletIFunctions;
|
static Service g_appletIFunctions;
|
||||||
@ -66,10 +70,12 @@ static Result _appletGetPerformanceMode(u32 *out);
|
|||||||
static Result _appletSetOperationModeChangedNotification(u8 flag);
|
static Result _appletSetOperationModeChangedNotification(u8 flag);
|
||||||
static Result _appletSetPerformanceModeChangedNotification(u8 flag);
|
static Result _appletSetPerformanceModeChangedNotification(u8 flag);
|
||||||
|
|
||||||
|
static Result _appletSelfExit(void);
|
||||||
//static Result _appletLockExit(void);
|
//static Result _appletLockExit(void);
|
||||||
//static Result _appletUnlockExit(void);
|
//static Result _appletUnlockExit(void);
|
||||||
|
//static Result _appletSetTerminateResult(Result res);
|
||||||
|
|
||||||
//static Result _appletExitProcessAndReturn(void);
|
static Result _appletExitProcessAndReturn(void);
|
||||||
|
|
||||||
Result appletInitialize(void)
|
Result appletInitialize(void)
|
||||||
{
|
{
|
||||||
@ -88,6 +94,7 @@ Result appletInitialize(void)
|
|||||||
|
|
||||||
g_appletResourceUserId = 0;
|
g_appletResourceUserId = 0;
|
||||||
g_appletNotifiedRunning = 0;
|
g_appletNotifiedRunning = 0;
|
||||||
|
g_appletExitProcessFlag = 0;
|
||||||
|
|
||||||
switch (__nx_applet_type) {
|
switch (__nx_applet_type) {
|
||||||
case AppletType_Default:
|
case AppletType_Default:
|
||||||
@ -246,13 +253,37 @@ Result appletInitialize(void)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void NORETURN _appletExitProcess(int result_code) {
|
||||||
|
appletExit();
|
||||||
|
|
||||||
|
svcExitProcess();
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
void appletExit(void)
|
void appletExit(void)
|
||||||
{
|
{
|
||||||
if (atomicDecrement64(&g_refCnt) == 0)
|
if (atomicDecrement64(&g_refCnt) == 0)
|
||||||
{
|
{
|
||||||
//TODO: Enable this somehow later with more condition(s)?
|
if ((envIsNso() && __nx_applet_exit_mode==0) || __nx_applet_exit_mode==1) {
|
||||||
/*if (__nx_applet_type == AppletType_LibraryApplet)
|
if (__nx_applet_type == AppletType_Application ||
|
||||||
_appletExitProcessAndReturn();*/
|
__nx_applet_type == AppletType_SystemApplication ||
|
||||||
|
__nx_applet_type == AppletType_LibraryApplet) {
|
||||||
|
if (!g_appletExitProcessFlag) {
|
||||||
|
g_appletExitProcessFlag = 1;
|
||||||
|
atomicIncrement64(&g_refCnt);
|
||||||
|
envSetExitFuncPtr(_appletExitProcess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (__nx_applet_type == AppletType_Application || __nx_applet_type == AppletType_SystemApplication) {
|
||||||
|
//_appletSetTerminateResult(0);
|
||||||
|
_appletSelfExit();
|
||||||
|
}
|
||||||
|
if (__nx_applet_type == AppletType_LibraryApplet)
|
||||||
|
_appletExitProcessAndReturn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (g_appletMessageEventHandle != INVALID_HANDLE) {
|
if (g_appletMessageEventHandle != INVALID_HANDLE) {
|
||||||
svcCloseHandle(g_appletMessageEventHandle);
|
svcCloseHandle(g_appletMessageEventHandle);
|
||||||
@ -853,7 +884,7 @@ static Result _appletCmdNoIO(Service* session, u64 cmd_id) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result appletSelfExit(void) {
|
static Result _appletSelfExit(void) {
|
||||||
return _appletCmdNoIO(&g_appletISelfController, 0);
|
return _appletCmdNoIO(&g_appletISelfController, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1070,6 +1101,39 @@ Result appletSetScreenShotImageOrientation(s32 val) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static Result _appletSetTerminateResult(Result res) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
Result res;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 22;
|
||||||
|
raw->res = res;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&g_appletISelfController);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}*/
|
||||||
|
|
||||||
Result appletCreateManagedDisplayLayer(u64 *out) {
|
Result appletCreateManagedDisplayLayer(u64 *out) {
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
@ -1106,9 +1170,9 @@ Result appletCreateManagedDisplayLayer(u64 *out) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static Result _appletExitProcessAndReturn(void) {
|
static Result _appletExitProcessAndReturn(void) {
|
||||||
return _appletCmdNoIO(&g_appletILibraryAppletSelfAccessor, 10);
|
return _appletCmdNoIO(&g_appletILibraryAppletSelfAccessor, 10);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
u8 appletGetOperationMode(void) {
|
u8 appletGetOperationMode(void) {
|
||||||
return g_appletOperationMode;
|
return g_appletOperationMode;
|
||||||
|
Loading…
Reference in New Issue
Block a user