From 12df895ff36b6a2fa34624a7082edfdf3a19a422 Mon Sep 17 00:00:00 2001 From: Princess-of-Sleeping <29831892+Princess-of-Sleeping@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:12:35 +0900 Subject: [PATCH] Added some missing ForKernel functions --- db/360/SceProcessmgr.yml | 2 +- include/psp2/kernel/processmgr.h | 11 --- include/psp2common/kernel/processmgr.h | 11 +++ include/psp2common/kernel/threadmgr.h | 7 +- include/psp2kern/kernel/cpu.h | 5 +- include/psp2kern/kernel/intrmgr.h | 6 ++ include/psp2kern/kernel/modulemgr.h | 93 +++++++++++++++++++ include/psp2kern/kernel/processmgr.h | 8 ++ include/psp2kern/kernel/sysmem.h | 10 ++ .../psp2kern/kernel/sysmem/address_space.h | 10 +- include/psp2kern/kernel/sysmem/fixedheap.h | 24 +++++ include/psp2kern/kernel/sysmem/heap.h | 5 + include/psp2kern/kernel/sysmem/nameheap.h | 24 +++++ .../psp2kern/kernel/sysmem/uid_entryheap.h | 24 +++++ include/psp2kern/kernel/sysmem/uid_guid.h | 7 ++ 15 files changed, 231 insertions(+), 16 deletions(-) create mode 100644 include/psp2kern/kernel/sysmem/fixedheap.h create mode 100644 include/psp2kern/kernel/sysmem/nameheap.h create mode 100644 include/psp2kern/kernel/sysmem/uid_entryheap.h diff --git a/db/360/SceProcessmgr.yml b/db/360/SceProcessmgr.yml index 008b87ac25..67997ec63b 100644 --- a/db/360/SceProcessmgr.yml +++ b/db/360/SceProcessmgr.yml @@ -60,11 +60,11 @@ modules: functions: ksceKernelCreateProcess: 0x71CF71FD ksceKernelExitProcess: 0x4CA7DC42 - ksceKernelGetClassForUid2: 0xC6820972 ksceKernelGetProcessKernelBuf: 0xB9E68092 ksceKernelGetProcessMainThread: 0x95F9ED94 ksceKernelGetProcessModuleInfo: 0xC1C91BB2 ksceKernelGetProcessSelfAuthInfo: 0xE4C83B0D + ksceKernelGetUIDProcessClass: 0xC6820972 ksceKernelLibcGettimeofday: 0xDE8B8B5E ksceKernelLibcTime: 0x9E38C556 ksceKernelResumeProcess: 0x080CDC59 diff --git a/include/psp2/kernel/processmgr.h b/include/psp2/kernel/processmgr.h index 7e193acfa7..faee697aec 100644 --- a/include/psp2/kernel/processmgr.h +++ b/include/psp2/kernel/processmgr.h @@ -17,17 +17,6 @@ extern "C" { #endif -typedef struct SceKernelTimeval { - SceInt32 sec; - SceInt32 usec; -} SceKernelTimeval; -VITASDK_BUILD_ASSERT_EQ(8, SceKernelTimeval); - -typedef struct SceKernelTimezone { - SceUInt64 value; -} SceKernelTimezone; -VITASDK_BUILD_ASSERT_EQ(8, SceKernelTimezone); - /** * Exit current Process with specified return code * diff --git a/include/psp2common/kernel/processmgr.h b/include/psp2common/kernel/processmgr.h index 849d43713e..816188ccca 100644 --- a/include/psp2common/kernel/processmgr.h +++ b/include/psp2common/kernel/processmgr.h @@ -19,6 +19,17 @@ typedef SceUInt32 SceKernelProcessType; typedef SceUInt64 SceKernelClock; typedef SceUInt32 SceKernelTime; +typedef struct SceKernelTimeval { + SceInt32 sec; + SceInt32 usec; +} SceKernelTimeval; +VITASDK_BUILD_ASSERT_EQ(8, SceKernelTimeval); + +typedef struct SceKernelTimezone { + SceUInt64 value; +} SceKernelTimezone; +VITASDK_BUILD_ASSERT_EQ(8, SceKernelTimezone); + typedef enum SceKernelProcessPrioritySystem { SCE_KERNEL_PROCESS_PRIORITY_SYSTEM_HIGH = 32, SCE_KERNEL_PROCESS_PRIORITY_SYSTEM_DEFAULT = 96, diff --git a/include/psp2common/kernel/threadmgr.h b/include/psp2common/kernel/threadmgr.h index e75e1abdc0..88336d2fcd 100644 --- a/include/psp2common/kernel/threadmgr.h +++ b/include/psp2common/kernel/threadmgr.h @@ -67,8 +67,13 @@ typedef struct SceKernelThreadOptParam { SceSize size; /** Attributes */ SceUInt32 attr; + SceUInt32 kStackMemType; + SceUInt32 uStackMemType; + SceUInt32 uTLSMemType; + SceUInt32 uStackMemid; + SceUInt32 data_0x18; } SceKernelThreadOptParam; -VITASDK_BUILD_ASSERT_EQ(8, SceKernelThreadOptParam); +VITASDK_BUILD_ASSERT_EQ(0x1C, SceKernelThreadOptParam); /** Structure to hold the status information for a thread * @see sceKernelGetThreadInfo diff --git a/include/psp2kern/kernel/cpu.h b/include/psp2kern/kernel/cpu.h index 8cd4b9ae55..131e24cc6a 100644 --- a/include/psp2kern/kernel/cpu.h +++ b/include/psp2kern/kernel/cpu.h @@ -102,13 +102,14 @@ static inline int ksceKernelDomainTextMemcpy(void *dst, const void *src, SceSize #endif -// ksceKernelGetVmaccessRange +// sceKernelGetVmaccessRange had prototype changed in some times +void ksceKernelGetVmaccessRange(SceUIntPtr *pRangeStart, SceUIntPtr *pRangeEnd); void ksceKernelCpuBranchPredictorInvalidateAll(void); void ksceKernelCpuBranchPredictorInvalidateAllIS(void); SceUInt8 ksceKernelCpuGetCONTEXTIDR(void); -// ksceKernelCpuUpdateSCTLR +void ksceKernelCpuUpdateSCTLR(void); SceBool ksceKernelIsUncacheAddressInTmpFsGame(void *address); diff --git a/include/psp2kern/kernel/intrmgr.h b/include/psp2kern/kernel/intrmgr.h index 60a604707b..55dcff4a93 100644 --- a/include/psp2kern/kernel/intrmgr.h +++ b/include/psp2kern/kernel/intrmgr.h @@ -68,11 +68,17 @@ int ksceKernelTriggerSubIntr(int intr_code, int subintr_code, void *subintr_arg) int ksceKernelEnableSubIntr(int intr_code, int subintr_code); int ksceKernelDisableSubIntr(int intr_code, int subintr_code); +int ksceKernelQueryIntrHandlerInfo(unsigned int intr_code, unsigned int a2, int a3); + + +/* For backwards compatibility */ + #define ksceKernelMaskIntr(intr_code) ksceKernelDisableIntr(intr_code) #define ksceKernelSetIntrMasked(intr_code, masked) ksceKernelEnableIntr(intr_code) #define ksceKernelUnmaskIntr(intr_code) ksceKernelEnableIntr(intr_code) #define ksceKernelGetIntrMasked ksceKernelSuspendIntr + #ifdef __cplusplus } #endif diff --git a/include/psp2kern/kernel/modulemgr.h b/include/psp2kern/kernel/modulemgr.h index 9250ec5073..8c3fc8b186 100644 --- a/include/psp2kern/kernel/modulemgr.h +++ b/include/psp2kern/kernel/modulemgr.h @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -64,6 +65,70 @@ typedef struct { } SceKernelModuleListInfo; VITASDK_BUILD_ASSERT_EQ(0xB0, SceKernelModuleListInfo); +typedef struct SceKernelModuleExportEntry { + SceNID libnid; + void *entry; // function ptr. or vars? +} SceKernelModuleExportEntry; +VITASDK_BUILD_ASSERT_EQ(8, SceKernelModuleExportEntry); + +typedef struct SceKernelModuleImportNonlinkedInfo { + SceSize size; // 0x124 + SceUID modid; + SceNID libnid; + char libname[0x100]; + int data_0x10C; + int data_0x110; + int data_0x114; + int data_0x118; + int data_0x11C; + int data_0x120; +} SceKernelModuleImportNonlinkedInfo; +VITASDK_BUILD_ASSERT_EQ(0x124, SceKernelModuleImportNonlinkedInfo); + +typedef struct SceSelfAppInfo { + int vendor_id; + int self_type; +} SceSelfAppInfo; +VITASDK_BUILD_ASSERT_EQ(8, SceSelfAppInfo); + +typedef struct SceLoadProcessParam { // size is 0x7C-bytes + SceUInt32 sysver; + char thread_name[0x20]; + SceUInt32 initial_thread_priority; // ex: 0x100000EC + SceSize initial_thread_stack_size; // ex: 0x6000 + SceUInt32 unk_0x2C; + SceUInt32 unk_0x30; + SceKernelThreadOptParam threadOptParam; + int unk_0x50; + char process_name[0x20]; // not titleid + SceUInt32 preload_disabled; + void *module_proc_param; +} SceLoadProcessParam; +VITASDK_BUILD_ASSERT_EQ(0x7C, SceLoadProcessParam); + +typedef struct _SceKernelFunctionShimInfo { + SceNID replaced_function_nid; /**< NID of the function that needs to be replaced */ + SceNID replacing_function_nid; /**< NID of the function that will serve as a replacement - must probably come from same library as replaced function */ +} SceKernelFunctionShimInfo; +VITASDK_BUILD_ASSERT_EQ(8, SceKernelFunctionShimInfo); + +typedef struct _SceKernelLibraryShimInfo { + const char *library_name; /**< Name of the library the shimmed functions come from (i.e. SceThreadmgr) */ + SceUInt32 unk_04; /**< Always 0 ? */ + SceUInt32 function_shims_count; /**< Size of the array pointed to by next field */ + SceKernelFunctionShimInfo* function_shims; +} SceKernelLibraryShimInfo; +VITASDK_BUILD_ASSERT_EQ(0x10, SceKernelLibraryShimInfo); + +typedef struct _SceKernelCompatibilityShimInfo { + const char *title_id; /**< TitleID (process name) of the app this shim applies to */ + SceUInt32 unk_04; /**< Always 0 ? */ + SceUInt32 library_shims_count; /**< Size of the array pointed to by next field */ + SceKernelLibraryShimInfo *library_shims; +} SceKernelCompatibilityShimInfo; +VITASDK_BUILD_ASSERT_EQ(0x10, SceKernelCompatibilityShimInfo); + + /** * @brief Register syscall function * @@ -437,6 +502,34 @@ int ksceKernelGetModulePath(SceUID modid, char *path, SceSize pathlen); int ksceKernelGetLibraryInfoForDebugger(SceUID pid, SceUID library_id, SceKernelModuleLibraryInfo *info); +void ksceKernelFinalizeKbl(void); +int ksceKernelGetExportedLibraryListInModule(SceUID pid, SceUID modid, SceUID *library_ids, SceSize *num); +int ksceKernelGetImportedLibraryListInModule(SceUID pid, SceUID modid, SceUID *library_ids, SceSize *num); +int ksceKernelGetLibEntCBListForSyslibtrace(void **ppList, SceSize *num); +int ksceKernelGetLibraryClientList(SceUID pid, SceUID library_id, SceUID *modids, SceSize *num, SceSize cpy_skip_num); +int ksceKernelGetLibraryDBFlags(SceUID pid, int *pFlags); +int ksceKernelGetLibraryExportInfoForDebugger(SceUID pid, SceUID library_id, SceKernelModuleExportEntry *list, SceSize *num, SceSize cpy_skip_num); +int ksceKernelGetLostLibraryInfo(SceUID pid, SceUID modid, SceNID libnid, SceKernelModuleImportNonlinkedInfo *info); +int ksceKernelGetLostLibraryList(SceUID pid, void *a2, SceSize *num); +int ksceKernelGetLostLibraryListInModule(SceUID pid, SceUID modid, void *pList, SceSize *num); +int ksceKernelGetMetaDataForDebugger(SceUID pid, SceUID uModuleId, void **start, void **stop); +void *ksceKernelGetModuleEntryPoint(SceUID modid); +int ksceKernelGetModuleFingerprint(SceUID moduleId, SceUInt32 *pFingerprint); +int ksceKernelGetModuleIsSharedByAddr(SceUID pid, void *addr); +int ksceKernelGetProgramIdentificationInfo(const char *path, SceUInt64 *pAuthid, SceSelfAppInfo *pInfo); +int ksceKernelGetStubInfoForDebugger(SceUID pid, SceUID stubid, void *a3); +int ksceKernelGetStubList(SceUID pid, SceUID *stub, SceSize *num); +int ksceKernelGetStubNidTableForDebugger(SceUID pid, SceUID stubid, void *a3, SceSize *num, SceSize cpy_skip_num); +int ksceKernelLoadPreloadingModules(SceUID pid, const SceLoadProcessParam *pParam, int flags); +SceUID ksceKernelLoadProcessImage(SceUID pid, const char *path, int flags, SceSelfAuthInfo *auth_info, SceLoadProcessParam *param, SceKernelCompatibilityShimInfo *shim_info); +int ksceKernelLoadPtLoadSegForFwloader(const char *path, int e_phnum, void *buffer, SceSize bufsize, int zero_unk, SceSize *bytes_read); +int ksceKernelModuleUnloadMySelf(void); +int ksceKernelStartPreloadingModules(SceUID pid); +int ksceKernelUnloadProcessModules(SceUID pid); + + +/* For backwards compatibility */ + #define ksceKernelGetModuleInternal ksceKernelGetModuleCB #define ksceKernelGetProcessMainModule ksceKernelGetModuleIdByPid diff --git a/include/psp2kern/kernel/processmgr.h b/include/psp2kern/kernel/processmgr.h index 1c6f14dafd..070c28ef52 100644 --- a/include/psp2kern/kernel/processmgr.h +++ b/include/psp2kern/kernel/processmgr.h @@ -8,7 +8,9 @@ #define _PSP2KERN_KERNEL_PROCESSMGR_H_ #include +#include #include +#include #ifdef __cplusplus extern "C" { @@ -96,6 +98,12 @@ ScePVoid ksceKernelGetProcessModuleInfo(SceUID pid); int ksceKernelGetProcessSelfAuthInfo(SceUID pid, SceSelfAuthInfo *self_auth_info); +int ksceKernelLibcGettimeofday(SceKernelTimeval *tv, SceKernelTimezone *tz); +SceKernelTime ksceKernelLibcTime(SceKernelTime *tloc); +int ksceKernelExitProcess(int status); +SceClass *ksceKernelGetUIDProcessClass(void); + + #ifdef __cplusplus } #endif diff --git a/include/psp2kern/kernel/sysmem.h b/include/psp2kern/kernel/sysmem.h index 077a99df50..4ab214fcd2 100644 --- a/include/psp2kern/kernel/sysmem.h +++ b/include/psp2kern/kernel/sysmem.h @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -58,6 +61,8 @@ typedef struct SceKernelAllocMemBlockKernelOpt { } SceKernelAllocMemBlockKernelOpt; VITASDK_BUILD_ASSERT_EQ(0x58, SceKernelAllocMemBlockKernelOpt); +typedef SceKernelAllocMemBlockKernelOpt SceKernelAllocMemBlockOptKernel; + /** * Allocates a new memory block * @@ -323,6 +328,11 @@ int ksceKernelUnlockRangeProc(SceUID pid, void *addr, SceSize size); */ int ksceKernelUnlockRangeWithMode(SceKernelMemoryRefPerm perm, void *addr, SceSize size); + +SceUID ksceKernelAllocPartitionMemBlock(SceUID part, const char *name, SceKernelMemBlockType type, SceSize size, const SceKernelAllocMemBlockOptKernel *pOpt); +int ksceKernelFreeSimpleMemBlock(void *a1); + + /* Macros for backwards compatibility */ #define ksceKernelFindMemBlockByAddrForPid(pid, addr, size) ksceKernelFindProcMemBlockByAddr(pid, addr, size) diff --git a/include/psp2kern/kernel/sysmem/address_space.h b/include/psp2kern/kernel/sysmem/address_space.h index e4d52a970f..4e13a3f41f 100644 --- a/include/psp2kern/kernel/sysmem/address_space.h +++ b/include/psp2kern/kernel/sysmem/address_space.h @@ -69,7 +69,15 @@ int ksceKernelProcessGetContext(SceUID pid, SceKernelProcessContext **ctx); int ksceKernelProcessSwitchContext(const SceKernelProcessContext *new_context, SceKernelProcessContext *prev_context); -#if defined(SCE_SDK_VERSION) && SCE_SDK_VERSION <= 0x1692000 +int ksceKernelAddressSpaceFreeAllMemBlock(SceUID guid); +int ksceKernelAddressSpaceSetPhyMemPart(SceUID guid, SceUInt32 index, void *pPhyMemPart); +int ksceKernelAddressSpaceUnmap(SceUID uid, int a2, int a3, void* addr, SceSize size); +int ksceKernelAddressSpaceVAtoPA(void *pAS, SceUInt32 mode, void *pVA, void **pPA); +SceUID ksceKernelCreateAddressSpace(SceUID pid, const char *name, SceUInt32 type, void *pOpt); +int ksceKernelDeleteAddressSpace(SceUID guid); + + +#if defined(PSP2_SDK_VERSION) && PSP2_SDK_VERSION <= 0x1692000 int ksceKernelSwitchVmaForPid(SceUID pid); #endif diff --git a/include/psp2kern/kernel/sysmem/fixedheap.h b/include/psp2kern/kernel/sysmem/fixedheap.h new file mode 100644 index 0000000000..f4336e50e5 --- /dev/null +++ b/include/psp2kern/kernel/sysmem/fixedheap.h @@ -0,0 +1,24 @@ +/** + * \kernelgroup{SceSysmem} + * \usage{psp2kern/kernel/sysmem/fixedheap.h,SceSysmemForDriver_stub} + */ + +#ifndef _PSP2KERN_KERNEL_SYSMEM_FIXEDHEAP_H_ +#define _PSP2KERN_KERNEL_SYSMEM_FIXEDHEAP_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +int ksceKernelGetFixedHeapInfoByPointer(void *pFixedHeap, void *pInfo); + + +#ifdef __cplusplus +} +#endif + +#endif /* _PSP2KERN_KERNEL_SYSMEM_FIXEDHEAP_H_ */ diff --git a/include/psp2kern/kernel/sysmem/heap.h b/include/psp2kern/kernel/sysmem/heap.h index 710dfaec58..9087145a58 100644 --- a/include/psp2kern/kernel/sysmem/heap.h +++ b/include/psp2kern/kernel/sysmem/heap.h @@ -113,6 +113,11 @@ void *ksceKernelAlloc(unsigned int size); */ int ksceKernelFree(void *ptr); + +int ksceKernelGetHeapInfo(SceUID heapid, SceUInt32 level, void *pInfo); +int ksceKernelGetHeapInfoByPtr(void *pObject, void *pInfo); + + #ifdef __cplusplus } #endif diff --git a/include/psp2kern/kernel/sysmem/nameheap.h b/include/psp2kern/kernel/sysmem/nameheap.h new file mode 100644 index 0000000000..a9e1845b5d --- /dev/null +++ b/include/psp2kern/kernel/sysmem/nameheap.h @@ -0,0 +1,24 @@ +/** + * \kernelgroup{SceSysmem} + * \usage{psp2kern/kernel/sysmem/nameheap.h,SceSysmemForDriver_stub} + */ + +#ifndef _PSP2KERN_KERNEL_SYSMEM_NAMEHEAP_H_ +#define _PSP2KERN_KERNEL_SYSMEM_NAMEHEAP_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +int ksceKernelNameHeapGetInfo(void *pInfo); + + +#ifdef __cplusplus +} +#endif + +#endif /* _PSP2KERN_KERNEL_SYSMEM_NAMEHEAP_H_ */ diff --git a/include/psp2kern/kernel/sysmem/uid_entryheap.h b/include/psp2kern/kernel/sysmem/uid_entryheap.h new file mode 100644 index 0000000000..c98974c723 --- /dev/null +++ b/include/psp2kern/kernel/sysmem/uid_entryheap.h @@ -0,0 +1,24 @@ +/** + * \kernelgroup{SceSysmem} + * \usage{psp2kern/kernel/sysmem/uid_entryheap.h,SceSysmemForDriver_stub} + */ + +#ifndef _PSP2KERN_KERNEL_SYSMEM_UID_ENTRYHEAP_H_ +#define _PSP2KERN_KERNEL_SYSMEM_UID_ENTRYHEAP_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +SceInt32 ksceKernelUIDEntryHeapGetInfo(SceUID entryHeapId, void *pInfo); + + +#ifdef __cplusplus +} +#endif + +#endif /* _PSP2KERN_KERNEL_SYSMEM_UID_ENTRYHEAP_H_ */ diff --git a/include/psp2kern/kernel/sysmem/uid_guid.h b/include/psp2kern/kernel/sysmem/uid_guid.h index 22a4626ea6..d88ca6c74d 100644 --- a/include/psp2kern/kernel/sysmem/uid_guid.h +++ b/include/psp2kern/kernel/sysmem/uid_guid.h @@ -119,6 +119,13 @@ int ksceGUIDReleaseObject(SceUID guid); int ksceGUIDGetUIDVectorByClass(SceClass *cls, int vis_level, SceUID *vector, SceSize num, SceSize *ret_num); +int ksceGUIDGetObjectWithClass(SceUID uid, SceClass *pClass, SceObjectBase **obj); +int ksceGUIDKernelCreateWithAttr(SceClass *pClass, const char *name, SceUInt32 attr, SceObjectBase **ppEntry); +SceUID ksceGUIDOpenByGUID(SceUID guid); + + +/* For backwards compatibility */ + typedef SceGUIDKernelCreateOpt SceCreateUidObjOpt; #define ksceKernelCreateUidObj(sce_class, name, opt, obj) ksceGUIDKernelCreateWithOpt(sce_class, name, opt, obj)