From 43fd137d551de96cb6afb3c3f330476a7e382821 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Sat, 2 May 2020 12:35:44 +0100 Subject: [PATCH] Use kernel version minor --- k11_extension/include/kernel.h | 10 +++++----- k11_extension/include/types.h | 9 +++++++++ k11_extension/source/svc/SendSyncRequest.c | 2 +- k11_extension/source/svc/UnmapProcessMemoryEx.c | 2 +- sysmodules/rosalina/source/hbloader.c | 2 +- sysmodules/rosalina/source/input_redirection.c | 2 +- sysmodules/sm/source/common.h | 6 ++++-- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/k11_extension/include/kernel.h b/k11_extension/include/kernel.h index 07f57fd..30da727 100644 --- a/k11_extension/include/kernel.h +++ b/k11_extension/include/kernel.h @@ -1138,15 +1138,15 @@ extern bool isN3DS; extern void *officialSVCs[0x7E]; #define KPROCESSRELATED_OFFSETOFF(classname, field) (isN3DS ? offsetof(classname##N3DS, field) :\ -((kernelVersion >= SYSTEM_VERSION(2, 44, 6)) ? offsetof(classname##O3DS8x, field) :\ +((GET_VERSION_MINOR(kernelVersion) >= 44) ? offsetof(classname##O3DS8x, field) :\ offsetof(classname##O3DSPre8x, field))) #define KPROCESSRELATED_GET_PTR(obj, field) (isN3DS ? &(obj)->N3DS.field :\ -((kernelVersion >= SYSTEM_VERSION(2, 44, 6)) ? &(obj)->O3DS8x.field :\ +((GET_VERSION_MINOR(kernelVersion) >= 44) ? &(obj)->O3DS8x.field :\ &(obj)->O3DSPre8x.field)) #define KPROCESSRELATED_GET_PTR_TYPE(type, obj, field) (isN3DS ? (type *)(&(obj)->N3DS.field) :\ -((kernelVersion >= SYSTEM_VERSION(2, 44, 6)) ? (type *)(&(obj)->O3DS8x.field) :\ +((GET_VERSION_MINOR(kernelVersion) >= 44) ? (type *)(&(obj)->O3DS8x.field) :\ (type *)(&(obj)->O3DSPre8x.field))) #define KPROCESS_OFFSETOF(field) KPROCESSRELATED_OFFSETOFF(KProcess, field) @@ -1189,7 +1189,7 @@ static inline KDebug *debugOfProcess(KProcess *process) static inline const char *classNameOfAutoObject(KAutoObject *object) { const char *name; - if(kernelVersion >= SYSTEM_VERSION(2, 46, 0)) + if(GET_VERSION_MINOR(kernelVersion) >= 46) { KClassToken tok; object->vtable->GetClassToken(&tok, object); @@ -1205,7 +1205,7 @@ extern Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Ha static inline Result createHandleForProcess(Handle *out, KProcess *process, KAutoObject *obj) { u8 token; - if(kernelVersion >= SYSTEM_VERSION(2, 46, 0)) + if(GET_VERSION_MINOR(kernelVersion) >= 46) { KClassToken tok; obj->vtable->GetClassToken(&tok, obj); diff --git a/k11_extension/include/types.h b/k11_extension/include/types.h index 0e8955e..2b6c2b0 100644 --- a/k11_extension/include/types.h +++ b/k11_extension/include/types.h @@ -78,6 +78,15 @@ typedef s32 Result; ///< Function result. #define SYSTEM_VERSION(major, minor, revision) \ (((major)<<24)|((minor)<<16)|((revision)<<8)) +/// Retrieves the major version from a packed system version. +#define GET_VERSION_MAJOR(version) ((version) >>24) + +/// Retrieves the minor version from a packed system version. +#define GET_VERSION_MINOR(version) (((version)>>16)&0xFF) + +/// Retrieves the revision version from a packed system version. +#define GET_VERSION_REVISION(version) (((version)>> 8)&0xFF) + #define CUR_THREAD_HANDLE 0xFFFF8000 #define CUR_PROCESS_HANDLE 0xFFFF8001 diff --git a/k11_extension/source/svc/SendSyncRequest.c b/k11_extension/source/svc/SendSyncRequest.c index 74762f3..0834254 100644 --- a/k11_extension/source/svc/SendSyncRequest.c +++ b/k11_extension/source/svc/SendSyncRequest.c @@ -100,7 +100,7 @@ Result SendSyncRequestHook(Handle handle) case 0x50100: { SessionInfo *info = SessionInfo_Lookup(clientSession->parentSession); - if(info != NULL && (strcmp(info->name, "srv:") == 0 || (kernelVersion < SYSTEM_VERSION(2, 39, 4) && strcmp(info->name, "srv:pm") == 0))) + if(info != NULL && (strcmp(info->name, "srv:") == 0 || (GET_VERSION_MINOR(kernelVersion) < 39 && strcmp(info->name, "srv:pm") == 0))) { char name[9] = { 0 }; memcpy(name, cmdbuf + 1, 8); diff --git a/k11_extension/source/svc/UnmapProcessMemoryEx.c b/k11_extension/source/svc/UnmapProcessMemoryEx.c index 8ee8753..f351a33 100644 --- a/k11_extension/source/svc/UnmapProcessMemoryEx.c +++ b/k11_extension/source/svc/UnmapProcessMemoryEx.c @@ -29,7 +29,7 @@ Result UnmapProcessMemoryEx(Handle processHandle, void *dst, u32 size) { - if(kernelVersion < SYSTEM_VERSION(2, 37, 0)) // < 6.x + if(GET_VERSION_MINOR(kernelVersion) < 37) // < 6.x return UnmapProcessMemory(processHandle, dst, size); // equivalent when size <= 64MB KProcessHwInfo *currentHwInfo = hwInfoOfProcess(currentCoreContext->objectContext.currentProcess); diff --git a/sysmodules/rosalina/source/hbloader.c b/sysmodules/rosalina/source/hbloader.c index c9aa68e..d37f500 100644 --- a/sysmodules/rosalina/source/hbloader.c +++ b/sysmodules/rosalina/source/hbloader.c @@ -301,7 +301,7 @@ void HBLDR_HandleCommands(void *ctx) kcaps0->descriptors[0] = 0xFC000000 | (osGetKernelVersion() >> 16); u64 lastdep = sizeof(dependencyList)/8; - if (osGetFirmVersion() >= SYSTEM_VERSION(2,50,0)) // 9.6+ FIRM + if (GET_VERSION_MINOR(osGetKernelVersion()) >= 50) // 9.6+ FIRM { exhi->sci.dependencies[lastdep++] = 0x0004013000004002ULL; // nfc strncpy((char*)&localcaps0->service_access[0x20], "nfc:u", 8); diff --git a/sysmodules/rosalina/source/input_redirection.c b/sysmodules/rosalina/source/input_redirection.c index 852b4c4..6417dbb 100644 --- a/sysmodules/rosalina/source/input_redirection.c +++ b/sysmodules/rosalina/source/input_redirection.c @@ -273,7 +273,7 @@ Result InputRedirection_DoOrUndoPatches(void) svcCloseHandle(processHandle); res = OpenProcessByName("ir", &processHandle); - if(R_SUCCEEDED(res) && osGetKernelVersion() >= SYSTEM_VERSION(2, 44, 6)) + if(R_SUCCEEDED(res) && GET_VERSION_MINOR(osGetKernelVersion()) >= 44) { svcGetProcessInfo(&textTotalRoundedSize, processHandle, 0x10002); // only patch .text + .data svcGetProcessInfo(&rodataTotalRoundedSize, processHandle, 0x10003); diff --git a/sysmodules/sm/source/common.h b/sysmodules/sm/source/common.h index 393df08..7ee7f6b 100644 --- a/sysmodules/sm/source/common.h +++ b/sysmodules/sm/source/common.h @@ -10,8 +10,10 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for #include <3ds.h> #include -#define IS_PRE_7X (osGetFirmVersion() < SYSTEM_VERSION(2, 39, 4)) -#define IS_PRE_93 (osGetFirmVersion() < SYSTEM_VERSION(2, 48, 3)) +#define KERNEL_VERSION_MINOR (GET_VERSION_MINOR(osGetKernelVersion())) + +#define IS_PRE_7X (KERNEL_VERSION_MINOR < 39) +#define IS_PRE_93 (KERNEL_VERSION_MINOR < 48) extern u32 nbSection0Modules; extern Handle resumeGetServiceHandleOrPortRegisteredSemaphore;