mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Add support for new homebrew ABI keys + loader info
This commit is contained in:
parent
409957c432
commit
01d648e7ed
@ -34,6 +34,8 @@ enum {
|
||||
EntryType_ProcessHandle=10, ///< Provides the process handle.
|
||||
EntryType_LastLoadResult=11, ///< Provides the last load result.
|
||||
EntryType_RandomSeed=14, ///< Provides random data used to seed the pseudo-random number generator.
|
||||
EntryType_UserIdStorage=15, ///< Provides persistent storage for the preselected user id.
|
||||
EntryType_HosVersion=16, ///< Provides the currently running Horizon OS version.
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -51,6 +53,11 @@ typedef void NORETURN (*LoaderReturnFn)(int result_code);
|
||||
*/
|
||||
void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr);
|
||||
|
||||
/// Returns information text about the loader, if present.
|
||||
const char* envGetLoaderInfo(void);
|
||||
/// Returns the size of the loader information text.
|
||||
u64 envGetLoaderInfoSize(void);
|
||||
|
||||
/// Retrieves the handle to the main thread.
|
||||
Handle envGetMainThreadHandle(void);
|
||||
/// Returns true if the application is running as NSO, otherwise NRO.
|
||||
@ -105,3 +112,6 @@ bool envHasRandomSeed(void);
|
||||
* @param out Pointer to a u64[2] buffer which will contain the random seed on return.
|
||||
*/
|
||||
void envGetRandomSeed(u64 out[2]);
|
||||
|
||||
/// Returns a pointer to the user id storage area (if present).
|
||||
u128* envGetUserIdStorage(void);
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright 2018 plutoo
|
||||
#include <string.h>
|
||||
#include "runtime/env.h"
|
||||
#include "runtime/hosversion.h"
|
||||
#include "services/sm.h"
|
||||
#include "services/fatal.h"
|
||||
#include "services/applet.h"
|
||||
@ -8,6 +9,8 @@
|
||||
void NORETURN __nx_exit(Result rc, LoaderReturnFn retaddr);
|
||||
|
||||
static bool g_isNso = false;
|
||||
static const char* g_loaderInfo = NULL;
|
||||
static u64 g_loaderInfoSize = 0;
|
||||
static Handle g_mainThreadHandle = INVALID_HANDLE;
|
||||
static LoaderReturnFn g_loaderRetAddr = NULL;
|
||||
static void* g_overrideHeapAddr = NULL;
|
||||
@ -20,6 +23,7 @@ static char* g_nextLoadArgv = NULL;
|
||||
static Result g_lastLoadResult = 0;
|
||||
static bool g_hasRandomSeed = false;
|
||||
static u64 g_randomSeed[2] = { 0, 0 };
|
||||
static u128* g_userIdStorage = NULL;
|
||||
|
||||
extern __attribute__((weak)) u32 __nx_applet_type;
|
||||
|
||||
@ -99,6 +103,14 @@ void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr)
|
||||
g_randomSeed[1] = ent->Value[1];
|
||||
break;
|
||||
|
||||
case EntryType_UserIdStorage:
|
||||
g_userIdStorage = (u128*)(uintptr_t)ent->Value[0];
|
||||
break;
|
||||
|
||||
case EntryType_HosVersion:
|
||||
hosversionSet(ent->Value[0]);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ent->Flags & EntryFlag_IsMandatory)
|
||||
{
|
||||
@ -112,6 +124,19 @@ void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr)
|
||||
ent++;
|
||||
}
|
||||
|
||||
g_loaderInfoSize = ent->Value[1];
|
||||
if (g_loaderInfoSize) {
|
||||
g_loaderInfo = (const char*)(uintptr_t)ent->Value[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char* envGetLoaderInfo(void) {
|
||||
return g_loaderInfo;
|
||||
}
|
||||
|
||||
u64 envGetLoaderInfoSize(void) {
|
||||
return g_loaderInfoSize;
|
||||
}
|
||||
|
||||
Handle envGetMainThreadHandle(void) {
|
||||
@ -196,3 +221,7 @@ void envGetRandomSeed(u64 out[2]) {
|
||||
out[0] = g_randomSeed[0];
|
||||
out[1] = g_randomSeed[1];
|
||||
}
|
||||
|
||||
u128* envGetUserIdStorage(void) {
|
||||
return g_userIdStorage;
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ void __attribute__((weak)) __appInit(void)
|
||||
if (R_FAILED(rc))
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
|
||||
|
||||
if (hosversionGet() == 0) {
|
||||
rc = setsysInitialize();
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
SetSysFirmwareVersion fw;
|
||||
@ -117,6 +118,7 @@ void __attribute__((weak)) __appInit(void)
|
||||
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
|
||||
setsysExit();
|
||||
}
|
||||
}
|
||||
|
||||
rc = appletInitialize();
|
||||
if (R_FAILED(rc))
|
||||
|
Loading…
Reference in New Issue
Block a user