Skip to content

Commit

Permalink
env: Add support for svc 0x80..0xBF hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
fincs committed Oct 12, 2022
1 parent de4d19d commit 8b77139
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions nx/include/switch/runtime/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum {
EntryType_OverrideHeap=3, ///< Provides heap override information.
EntryType_OverrideService=4, ///< Provides service override information.
EntryType_Argv=5, ///< Provides argv.
EntryType_SyscallAvailableHint=6, ///< Provides syscall availability hints.
EntryType_SyscallAvailableHint=6, ///< Provides syscall availability hints (SVCs 0x00..0x7F).
EntryType_AppletType=7, ///< Provides APT applet type.
EntryType_AppletWorkaround=8, ///< Indicates that APT is broken and should not be used.
EntryType_Reserved9=9, ///< Unused/reserved entry type, formerly used by StdioSockets.
Expand All @@ -37,6 +37,7 @@ enum {
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.
EntryType_SyscallAvailableHint2=17, ///< Provides syscall availability hints (SVCs 0x80..0xBF).
};

enum {
Expand Down Expand Up @@ -81,7 +82,7 @@ void* envGetArgv(void);
* @param svc Syscall number to test.
* @returns true if the syscall is available.
*/
bool envIsSyscallHinted(u8 svc);
bool envIsSyscallHinted(unsigned svc);

/// Returns the handle to the running homebrew process.
Handle envGetOwnProcessHandle(void);
Expand Down
11 changes: 8 additions & 3 deletions nx/source/runtime/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static LoaderReturnFn g_loaderRetAddr = NULL;
static void* g_overrideHeapAddr = NULL;
static u64 g_overrideHeapSize = 0;
static void* g_overrideArgv = NULL;
static u64 g_syscallHints[2];
static u64 g_syscallHints[3];
static Handle g_processHandle = INVALID_HANDLE;
static char* g_nextLoadPath = NULL;
static char* g_nextLoadArgv = NULL;
Expand All @@ -37,7 +37,7 @@ void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr)
g_isNso = true;
g_mainThreadHandle = main_thread;
g_loaderRetAddr = (LoaderReturnFn) &svcExitProcess;
g_syscallHints[0] = g_syscallHints[1] = UINT64_MAX;
g_syscallHints[0] = g_syscallHints[1] = g_syscallHints[2] = UINT64_MAX;
return;
}

Expand Down Expand Up @@ -110,6 +110,10 @@ void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr)
break;
}

case EntryType_SyscallAvailableHint2:
g_syscallHints[2] = ent->Value[0];
break;

default:
if (ent->Flags & EntryFlag_IsMandatory)
{
Expand Down Expand Up @@ -170,7 +174,8 @@ void* envGetArgv(void) {
return g_overrideArgv;
}

bool envIsSyscallHinted(u8 svc) {
bool envIsSyscallHinted(unsigned svc) {
if (svc >= 0xC0) return false;
return !!(g_syscallHints[svc/64] & (1ull << (svc%64)));
}

Expand Down

0 comments on commit 8b77139

Please sign in to comment.