Skip to content

Commit

Permalink
Merge pull request #825 from Princess-of-Sleeping/master
Browse files Browse the repository at this point in the history
Added some missing ForKernel functions
  • Loading branch information
Princess-of-Sleeping authored Nov 11, 2023
2 parents 720c7d9 + 12df895 commit d0456a3
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 16 deletions.
2 changes: 1 addition & 1 deletion db/360/SceProcessmgr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions include/psp2/kernel/processmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions include/psp2common/kernel/processmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion include/psp2common/kernel/threadmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions include/psp2kern/kernel/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions include/psp2kern/kernel/intrmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 93 additions & 0 deletions include/psp2kern/kernel/modulemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vitasdk/build_utils.h>
#include <psp2common/kernel/modulemgr.h>
#include <psp2kern/types.h>
#include <psp2kern/kernel/threadmgr.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions include/psp2kern/kernel/processmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#define _PSP2KERN_KERNEL_PROCESSMGR_H_

#include <vitasdk/build_utils.h>
#include <psp2common/kernel/processmgr.h>
#include <psp2kern/types.h>
#include <psp2kern/kernel/sysmem.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions include/psp2kern/kernel/sysmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <psp2kern/kernel/sysmem/uid_class.h>
#include <psp2kern/kernel/sysmem/uid_guid.h>
#include <psp2kern/kernel/sysmem/uid_puid.h>
#include <psp2kern/kernel/sysmem/uid_entryheap.h>
#include <psp2kern/kernel/sysmem/fixedheap.h>
#include <psp2kern/kernel/sysmem/nameheap.h>
#include <psp2kern/kernel/sysmem/heap.h>
#include <psp2kern/kernel/sysmem/data_transfers.h>
#include <psp2kern/kernel/sysmem/memtype.h>
Expand Down Expand Up @@ -58,6 +61,8 @@ typedef struct SceKernelAllocMemBlockKernelOpt {
} SceKernelAllocMemBlockKernelOpt;
VITASDK_BUILD_ASSERT_EQ(0x58, SceKernelAllocMemBlockKernelOpt);

typedef SceKernelAllocMemBlockKernelOpt SceKernelAllocMemBlockOptKernel;

/**
* Allocates a new memory block
*
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 9 additions & 1 deletion include/psp2kern/kernel/sysmem/address_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions include/psp2kern/kernel/sysmem/fixedheap.h
Original file line number Diff line number Diff line change
@@ -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 <vitasdk/build_utils.h>
#include <psp2kern/types.h>

#ifdef __cplusplus
extern "C" {
#endif


int ksceKernelGetFixedHeapInfoByPointer(void *pFixedHeap, void *pInfo);


#ifdef __cplusplus
}
#endif

#endif /* _PSP2KERN_KERNEL_SYSMEM_FIXEDHEAP_H_ */
5 changes: 5 additions & 0 deletions include/psp2kern/kernel/sysmem/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions include/psp2kern/kernel/sysmem/nameheap.h
Original file line number Diff line number Diff line change
@@ -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 <vitasdk/build_utils.h>
#include <psp2kern/types.h>

#ifdef __cplusplus
extern "C" {
#endif


int ksceKernelNameHeapGetInfo(void *pInfo);


#ifdef __cplusplus
}
#endif

#endif /* _PSP2KERN_KERNEL_SYSMEM_NAMEHEAP_H_ */
24 changes: 24 additions & 0 deletions include/psp2kern/kernel/sysmem/uid_entryheap.h
Original file line number Diff line number Diff line change
@@ -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 <vitasdk/build_utils.h>
#include <psp2kern/types.h>

#ifdef __cplusplus
extern "C" {
#endif


SceInt32 ksceKernelUIDEntryHeapGetInfo(SceUID entryHeapId, void *pInfo);


#ifdef __cplusplus
}
#endif

#endif /* _PSP2KERN_KERNEL_SYSMEM_UID_ENTRYHEAP_H_ */
7 changes: 7 additions & 0 deletions include/psp2kern/kernel/sysmem/uid_guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d0456a3

Please sign in to comment.