env: Add support for svc 0x80..0xBF hinting

This commit is contained in:
fincs 2022-10-12 19:42:37 +02:00
parent de4d19df1a
commit 8b77139a04
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 11 additions and 5 deletions

View File

@ -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.
@ -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 {
@ -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);

View File

@ -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;
@ -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;
}
@ -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)
{
@ -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)));
}