summaryrefslogtreecommitdiff
path: root/include/kernel/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'include/kernel/kernel')
-rw-r--r--include/kernel/kernel/cpu.h31
-rw-r--r--include/kernel/kernel/dmac.h6
-rw-r--r--include/kernel/kernel/excpmgr.h2
-rw-r--r--include/kernel/kernel/modulemgr.h476
-rw-r--r--include/kernel/kernel/processmgr.h36
-rw-r--r--include/kernel/kernel/suspend.h15
-rw-r--r--include/kernel/kernel/sysmem.h108
-rw-r--r--include/kernel/kernel/threadmgr.h274
-rw-r--r--include/kernel/kernel/utils.h205
9 files changed, 1074 insertions, 79 deletions
diff --git a/include/kernel/kernel/cpu.h b/include/kernel/kernel/cpu.h
index d79d416..4765d52 100644
--- a/include/kernel/kernel/cpu.h
+++ b/include/kernel/kernel/cpu.h
@@ -1,6 +1,7 @@
#ifndef _PSP2_KERNEL_CPU_H_
#define _PSP2_KERNEL_CPU_H_
+#include <psp2common/kernel/cpu.h>
#include <psp2kern/types.h>
#ifdef __cplusplus
@@ -19,7 +20,7 @@ extern "C" {
} while(0)
/**
- * @brief Call this when existing a syscall
+ * @brief Call this when exiting a syscall
*
* @param state The state
*/
@@ -28,6 +29,18 @@ extern "C" {
asm volatile ("mcr p15, 0, %0, c13, c0, 3" :: "r" (state) : "memory"); \
} while (0)
+
+/**
+ * @brief Writeback a range of L1 dcache (without L2)
+ *
+ * @param ptr The pointer
+ * @param[in] len The length
+ *
+ * @return Zero on success
+ */
+int sceKernelCpuDcacheWritebackRange(const void *ptr, size_t len);
+
+
/**
* @brief Save process context
*
@@ -82,8 +95,10 @@ static inline int sceKernelCpuUnrestrictedMemcpy(void *dst, const void *src, siz
asm ("mrc p15, 0, %0, c3, c0, 0" : "=r" (prev_dacr));
asm ("mcr p15, 0, %0, c3, c0, 0" :: "r" (0xFFFF0000));
- memcpy(dst, src, len);
- sceKernelCpuDcacheWritebackRange((uintptr_t)dst & ~0x1F, (len + 0x1F) & ~0x1F);
+ for (size_t i=0; i < len; i++) {
+ ((char *) dst)[i] = ((char *) src)[i];
+ }
+ sceKernelCpuDcacheWritebackRange((void *)((uintptr_t)dst & ~0x1F), (len + 0x1F) & ~0x1F);
asm ("mcr p15, 0, %0, c3, c0, 0" :: "r" (prev_dacr));
return 0;
@@ -113,16 +128,6 @@ int sceKernelCpuDisableInterrupts(void);
int sceKernelCpuEnableInterrupts(int flags);
/**
- * @brief Writeback a range of L1 dcache (without L2)
- *
- * @param ptr The pointer
- * @param[in] len The length
- *
- * @return Zero on success
- */
-int sceKernelCpuDcacheWritebackRange(const void *ptr, size_t len);
-
-/**
* @brief Invalidate a range of L1 dcache (without L2)
*
* @param ptr The pointer
diff --git a/include/kernel/kernel/dmac.h b/include/kernel/kernel/dmac.h
index 60718be..669257e 100644
--- a/include/kernel/kernel/dmac.h
+++ b/include/kernel/kernel/dmac.h
@@ -1,11 +1,13 @@
#ifndef _PSP2_KERNEL_DMAC_H_
#define _PSP2_KERNEL_DMAC_H_
+#include <stddef.h>
+
#ifdef __cplusplus
extern "C" {
#endif
-/***
+/**
* DMA memcpy
*
* @param[in] dst - Destination
@@ -16,7 +18,7 @@ extern "C" {
*/
void *sceDmacMemcpy(void *dst, const void *src, size_t size);
-/***
+/**
* DMA memset
*
* @param[in] dst - Destination
diff --git a/include/kernel/kernel/excpmgr.h b/include/kernel/kernel/excpmgr.h
index d9c83ed..c852da6 100644
--- a/include/kernel/kernel/excpmgr.h
+++ b/include/kernel/kernel/excpmgr.h
@@ -16,7 +16,7 @@ typedef enum SceExcpKind {
SCE_EXCP_FIQ = 7
} SceExcpKind;
-/***
+/**
* Get a pointer to SceExcpmgr's internal data
*
* This is only used by exception handlers.
diff --git a/include/kernel/kernel/modulemgr.h b/include/kernel/kernel/modulemgr.h
index 804eb63..c8e115c 100644
--- a/include/kernel/kernel/modulemgr.h
+++ b/include/kernel/kernel/modulemgr.h
@@ -21,36 +21,39 @@ extern "C" {
#define SCE_KERNEL_STOP_CANCEL SCE_KERNEL_STOP_FAIL
/** @} */
-typedef struct
-{
- SceUInt size; //!< this structure size (0x18)
+typedef struct SceKernelModuleName {
+ char s[0x1C];
+} SceKernelModuleName;
+
+typedef struct SceKernelSegmentInfo {
+ SceSize size; //!< this structure size (0x18)
SceUInt perms; //!< probably rwx in low bits
void *vaddr; //!< address in memory
- SceUInt memsz; //!< size in memory
- SceUInt flags; //!< meaning unknown
- SceUInt res; //!< unused?
+ SceSize memsz; //!< size in memory
+ SceSize filesz; //!< original size of memsz
+ SceUInt res; //!< unused
} SceKernelSegmentInfo;
-typedef struct
-{
- SceUInt size; //!< 0x1B8 for Vita 1.x
- SceUInt handle; //!< kernel module handle?
- SceUInt flags; //!< some bits. could be priority or whatnot
+typedef struct SceKernelModuleInfo {
+ SceSize size; //!< 0x1B8 for Vita 1.x
+ SceUID modid;
+ uint16_t modattr;
+ uint8_t modver[2];
char module_name[28];
SceUInt unk28;
- void *module_start;
- SceUInt unk30;
- void *module_stop;
- void *exidxTop;
- void *exidxBtm;
- SceUInt unk40;
- SceUInt unk44;
+ void *start_entry;
+ void *stop_entry;
+ void *exit_entry;
+ void *exidx_top;
+ void *exidx_btm;
+ void *extab_top;
+ void *extab_btm;
void *tlsInit;
SceSize tlsInitSize;
SceSize tlsAreaSize;
char path[256];
SceKernelSegmentInfo segments[4];
- SceUInt type; //!< 6 = user-mode PRX?
+ SceUInt type; //!< 6 = user-mode PRX?
} SceKernelModuleInfo;
typedef struct {
@@ -64,41 +67,452 @@ typedef struct {
typedef struct
{
SceSize size;
- char versionString[16];
- SceUInt unk_14;
- SceUInt unk_18;
- SceUInt unk_1C;
+ char versionString[0x1C];
SceUInt version;
SceUInt unk_24;
} SceKernelFwInfo;
+typedef struct {
+ SceSize size; //!< sizeof(SceKernelSegmentInfo2) (0x14)
+ int perm;
+ void *vaddr;
+ uint32_t memsz;
+ int unk_10;
+} SceKernelSegmentInfo2;
+
+typedef struct {
+ SceSize size;
+ SceUID modid;
+ uint32_t version;
+ uint32_t module_version;
+ uint32_t unk10;
+ void *unk14;
+ uint32_t unk18;
+ void *unk1C;
+ void *unk20;
+ char module_name[28];
+ uint32_t unk40;
+ uint32_t unk44;
+ uint32_t nid;
+ int segments_num;
+ union {
+ struct {
+ SceKernelSegmentInfo2 SegmentInfo[1];
+ uint32_t addr[4];
+ } seg1;
+ struct {
+ SceKernelSegmentInfo2 SegmentInfo[2];
+ uint32_t addr[4];
+ } seg2;
+ struct {
+ SceKernelSegmentInfo2 SegmentInfo[3];
+ uint32_t addr[4];
+ } seg3;
+ struct {
+ SceKernelSegmentInfo2 SegmentInfo[4];
+ uint32_t addr[4];
+ } seg4;
+ };
+} SceKernelModuleListInfo;
+
+typedef struct SceKernelModuleLibraryInfo {
+ SceSize size; //!< sizeof(SceKernelModuleLibraryInfo) : 0x120
+ SceUID libid;
+ uint32_t libnid;
+ uint16_t libver[2];
+ uint16_t entry_num_function;
+ uint16_t entry_num_variable;
+ uint16_t unk_0x14;
+ uint16_t unk_0x16;
+ char library_name[0x100]; // offset : 0x18
+ uint32_t unk_0x118;
+ SceUID modid2;
+} SceKernelModuleLibraryInfo;
+
+/**
+ * @brief Register syscall function
+ *
+ * @param[in] syscall_id - register syscall id (Must be less than 0x1000)
+ * @param[in] func - syscall function
+ *
+ * @return none
+ */
+void sceKernelRegisterSyscall(int syscall_id, const void *func);
+
+/**
+ * @brief Setup kernel for modulemgr
+ *
+ * @note - allocate and initialize syscall table
+ *
+ * @return none
+ */
+void sceKernelSetupForModulemgr(void);
+
+/**
+ * @brief Get module id list
+ *
+ * @param[in] pid - target pid
+ * @param[in] flags1 - unknown, use 0x7FFFFFFF
+ * @param[in] flags2 - unknown, use 1
+ * @param[out] modids - info output pointer
+ * @param[inout] num - in:list max num, out:get modid num
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelGetModuleList(SceUID pid, int flags1, int flags2, SceUID *modids, size_t *num);
+
+/**
+ * @par Example1: Get max to 10 kernel module info
+ * @code
+ * SceKernelModuleListInfo infolists[10];
+ * size_t num = 10;// Get max
+ * uint32_t offset = 0;
+ * SceKernelModuleListInfo *info = &infolists[0];
+ *
+ * sceKernelGetModuleList2(0x10005, infolists, &num);
+ *
+ * for(int i=0;i<num;i++){
+ * printf("name : %s\n", info->module_name);
+ *
+ * if(info->segments_num == 1){
+ * printf("vaddr:0x%08X\n", info->seg1.SegmentInfo[0].vaddr);
+ * }else if(info->segments_num == 2){
+ * printf("vaddr:0x%08X\n", info->seg2.SegmentInfo[0].vaddr);
+ * }
+ * info = ((char *)info) + info->size;
+ * }
+ * @endcode
+ *
+ * @param[in] pid - target pid
+ * @param[out] infolists - infolists output
+ * @param[inout] num - Specify the maximum number of modinfolist to retrieve. If the function returns 0, it returns the number of modules loaded in the target pid in num
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelGetModuleList2(SceUID pid, SceKernelModuleListInfo *infolists, size_t *num);
+
+/**
+ * @brief Get module info
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target module id
+ * @param[out] info - info output pointer
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelGetModuleInfo(SceUID pid, SceUID modid, SceKernelModuleInfo *info);
-int sceKernelGetModuleInternal(SceUID modid, void **module);
+/**
+ * @brief Get module info mini by module address
+ *
+ * @param[in] pid - target pid
+ * @param[in] module_addr - target module address, Also possible with data segment address
+ * @param[out] module_nid - can also set NULL, module nid output
+ * @param[out] program_text_addr - can also set NULL, program text addr output
+ * @param[out] module_name - can also set NULL, module name output
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelGetModuleInfoMinByAddr(SceUID pid, const void *module_addr, uint32_t *module_nid, const void **program_text_addr, SceKernelModuleName *module_name);
+
+/**
+ * @brief Get module info (internal)
+ *
+ * @param[in] modid - target module id
+ * @param[out] module_info - module_info output pointer
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelGetModuleInternal(SceUID modid, void **module_info);
+
+/**
+ * @brief Get module id by module address
+ *
+ * @param[in] pid - target pid
+ * @param[in] module_addr - target module address
+ *
+ * @return modid on success, < 0 on error.
+ */
+SceUID sceKernelGetModuleIdByAddr(SceUID pid, const void *module_addr);
+
+/**
+ * @brief search kernel module by module name
+ *
+ * @param[in] module_name - target module name
+ *
+ * @return modid on success, < 0 on error.
+ */
+SceUID sceKernelSearchModuleByName(const char *module_name);
+
+/**
+ * @brief Get fw info
+ *
+ * @param[out] data - fw info output pointer
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelGetSystemSwVersion(SceKernelFwInfo *data);
-int sceKernelLoadStartModule(const char *path, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
+/**
+ * @brief load module (kernel only)
+ *
+ * @param[in] path - module path
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ *
+ * @return modid on success, < 0 on error.
+ */
SceUID sceKernelLoadModule(const char *path, int flags, SceKernelLMOption *option);
+
+/**
+ * @brief start module (kernel only)
+ *
+ * @param[in] modid - target module id
+ * @param[in] args - module start args
+ * @param[in] argp - module start argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_start res, SCE_KERNEL_START_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelStartModule(SceUID modid, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
-int sceKernelUnloadModule(SceUID modid, int flags, SceKernelULMOption *option);
+
+/**
+ * @brief load and start module (kernel only)
+ *
+ * @param[in] path - module path
+ * @param[in] args - module start args
+ * @param[in] argp - module start argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_start res, SCE_KERNEL_START_SUCCESS etc...
+ *
+ * @return modid on success, < 0 on error.
+ */
+SceUID sceKernelLoadStartModule(const char *path, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
+
+/**
+ * @brief stop module (kernel only)
+ *
+ * @param[in] modid - target module id
+ * @param[in] args - module stop args
+ * @param[in] argp - module stop argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_stop res, SCE_KERNEL_STOP_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelStopModule(SceUID modid, SceSize args, void *argp, int flags, SceKernelULMOption *option, int *status);
+
+/**
+ * @brief unload module (kernel only)
+ *
+ * @param[in] modid - target module id
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelUnloadModule(SceUID modid, int flags, SceKernelULMOption *option);
+
+/**
+ * @brief stop and unload module (kernel only)
+ *
+ * @param[in] modid - target module id
+ * @param[in] args - module stop args
+ * @param[in] argp - module stop argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_stop res, SCE_KERNEL_STOP_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelStopUnloadModule(SceUID modid, SceSize args, void *argp, int flags, SceKernelULMOption *option, int *status);
-SceUID sceKernelLoadStartSharedModuleForPid(SceUID pid, const char *path, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
-SceUID sceKernelLoadStartModuleForPid(SceUID pid, const char *path, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
-int sceKernelStartModuleForPid(SceUID pid, SceUID modid, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
+/**
+ * @brief load module
+ *
+ * @param[in] pid - target pid
+ * @param[in] path - module path
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ *
+ * @return modid on success, < 0 on error.
+ */
SceUID sceKernelLoadModuleForPid(SceUID pid, const char *path, int flags, SceKernelLMOption *option);
-SceUID sceKernelUnloadModuleForPid(SceUID pid, SceUID modid, int flags, SceKernelULMOption *option);
+
+/**
+ * @brief start module
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target module id
+ * @param[in] args - module start args
+ * @param[in] argp - module start argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_start res, SCE_KERNEL_START_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelStartModuleForPid(SceUID pid, SceUID modid, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
+
+/**
+ * @brief load and start module
+ *
+ * @param[in] pid - target pid
+ * @param[in] path - module path
+ * @param[in] args - module start args
+ * @param[in] argp - module start argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_start res, SCE_KERNEL_START_SUCCESS etc...
+ *
+ * @return modid on success, < 0 on error.
+ */
+SceUID sceKernelLoadStartModuleForPid(SceUID pid, const char *path, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
+
+/**
+ * @brief stop module
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target module id
+ * @param[in] args - module stop args
+ * @param[in] argp - module stop argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_stop res, SCE_KERNEL_STOP_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelStopModuleForPid(SceUID pid, SceUID modid, SceSize args, void *argp, int flags, SceKernelULMOption *option, int *status);
+
+/**
+ * @brief unload module
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target module id
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelUnloadModuleForPid(SceUID pid, SceUID modid, int flags, SceKernelULMOption *option);
+
+/**
+ * @brief stop and unload module
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target module id
+ * @param[in] args - module stop args
+ * @param[in] argp - module stop argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_stop res, SCE_KERNEL_STOP_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelStopUnloadModuleForPid(SceUID pid, SceUID modid, SceSize args, void *argp, int flags, SceKernelULMOption *option, int *status);
+/**
+ * @brief load and start module as shared module
+ *
+ * @param[in] pid - target pid
+ * @param[in] path - module path
+ * @param[in] args - module start args
+ * @param[in] argp - module start argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_start res, SCE_KERNEL_START_SUCCESS etc...
+ *
+ * @return modid on success, < 0 on error.
+ */
+SceUID sceKernelLoadStartSharedModuleForPid(SceUID pid, const char *path, SceSize args, void *argp, int flags, SceKernelLMOption *option, int *status);
+
+/**
+ * @brief stop and unload module as shared module
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target module id
+ * @param[in] args - module stop args
+ * @param[in] argp - module stop argp
+ * @param[in] flags - unknown, set zero
+ * @param[in] option - unknown
+ * @param[out] status - module_stop res, SCE_KERNEL_STOP_SUCCESS etc...
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelStopUnloadSharedModuleForPid(SceUID pid, SceUID modid, SceSize args, void *argp, int flags, SceKernelULMOption *option, int *status);
+
+/**
+ * @brief mount bootfs (load bootfs module)
+ *
+ * @param[in] bootImagePath - bootfs module path
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelMountBootfs(const char *bootImagePath);
+
+/**
+ * @brief unmount bootfs (unload bootfs module)
+ *
+ * @return 0 on success, < 0 on error.
+ */
int sceKernelUmountBootfs(void);
+/**
+ * @brief Get the main module for a given process.
+ * @param pid The process to query.
+ * @return the UID of the module else < 0 for an error.
+ */
+SceUID sceKernelGetProcessMainModule(SceUID pid);
+
+/**
+ * @brief Get the module path
+ *
+ * @param[in] pid - target pid
+ * @param[out] path - module path output
+ * @param[in] pathlen - path output max len
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelGetModulePath(SceUID modid, char *path, int pathlen);
+
+/**
+ * @brief Get library info
+ *
+ * @param[in] pid - target pid
+ * @param[in] modid - target library id
+ * @param[out] info - info output
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelGetModuleLibraryInfo(SceUID pid, SceUID libid, SceKernelModuleLibraryInfo *info);
+
+typedef struct SceKernelModuleExportEntry {
+ uint32_t libnid;
+ const void *entry; // function ptr. or vars?
+} SceKernelModuleExportEntry;
+
+/**
+ * @brief Get module export entry
+ *
+ * @param[in] pid - target pid
+ * @param[in] libid - target library uid
+ * @param[out] list - data output
+ * @param[inout] num - in:list max num, out:get entry num
+ * @param[in] cpy_skip_num - The index at which to start copying
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelGetModuleLibExportList(SceUID pid, SceUID libid, SceKernelModuleExportEntry *list, SceSize *num, SceSize cpy_skip_num);
+
+int sceKernelGetModuleUid(SceUID pid, SceUID modid, SceUID *modid_out, const void *unk1, int unk2);
+int sceKernelGetModuleUidList(SceUID pid, SceUID *modids, size_t *num);
+
#ifdef __cplusplus
}
#endif
#endif /* _PSP2_KERNEL_MODULEMGR_H_ */
-
diff --git a/include/kernel/kernel/processmgr.h b/include/kernel/kernel/processmgr.h
index f203eed..819129b 100644
--- a/include/kernel/kernel/processmgr.h
+++ b/include/kernel/kernel/processmgr.h
@@ -7,6 +7,9 @@
extern "C" {
#endif
+/** UID of the kernel process */
+#define SCE_KERNEL_PROCESS_ID_KERNEL 0x10005
+
typedef struct SceKernelProcessInfo {
SceSize size; //!< size of this struct, make sure it's 0xE8
SceUID pid; //!< our process ID
@@ -25,6 +28,39 @@ int sceKernelCreateProcessLocalStorage(const char *name, SceSize size);
void *sceKernelGetProcessLocalStorageAddr(int key);
int sceKernelGetProcessLocalStorageAddrForPid(SceUID pid, int key, void **out_addr, int create_if_doesnt_exist);
+/**
+ * @brief Launch an application
+ * @param[in] titleid The TitleId of the app to open.
+ * @param[in] flags Some unknown flags.
+ * @param[in] path Path of the eboot.bin to launch.
+ * @param[in] unk Unknown.
+ * @return PID of the launched app on success, < 0 on error.
+ */
+SceUID sceKernelLaunchApp(char* titleid, uint32_t flags, char *path, uint32_t unk);
+
+/**
+ * @brief Resume a suspended process.
+ * @param[in] pid The process to resume.
+ * @return Zero on success, < 0 on error.
+ */
+int sceKernelResumeProcess(SceUID pid);
+
+/**
+ * @brief Suspend a running process.
+ * @param[in] pid The process to suspend.
+ * @param[in] status The new status for the process.
+ * @return Zero on success, < 0 on error.
+ */
+int sceKernelSuspendProcess(SceUID pid, int status);
+
+/**
+ * @brief Get the status of a given process.
+ * @param[in] pid The process ID to query.
+ * @param[out] status The bit field status of the process.
+ * @return Zero on success, < 0 on error.
+ */
+int sceKernelGetProcessStatus(SceUID pid, int *status);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/kernel/kernel/suspend.h b/include/kernel/kernel/suspend.h
index 712e9b3..a1429c9 100644
--- a/include/kernel/kernel/suspend.h
+++ b/include/kernel/kernel/suspend.h
@@ -7,6 +7,8 @@
extern "C" {
#endif
+typedef int (* SceSysEventHandler)(int resume, int eventid, void *args, void *opt);
+
typedef enum SceKernelPowerTickType {
/** Cancel all timers */
SCE_KERNEL_POWER_TICK_DEFAULT = 0,
@@ -19,7 +21,7 @@ typedef enum SceKernelPowerTickType {
} SceKernelPowerTickType;
-/***
+/**
* Cancel specified idle timers to prevent entering in power save processing.
*
* @param[in] type - One of ::SceKernelPowerTickType
@@ -28,6 +30,17 @@ typedef enum SceKernelPowerTickType {
*/
int sceKernelPowerTick(int type);
+/**
+ * Register system event handler
+ *
+ * @param[in] name - Name of handler
+ * @param[in] handler - The handler
+ * @param[in] args - Handler arguments
+ *
+ * @return 0 on success, < 0 on error.
+*/
+int sceKernelRegisterSysEventHandler(const char *name, SceSysEventHandler handler, void *args);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/kernel/kernel/sysmem.h b/include/kernel/kernel/sysmem.h
index 72d6c06..aa882e3 100644
--- a/include/kernel/kernel/sysmem.h
+++ b/include/kernel/kernel/sysmem.h
@@ -1,13 +1,14 @@
#ifndef _PSP2_KERNEL_SYSMEM_H_
#define _PSP2_KERNEL_SYSMEM_H_
-#include <psp2kern/types.h>
+#include <stdarg.h>
+#include <psp2kern/kernel/types.h>
#ifdef __cplusplus
extern "C" {
#endif
-typedef enum SceKernelMemBlockType {
+typedef enum _SceKernelMemBlockType {
SCE_KERNEL_MEMBLOCK_TYPE_SHARED_RX = 0x0390D050,
SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW = 0x09408060,
SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE = 0x0C208060,
@@ -18,7 +19,7 @@ typedef enum SceKernelMemBlockType {
SCE_KERNEL_MEMBLOCK_TYPE_KERNEL_RX = 0x1020D005,
SCE_KERNEL_MEMBLOCK_TYPE_KERNEL_RW = 0x1020D006,
SCE_KERNEL_MEMBLOCK_TYPE_RW_UNK0 = 0x6020D006
-} SceKernelMemBlockType;
+} _SceKernelMemBlockType;
typedef enum SceKernelAllocMemBlockAttr {
SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_PADDR = 0x00000002U,
@@ -132,7 +133,19 @@ typedef struct SceKernelProcessContext {
SceUInt32 CONTEXTIDR;
} SceKernelProcessContext;
-/***
+typedef enum SceKernelSysrootSelfIndex {
+ SCE_KERNEL_SYSROOT_SELF_INDEX_GCAUTHMGR_SM = 0,
+ SCE_KERNEL_SYSROOT_SELF_INDEX_RMAUTH_SM = 1,
+ SCE_KERNEL_SYSROOT_SELF_INDEX_ENCDEC_W_PORTABILITY_SM = 2
+} SceKernelSysrootSelfIndex;
+
+typedef struct SceKernelSysrootSelfInfo {
+ uint32_t size;
+ void *self_data;
+ uint32_t self_size;
+} SceKernelSysrootSelfInfo;
+
+/**
* Allocates a new memory block
*
* @param[in] name - Name for the memory block
@@ -144,7 +157,7 @@ typedef struct SceKernelProcessContext {
*/
SceUID sceKernelAllocMemBlock(const char *name, SceKernelMemBlockType type, int size, SceKernelAllocMemBlockKernelOpt *optp);
-/***
+/**
* Frees new memory block
*
* @param[in] uid - SceUID of the memory block to free
@@ -153,7 +166,7 @@ SceUID sceKernelAllocMemBlock(const char *name, SceKernelMemBlockType type, int
*/
int sceKernelFreeMemBlock(SceUID uid);
-/***
+/**
* Gets the base address of a memory block
*
* @param[in] uid - SceUID of the memory block
@@ -163,7 +176,7 @@ int sceKernelFreeMemBlock(SceUID uid);
*/
int sceKernelGetMemBlockBase(SceUID uid, void **basep);
-/***
+/**
* Gets the memory block type of a memory block
*
* @param[in] uid - SceUID of the memory block
@@ -173,7 +186,7 @@ int sceKernelGetMemBlockBase(SceUID uid, void **basep);
*/
int sceKernelGetMemBlockType(SceUID uid, unsigned int *type);
-/***
+/**
* Find the SceUID of a memory block
*
* @param[in] addr - Base address of the memory block
@@ -183,7 +196,7 @@ int sceKernelGetMemBlockType(SceUID uid, unsigned int *type);
*/
SceUID sceKernelFindMemBlockByAddr(const void *addr, SceSize size);
-/***
+/**
* Find the SceUID of a memory block for a PID
*
* @param[in] pid - PID of the process
@@ -259,10 +272,13 @@ int sceKernelUidRetain(SceUID uid);
int sceKernelUidRelease(SceUID uid);
SceClass *sceKernelGetUidClass(void);
+SceClass *sceKernelGetUidDLinkClass(void);
+SceClass *sceKernelGetUidHeapClass(void);
+SceClass *sceKernelGetUidMemBlockClass(void);
int sceKernelCreateClass(SceClass *cls, const char *name, void *uidclass, size_t itemsize, SceClassCallback create, SceClassCallback destroy);
int sceKernelDeleteUserUid(SceUID pid, SceUID user_uid);
int sceKernelDeleteUid(SceUID uid);
-int sceKernelFindClassByName(const char name, SceClass **cls);
+int sceKernelFindClassByName(const char *name, SceClass **cls);
int sceKernelSwitchVmaForPid(SceUID pid);
@@ -272,6 +288,17 @@ int sceKernelGetPidContext(SceUID pid, SceKernelProcessContext **ctx);
int sceKernelGetProcessTitleId(SceUID pid, char *titleid, size_t len);
int sceKernelMapBlockUserVisible(SceUID uid);
+int sceKernelMapUserBlock(const char *name, int permission, int type,
+ const void *user_buf, unsigned int size, void **kernel_page,
+ unsigned int *kernel_size, unsigned int *kernel_offset);
+int sceKernelMapUserBlockDefaultType(const char *name, int permission, const void *user_buf,
+ unsigned int size, void **kernel_page,
+ unsigned int *kernel_size, unsigned int *kernel_offset);
+int sceKernelMapUserBlockDefaultTypeForPid(int pid, const char *name, int permission,
+ const void *user_buf, unsigned int size, void **kernel_page,
+ unsigned int *kernel_size, unsigned int *kernel_offset);
+
+int sceSysrootGetSelfInfo(SceKernelSysrootSelfIndex index, SceKernelSysrootSelfInfo *info);
/**
* Get the physical address of a given virtual address
@@ -281,7 +308,7 @@ int sceKernelMapBlockUserVisible(SceUID uid);
*
* @return 0 on success, < 0 on error.
*/
-int sceKernelGetPaddr(void *addr, uintptr_t *paddr);
+int sceKernelGetPaddr(const void *addr, uintptr_t *paddr);
/**
* Get the physical address list of a given virtual address range
@@ -392,11 +419,37 @@ int sceKernelMemRangeReleaseForPid(SceUID pid, void *addr, unsigned int size);
*/
int sceKernelMemRangeReleaseWithPerm(SceKernelMemoryRefPerm perm, void *addr, unsigned int size);
-int sceSysrootIsManufacturingMode(void);
+int sceSysrootUseExternalStorage(void);
+
+#define sceSysrootIsManufacturingMode() sceSysrootUseExternalStorage()
+
+int sceSysrootUseInternalStorage(void);
int sceDebugPrintf(const char *fmt, ...);
-int sceDebugPrintf2(int unk0, int unk1, const char *fmt, ...);
+typedef struct kernel_message_ctx
+{
+ int hex_value0_hi;
+ int hex_value0_lo;
+ int hex_value1;
+ char* msg0;
+ int num;
+ char* msg1;
+} kernel_message_ctx;
+
+// msg_type_flag : 0 or 0xB
+
+int sceDebugPrintf2(int msg_type_flag, kernel_message_ctx *msg_ctx, const char *fmt, ...);
+
+int sceDebugVprintf(const char *fmt, va_list args);
+
+int sceDebugPrintKernelPanic(kernel_message_ctx *msg_ctx, void *some_address);
+
+int sceDebugPrintfKernelPanic(kernel_message_ctx *msg_ctx, void *some_address, char* format, ...);
+
+int sceDebugPrintKernelAssertion(int condition, kernel_message_ctx *msg_ctx, void *some_address);
+
+int sceDebugPrintfKernelAssertion(int unk, int condition, kernel_message_ctx *msg_ctx, int some_address, const char *fmt, ...);
int sceDebugSetHandlers(int (*func)(void *args, char c), void *args);
@@ -406,9 +459,36 @@ void *sceDebugGetPutcharHandler(void);
int sceDebugPutchar(int character);
+int sceDebugDisableInfoDump(int flag);
+
+typedef struct
+{
+ size_t size; //!< sizeof(SceSysrootProcessHandler)
+ int (* unk_4)(void);
+ int (* unk_8)(void);
+ int (* unk_C)(void);
+ int (* unk_10)(void);
+ int (* unk_14)(void);
+ int (* unk_18)(void);
+ int (* on_process_created)(void); //!< called when process is created
+ int (* unk_20)(void);
+ int (* unk_24)(void);
+} SceSysrootProcessHandler;
+
+/**
+ * Set handlers for the process lifecycle.
+ *
+ * This internal function allows a developer to introspect and receive events based
+ * on the process lifecycle.
+ *
+ * @param[in] handlers Pointer to struct containing the handlers. This function does not copy the handlers, so this pointer must remain valid after a successful call.
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceKernelSysrootSetProcessHandler(const SceSysrootProcessHandler *handlers);
+
#ifdef __cplusplus
}
#endif
#endif
-
diff --git a/include/kernel/kernel/threadmgr.h b/include/kernel/kernel/threadmgr.h
index 8990a7b..76e2b4c 100644
--- a/include/kernel/kernel/threadmgr.h
+++ b/include/kernel/kernel/threadmgr.h
@@ -1,21 +1,14 @@
#ifndef _PSP2_KERNEL_THREADMGR_H_
#define _PSP2_KERNEL_THREADMGR_H_
-#include <psp2kern/types.h>
+#include <psp2common/kernel/threadmgr.h>
#ifdef __cplusplus
extern "C" {
#endif
-#define SCE_KERNEL_MUTEX_ATTR_RECURSIVE 2
-
-/** 64-bit system clock type. */
-typedef SceUInt64 SceKernelSysClock;
-
/* Threads. */
-typedef int (*SceKernelThreadEntry)(SceSize args, void *argp);
-
/** Additional options used when creating threads. */
typedef struct SceKernelThreadOptParam {
/** Size of the ::SceKernelThreadOptParam structure. */
@@ -439,18 +432,71 @@ int sceKernelUnlockMutex(SceUID mutexid, int unlockCount);
*/
int sceKernelCancelMutex(SceUID mutexid, int newCount, int *numWaitThreads);
-typedef struct SceKernelLwMutexWork {
- SceInt64 data[4];
-} SceKernelLwMutexWork;
+/**
+ * Retrieve information about a mutex.
+ *
+ * @param mutexid - UID of the mutex to retrieve info for.
+ * @param info - Pointer to a ::SceKernelMutexInfo struct to receive the info.
+ *
+ * @return < 0 on error.
+ */
+int sceKernelGetMutexInfo(SceUID mutexid, SceKernelMutexInfo *info);
+
+/* Fast mutex */
+
+typedef struct SceKernelFastMutexWork {
+ SceInt64 data[8];
+} SceKernelFastMutexWork;
-typedef struct SceKernelLwMutexOptParam {
+typedef enum SceKernelFastMutexAttr {
+ SCE_KERNEL_FAST_MUTEX_ATTR_RECURSIVE = 0x00000002,
+ SCE_KERNEL_FAST_MUTEX_ATTR_CEILING = 0x00000004,
+ SCE_KERNEL_FAST_MUTEX_ATTR_UNK_3 = 0x00000008,
+ SCE_KERNEL_FAST_MUTEX_ATTR_TH_FIFO = 0x00000000,
+ SCE_KERNEL_FAST_MUTEX_ATTR_TH_PRIO = 0x00002000,
+ SCE_KERNEL_FAST_MUTEX_ATTR_UNK_15 = 0x00008000,
+ // All other flags are invalid
+} SceKernelFastMutexAttr;
+
+typedef struct SceKernelFastMutexOptParam {
SceSize size;
-} SceKernelLwMutexOptParam;
+ SceInt32 ceilingPriority;
+} SceKernelFastMutexOptParam;
+
+SceInt32 sceKernelInitializeFastMutex(
+ SceKernelFastMutexWork *pWork,
+ const char *pName,
+ SceKernelFastMutexAttr attr,
+ const SceKernelFastMutexOptParam *pOptParam);
+
+SceInt32 sceKernelLockFastMutex(SceKernelFastMutexWork *pWork);
-int sceKernelInitializeFastMutex(void *mutex, const char *name, int unk0, int unk1);
-int sceKernelLockFastMutex(void *mutex);
-int sceKernelUnlockFastMutex(void *mutex);
-int sceKernelDeleteFastMutex(void *mutex);
+SceInt32 sceKernelTryLockFastMutex(SceKernelFastMutexWork *pWork);
+
+SceInt32 sceKernelUnlockFastMutex(SceKernelFastMutexWork *pWork);
+
+SceInt32 sceKernelFinalizeFastMutex(SceKernelFastMutexWork *pWork);
+
+typedef struct SceKernelFastMutexInfo {
+// 0x00
+ SceSize size;
+ SceUID uid;
+ char name[SCE_UID_NAMELEN + 1];
+ SceKernelFastMutexAttr attr;
+ SceKernelFastMutexWork *pWork;
+// 0x30
+ SceInt32 currentCount;
+ SceUID currentOwnerId;
+ SceInt32 ceilingPriority;
+ SceInt32 unk3C;
+// 0x40
+ SceUInt32 numWaitThreads;
+// 0x44
+} SceKernelFastMutexInfo;
+
+SceInt32 sceKernelGetFastMutexInfo(SceKernelFastMutexWork *pWork, SceKernelFastMutexInfo *pInfo);
+
+SceInt32 sceKernelGetFastMutexInfoById(SceUID uid, SceKernelFastMutexInfo *pInfo);
/* Event flags. */
@@ -829,6 +875,200 @@ int sceKernelRunWithStack(int stack_size, int (*to_call)(void *), void *args);
*/
int sceKernelGetFaultingProcess(SceKernelFaultingProcessInfo *info);
+/* Workqueues */
+
+typedef int (*SceKernelWorkQueueWorkFunction)(void *args);
+
+/**
+ * @brief Enqueue work to a workqueue
+ *
+ * @param[in] uid UID of the workqueue (0x10023 for the SceKernelGlobalWorkQueue)
+ * @param[in] name Name of the work to enqueue
+ * @param[in] work Work function to enqueue
+ * @param[in] args Argument to pass to the work function
+ *
+ * @return Zero on success
+ */
+int sceKernelEnqueueWorkQueue(SceUID uid, const char *name, SceKernelWorkQueueWorkFunction work, void *args);
+
+/**
+ * @brief Get the main thread for a given process.
+ * @param[in] pid The process id to query for.
+ * @return The thread UID on success, else < 0 on error.
+ */
+SceUID sceKernelGetProcessMainThread(SceUID pid);
+
+/**
+ * @brief Retrieve a list of all threads belonging to a process.
+ * @param[in] pid The process to query.
+ * @param[out] ids The list of thread ids. Can be NULL if output is not required.
+ * @param[in] n The max number of thread ids to copy out.
+ * @param[out] copy_count The number of thread ids copied.
+ * @return The number of threads within the process, else < 0 on error.
+ */
+int sceKernelGetThreadIdList(SceUID pid, SceUID *ids, int n, int *copy_count);
+
+/** Structure representing all ARM registers */
+typedef struct ArmCpuRegisters
+{
+ uint32_t r0;
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t r11;
+ uint32_t r12;
+ uint32_t sp;
+ uint32_t lr;
+ uint32_t pc;
+ uint32_t cpsr;
+ uint32_t unk;
+} ArmCpuRegisters;
+
+/** Structure containing a threads register states. */
+typedef struct ThreadCpuRegisters
+{
+ /** Set of registers used for user mode. */
+ ArmCpuRegisters user;
+
+ /** Set of registers used for kernel mode. */
+ ArmCpuRegisters kernel;
+} ThreadCpuRegisters;
+
+/**
+ * @brief Query the state of the registers for a suspended thread.
+ *
+ * The registers returned are the user/kernel set for the requested thread.
+ * It's not certain that user/kernel is correct representation, instead it could be current/exception.
+ * The thread provided must be suspended for this function to succeed.
+ *
+ * @param[in] thid The thread to query.
+ * @param[out] registers The set of registers belonging to the thread.
+ * @return Zero on success, else < 0 on error.
+ */
+int sceKernelGetThreadCpuRegisters(SceUID thid, ThreadCpuRegisters *registers);
+
+
+/**
+ * @brief Change the thread suspension status to another value.
+ *
+ * More research needs to be done to find out exactly what each status actually means. Some examples of useful scenarios:
+ * When handling an exception changing the status to 0x1002 (on a newly suspended thread) will stop the kernel rethrowing the same exception.
+ * When resuming a suspended thread changing the status to 2 will allow it to resume.
+ *
+ * @param[in] thid The thread to change.
+ * @param[in] status The new status for suspension.
+ * @return Zero on success, else < 0 on error.
+ */
+int sceKernelChangeThreadSuspendStatus(SceUID thid, int status);
+
+/* Message pipes */
+
+/**
+ * Create a message pipe
+ *
+ * @param name - Name of the pipe
+ * @param type - The type of memory attribute to use internally (set to 0x40)
+ * @param attr - Set to 12
+ * @param bufSize - The size of the internal buffer in multiples of 0x1000 (4KB)
+ * @param opt - Message pipe options (set to NULL)
+ *
+ * @return The UID of the created pipe, < 0 on error
+ */
+SceUID sceKernelCreateMsgPipe(const char *name, int type, int attr, unsigned int bufSize, void *opt);
+
+/**
+ * Delete a message pipe
+ *
+ * @param uid - The UID of the pipe
+ *
+ * @return 0 on success, < 0 on error
+ */
+int sceKernelDeleteMsgPipe(SceUID uid);
+
+typedef struct
+{
+ const void *message;
+ unsigned int size;
+} MsgPipeSendData;
+
+/**
+ * Send a message to a pipe
+ *
+ * @param uid - The UID of the pipe
+ * @param message - Pointer to the message
+ * @param size - Size of the message
+ * @param unk1 - Unknown - async vs sync? use 0 for sync
+ * @param unk2 - Unknown - use NULL
+ * @param timeout - Timeout for send in us. use NULL to wait indefinitely
+ *
+ * @return 0 on success, < 0 on error
+ */
+int sceKernelSendMsgPipeVector(SceUID uid, const MsgPipeSendData *v, unsigned int n, int unk1, void *unk2, unsigned int *timeout);
+
+/**
+ * Try to send a message to a pipe
+ *
+ * @param uid - The UID of the pipe
+ * @param message - Pointer to the message
+ * @param size - Size of the message
+ * @param unk1 - Unknown - use 0
+ * @param unk2 - Unknown - use NULL
+ *
+ * @return 0 on success, < 0 on error
+ */
+int sceKernelTrySendMsgPipeVector(SceUID uid, const MsgPipeSendData *v, unsigned int size, int unk1, void *unk2);
+
+typedef struct
+{
+ void *message;
+ unsigned int size;
+} MsgPipeRecvData;
+
+/**
+ * Receive a message from a pipe
+ *
+ * @param uid - The UID of the pipe
+ * @param message - Pointer to the message
+ * @param size - Size of the message
+ * @param unk1 - Unknown - async vs sync? use 0 for sync
+ * @param unk2 - Unknown - use NULL
+ * @param timeout - Timeout for receive in us. use NULL to wait indefinitely
+ *
+ * @return 0 on success, < 0 on error
+ */
+int sceKernelReceiveMsgPipeVector(SceUID uid, const MsgPipeRecvData *v, unsigned int n, int unk1, void *unk2, unsigned int *timeout);
+
+/**
+ * Receive a message from a pipe
+ *
+ * @param uid - The UID of the pipe
+ * @param message - Pointer to the message
+ * @param size - Size of the message
+ * @param unk1 - Unknown - use 0
+ * @param unk2 - Unknown - use NULL
+ *
+ * @return 0 on success, < 0 on error
+ */
+int sceKernelTryReceiveMsgPipeVector(SceUID uid, const MsgPipeRecvData *v, unsigned int size, int unk1, void *unk2);
+
+/**
+ * Cancel a message pipe
+ *
+ * @param uid - UID of the pipe to cancel
+ * @param psend - Receive number of sending threads, NULL is valid
+ * @param precv - Receive number of receiving threads, NULL is valid
+ *
+ * @return 0 on success, < 0 on error
+ */
+int sceKernelCancelMsgPipe(SceUID uid, int *psend, int *precv);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/kernel/kernel/utils.h b/include/kernel/kernel/utils.h
new file mode 100644
index 0000000..c7f1c92
--- /dev/null
+++ b/include/kernel/kernel/utils.h
@@ -0,0 +1,205 @@
+#ifndef _PSP2_KERNEL_UTILS_H_
+#define _PSP2_KERNEL_UTILS_H_
+
+#include <psp2kern/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SCE_SHA1_BLOCK_SIZE 64
+#define SCE_SHA1_DIGEST_SIZE 20
+#define SCE_SHA224_BLOCK_SIZE 64
+#define SCE_SHA224_DIGEST_SIZE 28
+#define SCE_SHA256_BLOCK_SIZE 64
+#define SCE_SHA256_DIGEST_SIZE 32
+
+typedef struct SceSha1Context {
+ uint32_t h[5];
+ uint16_t usRemains;
+ uint16_t usComputed;
+ uint64_t ullTotalLen;
+ char buf[SCE_SHA1_BLOCK_SIZE];
+ char result[SCE_SHA1_DIGEST_SIZE];
+ uint32_t pad;
+} SceSha1Context;
+
+typedef struct SceSha224Context {
+ uint32_t h[8];
+ uint32_t pad;
+ uint16_t usRemains;
+ uint16_t usComputed;
+ uint64_t ullTotalLen;
+ char buf[SCE_SHA224_BLOCK_SIZE];
+ char result[SCE_SHA224_DIGEST_SIZE];
+ uint32_t pad2;
+} SceSha224Context;
+
+typedef struct SceSha256Context {
+ uint32_t h[8];
+ uint32_t pad;
+ uint16_t usRemains;
+ uint16_t usComputed;
+ uint64_t ullTotalLen;
+ char buf[SCE_SHA256_BLOCK_SIZE];
+ char result[SCE_SHA256_DIGEST_SIZE];
+} SceSha256Context;
+
+struct SceDeflatePartialInputParam;
+
+typedef struct SceDeflatePartialInputParam {
+ uint32_t size;
+ const void *pBufEnd;
+ void *cookie;
+ const void *(* SceDeflateDecompressPartialInputCallback)(struct SceDeflatePartialInputParam* param, uint32_t outputsize);
+} SceDeflatePartialInputParam;
+
+typedef struct {
+ uint8_t data[976];
+} SceAesContext;
+
+int sceSha1BlockInit(SceSha1Context *pContext);
+int sceSha1BlockUpdate(SceSha1Context *pContext, const void *plain, uint32_t len);
+int sceSha1BlockResult(SceSha1Context *pContext, char *digest);
+int sceSha1Digest(const void *plain, uint32_t len, char *result);
+
+int sceSha224BlockInit(SceSha224Context *pContext);
+int sceSha224BlockUpdate(SceSha224Context *pContext, const void *plain, uint32_t len);
+int sceSha224BlockResult(SceSha224Context *pContext, char *digest);
+int sceSha224Digest(const void *plain, uint32_t len, char *result);
+
+int sceSha256BlockInit(SceSha256Context *pContext);
+int sceSha256BlockUpdate(SceSha256Context *pContext, const void *plain, uint32_t len);
+int sceSha256BlockResult(SceSha256Context *pContext, char *digest);
+int sceSha256Digest(const void *plain, uint32_t len, char *result);
+
+int sceHmacSha1Digest(const unsigned char *key, uint32_t key_len, const void *plain, uint32_t len, char *result);
+int sceHmacSha224Digest(const unsigned char *key, uint32_t key_len, const void *plain, uint32_t len, char *result);
+int sceHmacSha256Digest(const unsigned char *key, uint32_t key_len, const void *plain, uint32_t len, char *result);
+
+/**
+ * @param[out] dst - dst buf
+ * @param[in] dst_size - dst buf size
+ * @param[in] src - Gzip compressed data
+ * @param[out] crc32 - crc32 when decompressed
+ *
+ * @return decompressed size on success, < 0 on error.
+ */
+int sceGzipDecompress(void *dst, uint32_t dst_size, const void *src, uint32_t *crc32);
+
+/**
+ * @brief Check magic of Gzip header
+ *
+ * @param[in] src - Gzip compressed data
+ *
+ * @return 1 on success, 0 is not Gzip data.
+ */
+int sceGzipIsValid(const void *src);
+
+/**
+ * @brief Get filename etc. in Gzip data
+ *
+ * @param[in] src - Gzip compressed data
+ * @param[out] extra - Get information on extra-field
+ * @param[out] name - Get filename information
+ * @param[out] comment - Get comment information
+ * @param[out] crc - Get CRC16 information
+ * @param[out] data - Get compressed data start address
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceGzipGetInfo(const void *src, const void **extra, const char **name, const char **comment, unsigned short *crc, const void **data);
+
+/**
+ * @brief Get filename string address
+ *
+ * @param[in] src - Gzip compressed data
+ *
+ * @return string address on success, NULL on error.
+ */
+const char *sceGzipGetName(const void *src);
+
+/**
+ * @brief Get comment string address
+ *
+ * @param[in] src - Gzip compressed data
+ *
+ * @return string address on success, NULL on error.
+ */
+const char *sceGzipGetComment(const void *src);
+
+/**
+ * @brief Get compressed data start address
+ *
+ * @param[in] src - Gzip compressed data
+ *
+ * @return compressed data address on success, NULL on error.
+ */
+const void *sceGzipGetCompressedData(const void *src);
+
+/**
+ * @brief Get filename etc. in Zlib data
+ *
+ * @param[in] src - Zlib compressed data
+ * @param[out] cmf - Get CMF (Compression Method and flags)
+ * @param[out] flg - Get FLG (FLaGs)
+ * @param[out] dictid - Get DictId
+ * @param[out] data - Get compressed data start address
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceZlibGetInfo(const void *src, unsigned char *cmf, unsigned char *flg, unsigned int *dictid, const void **data);
+
+/**
+ * @brief Get compressed data start address
+ *
+ * @param[in] src - Gzip compressed data
+ *
+ * @return compressed data address on success, NULL on error.
+ */
+const void *sceZlibGetCompressedData(const void *src);
+
+/**
+ * @param[out] dst - dst buf
+ * @param[in] dst_size - dst buf size
+ * @param[in] src - Zlib compressed data
+ * @param[out] adler32 - adler32 when decompressed
+ *
+ * @return decompressed size on success, < 0 on error.
+ */
+int sceZlibDecompress(void *dst, uint32_t dst_size, const void *src, uint32_t *adler32);
+
+/**
+ * @param[out] dst - dst buf
+ * @param[in] dst_size - dst buf size
+ * @param[in] src - Deflate compressed data
+ * @param[out] next - next data
+ *
+ * @return decompressed size on success, < 0 on error.
+ */
+int sceDeflateDecompress(void *dst, uint32_t dst_size, const void *src, const void **next);
+int sceDeflateDecompressPartial(void *dst, unsigned int dst_size, const void *src, const void **next, SceDeflatePartialInputParam *cbInfo);
+
+/**
+ * @param[out] ctx - out key data, etc...
+ * @param[in] blocksize - 128 or 192 or 256
+ * @param[in] keysize - 128 or 192 or 256
+ * @param[in] key - key data
+ *
+ * @return 0 on success, < 0 on error.
+ */
+int sceAesInit1(SceAesContext *ctx, int blocksize, int keysize, const void *key);
+int sceAesInit2(SceAesContext *ctx, int blocksize, int keysize, const void *key);
+int sceAesInit3(SceAesContext *ctx, int blocksize, int keysize, const void *key);
+
+int sceAesDecrypt1(SceAesContext *ctx, const void *src, void *dst);
+int sceAesDecrypt2(SceAesContext *ctx, const void *src, void *dst);
+
+int sceAesEncrypt1(SceAesContext *ctx, const void *src, void *dst);
+int sceAesEncrypt2(SceAesContext *ctx, const void *src, void *dst);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PSP2_KERNEL_UTILS_H_ */