SceSysmem

From Vita Development Wiki
Revision as of 21:53, 15 September 2021 by CelesteBlue (talk | contribs)
Jump to navigation Jump to search

SceSysmem is a kernel module that acts as the heart of the kernel. It exports multiple libraries for various features. SceSysmem is the first module that is loaded in the kernel load sequence and its libraries are imported by almost all other modules. See Virtual Memory and Physical Memory for more details on the memory subsystem.

Module

This module exists in both non-secure and secure world. The non-secure world SELF can be found in os0:kd/sysmem.skprx. It also can be found in the Boot Image.

Version World Privilege
1.50-3.61 Non-secure Kernel
1.69-1.80 Secure Kernel

Libraries

Known NIDs

Version Name World Visibility NID
1.50-3.61 SceSysmemForKernel Non-secure Kernel 0x63A519E5
3.63-3.65 SceSysmemForKernel Non-secure Kernel 0x02451F0F
1.50-3.60 SceSysmemForDriver Non-secure Kernel 0x6F25E18A
1.50-1.692 SceSysmemForDebugger Non-secure Kernel 0xC7309957
1.50-3.60 SceSysmem Non-secure User 0x37FE725A
1.50-3.60 SceDipsw Non-secure User 0xB36D5922
1.50-3.60 SceDipswForDriver Non-secure Kernel 0xC9E26388
1.50-3.60 SceUartForKernel Non-secure Kernel 0xC03DBE40
1.50-3.60 SceCpu Non-secure User 0x45265161
1.50-3.60 SceCpuForKernel Non-secure Kernel 0x54BF2BAB
3.65 SceCpuForKernel Non-secure Kernel 0xA5195D20
1.50-3.60 SceCpuForDriver Non-secure Kernel 0x40ECDB0E
1.50-1.69 SceSysclibForKernel Non-secure Kernel 0x24878615
3.60 SceSysclibForKernel Non-secure Kernel removed
1.50-3.60 SceSysclibForDriver Non-secure Kernel 0x7EE45391
1.50-3.60 SceSysrootForKernel Non-secure Kernel 0x3691DA45
1.50-3.60 SceSysrootForDriver Non-secure Kernel 0x2ED7F97A
1.50-3.60 SceKernelUtilsForDriver Non-secure Kernel 0x496AD8B4
1.50 SceZlibForDriver Non-secure Kernel 0xE241534E
1.50-3.60 SceKernelSuspendForDriver Non-secure Kernel 0x7290B21C
1.50-3.60 SceQafMgrForDriver Non-secure Kernel 0x4E29D3B6
1.50-3.60 ScePmMgrForDriver Non-secure Kernel 0xF13F32F9
1.50-3.60 SceSblAIMgrForDriver Non-secure Kernel 0xFD00C69A
1.50-3.60 SceProcEventForDriver Non-secure Kernel 0x887F19D0
1.50-3.60 SceDebugLed Non-secure User 0xAE004C0A
1.50-3.60 SceDebugLedForDriver Non-secure Kernel 0x7BC05EAD
1.50-3.60 SceDebugForKernel Non-secure Kernel 0x88C17370
1.50-3.60 SceDebugForDriver Non-secure Kernel 0x88758561
1.69-3.60 SceSysmemForTZS Secure Kernel 0x08680060
1.69-3.60 SceDipswForTZS Secure Kernel 0x9DBF584C
1.80-3.60 SceUartForTZS Secure Kernel 0xA1D740D7
1.80-3.60 SceDebugForTZS Secure Kernel 0x028FFADB
1.69-3.60 SceCpuForTZS Secure Kernel 0xC516B23E
1.69-3.60 SceSysclibForTZS Secure Kernel 0xC839BB78
1.69-3.60 SceSysrootForTZS Secure Kernel 0xFEFF641D
1.69-3.60 SceQafMgrForTZS Secure Kernel 0x637069DD
1.69-3.60 ScePmMgrForTZS Secure Kernel 0x27F1AFD8
1.69-3.60 SceSblAIMgrForTZS Secure Kernel 0x60D19047

Types

// Dummy typedefs for wiki
typedef struct SceKernelVARange SceKernelVARange;
typedef struct SceKernelBootArgs SceKernelBootArgs;
typedef struct SceSysrootProcessHandler SceSysrootProcessHandler;
typedef struct SceSysrootModulemgrHandlers SceSysrootModulemgrHandlers;
typedef struct SceSysrootForKernel_D29BCA77_struct SceSysrootForKernel_D29BCA77_struct;
typedef struct SceSysrootForDriver_733C243E_struct SceSysrootForDriver_733C243E_struct;

typedef SceUInt32 SceCachedSecureModule;
#define SCE_CACHED_SECURE_MODULE_GCAUTHMGR 0            // os0:sm/gcauthmgr_sm.self
#define SCE_CACHED_SECURE_MODULE_RMAUTH 1               // os0:sm/rmauth_sm.self
#define SCE_CACHED_SECURE_MODULE_ENDEC_W_PORTABILITY 2  // os0:sm/encdec_w_portability_sm.self

typedef struct SceCachedSecureModuleInfo { // size is 0xC
	SceSize size;     // Size of this structure
	void *pSelfData;  // Virtual address of the SM
	SceSize selfSize; // Size of the SM
} SceCachedSecureModuleInfo;

#define SCE_SYSROOT_INIT_CALLBACK_MAX_FUNC (9)
#define SCE_SYSROOT_INIT_CALLBACK_MAX_SLOT (8)

typedef struct SceUIDSysrootObject { // size is 0x41C on FW 3.60
	void *object;
	SceClass *sce_class;
	SceSize size; // Size of this structure
	SceUInt32 magic1;
	int cpu_intr;
	SceSize boot_alloc_memory_size; // 0x400
	void *boot_alloc_memory;      // used by boot time malloc
	int unk_0x1C; // 0x4
	void *unk_0x20; // size is 0x80-bytes
	SceUInt32 boot_flags; // 0x10 for coldboot, 0x1 for secure state
	SceUInt32 status;
	SceCorelockContext corelock_context;

	// start ModulePrivate
	int unk_0x34;   // ex:0
	int unk_0x38;   // ex:0
	void *unk_0x3C; // size is 4 byte
	void *unk_0x40; // Related to SceHeap. size is 0xDC byte.
	void *unk_0x44; // SceExcpmgr data vaddr?
	void *unk_0x48; // SceKernelIntrMgr data vaddr?
	void *unk_0x4C;
	void *unk_0x50;
	int unk_0x54;   // ex:0
	void *unk_0x58;
	int unk_0x5C;   // ex:0
	int unk_0x60;   // ex:0
	int unk_0x64;   // ex:0
	int unk_0x68;   // Used by Tzs SceSblSmsched
	// end ModulePrivate

	SceKblParam *kbl_param;
	SceKernelBootArgs *boot_args;
	SceUInt32 soc_revision;
	SceUInt32 unk_0x78; // ex:0
	SceUInt32 soc_revision2;
	SceUInt32 model_info;
	SceUInt32 model_capability;

	void *longtime5base;

	int cpu_intr_for_init_callback;
	SceUInt32 init_callback_registable_base_number;
	struct {
		int (* callback)(int a1, void *args);
		void *args;
	} init_callback_slot[SCE_SYSROOT_INIT_CALLBACK_MAX_FUNC][SCE_SYSROOT_INIT_CALLBACK_MAX_SLOT];

	int (* sceKernelSysrootThreadMgrStartAfterProcess)(void);
	int (* sceKernelSysrootIofilemgrStart)(void);
	void *unk_0x2DC;
	void *unk_0x2E0;
	char *sysroot_names[9];
	SceUID this_object_uid;
	void *unk_0x30C; // size is 0x2C-bytes, maybe guid entry heap object
	void *unk_0x310;
	void *unk_0x314;
	void *VBAR;
	void *MVBAR;
	void *unk_0x320;
	void **unk_func_0x324; // SceSblACMgr
	SceUID (* sceKernelSysrootGetThreadId)(void);
	int (* sceKernelSysrootThreadFunction3)(void);                   // Temp name, SceKernelThreadMgr + 0xC79, SceThreadmgrForDriver_91382762
	SceUID (* sceKernelSysrootGetProcessId)(void);
	int (* sceKernelSysrootThreadFunction4)(void);                   // Temp name, SceKernelThreadMgr + 0x8D1
	int (* sceKernelSysrootThreadFunction5)(void);                   // Temp name, SceKernelThreadMgr + 0x8ED
	int (* sceKernelSysrootThreadFunction6)(void);                   // Temp name, SceKernelThreadMgr + 0x90D
	void (* sceKernelSysrootThreadFunction7)(void);                  // Temp name, SceKernelThreadMgr + 0xE69
	int (* sceKernelSysrootThreadFunction8)(void);                   // Temp name, SceKernelThreadMgr + 0x8BD, SceThreadmgrForDriver_332E127C
	int (* sceKernelSysrootThreadFunction9)(int a1, int a2, int a3); // Temp name, SceKernelThreadMgr + 0x2541
	int (* sceKernelSysrootThreadFunction10)(int a1);                // Temp name, SceKernelThreadMgr + 0xC99, SceThreadmgrForDriver_AB977C72
	SceSysrootModulemgrHandlers *modulemgr_handlers;
	int unk_0x354; // ex:0xFFFFFFFF
	SceSysrootForKernel_D29BCA77_struct *processmgr_callbacks_1;
	SceSysrootForDriver_733C243E_struct *processmgr_callbacks_2;
	void *unk_func_0x360; // SceDeci4pSDfMgr
	int (* sceKernelSysrootGetBusError)(void *dst, SceSize len);
	int (* sceKernelSysrootAppMgrFunction1)(int a1, int a2, int a3, int a4, int a5, int a6); // SceAppMgr + 0x2795, SceAppMgrForDriver_324DD34E
	SceUID (* sceKernelSysrootGetShellPid)(void);
	void *unk_func_0x370; // SceCoredump + 0x7109, SceCoredumpForDriver_A7D214A7
	void *unk_func_0x374; // SceCoredump + 0x74F9, SceCoredumpForDriver_340856F7
	void *unk_func_0x378; // SceCoredump + 0x132ED, SceCoredumpForDriver_EF20949F
	int unk_0x37C; // ex:0
	int (* sceKernelSysrootGetLicenseStatusForDriver)(void); // SceSblPostSsMgr + 0x9001, sceSblLicMgrGetLicenseStatusForDriver
	int (* unk_func_0x384)(void); // SceSblPostSsMgr + 0xB005, SceSblPostSsMgrForDriver_22599675, get flag
	int (* unk_func_0x388)(void); // SceSblPostSsMgr + 0xB011, SceSblPostSsMgrForDriver_9B49C249, get flag
	void *unk_func_0x38C;         // SceSblPostSsMgr + 0xB4ED, SceSblPostSsMgrForDriver_D8A2D465
	int (* sceKernelSysrootGetTrilithiumBufferForDriver)(void); // SceSblPostSsMgr + 0xB111, sceSblUtMgrGetTrilithiumBufferForDriver
	int (* sceKernelSysrootHasNpTestFlag)(void);
	void *unk_func_0x398; // SceSblUpdateMgr + 0x8B01
	int (* sceKernelSysrootLedSetMode)(int led, int mode, void *led_configuration);
	SceKernelVARange *cached_sm_info_ranges; // See SceCachedSecureModuleInfo
	int (* sceKernelSysrootGetFunctionNameByNIDForKernel)(SceNID funcnid, const char **name); // sceNidsymtblGetFunctionNameByNIDForDriver
	void *SceSysrootForKernel_47724459_cb; // SceDeci4pSDfMgr or SceDeci4pDfMgr, set by SceSysrootForDriver_C5EAF5F7
	void *unk_0x3AC; // SceDeci4pSDfMgr
	void *unk_struct_0x3B0; // SceDeci4pDfMgr
	void *unk_0x3B4; // SceDeci4pTsmp
	void *unk_0x3B8; // SceDeci4pTsmp
	void *unk_0x3BC; // SceDeci4pTsmp
	void *unk_0x3C0; // SceDeci4pTsmp
	SceSysrootProcessHandler *process_handler; // maybe for SceDeci4p
	SceSysrootDbgpHandler    *dbgp_handler;    // maybe for SceDeci4p
	void *unk_func_0x3CC; // SceNetPs + 0x3E51, SceNetPsForDriver_83A12CCC
	void *unk_func_0x3D0; // SceNetPs + 0x3F4D, SceNetPsForDriver_C000CA8F
	void *unk_func_0x3D4; // SceDeci4pTmcp
	void *unk_func_0x3D8; // SceDeci4pSDbgp
	void *unk_func_0x3DC; // SceNetPs + 0x3E51, SceNetPsForDriver_83A12CCC
	void *unk_func_0x3E0; // SceNetPs + 0x3F4D, SceNetPsForDriver_C000CA8F
	int (* sceKernelSysrootAppMgrFunction3)(int a1, int a2); // SceAppMgr + 0x9F49
	int (* sceKernelSysrootAppMgrFunction4)(int a1, int a2); // SceAppMgr + 0x9EED
	int (* sceKernelSysrootAppMgrFunction5)(int a1);	 // SceAppMgr + 0x9D31
	void *unk_func_0x3F0; // ScePfsMgr + 0x1, ScePfsMgrForKernel_4C148288
	void *unk_struct_0x3F4; // SceBt
	void *unk_struct_0x3F8; // SceHid
	void *unk_struct_0x3FC; // SceDeci4pSDbgp
	void *unk_data_0x400; // SceDeci4pSDbgp
	void *unk_func_0x404; // SceDeci4pSDfCtl
	void *unk_func_0x408; // SceDeci4pSDfCtl
	void *unk_func_0x40C; // ScePamgr
	void *unk_func_0x410; // ScePamgr
	void *unk_func_0x414; // ScePamgr
	SceUInt32 magic2;
} SceUIDSysrootObject;

typedef SceUIDSysrootObject SceSysroot;

typedef struct SceSysrootForKernel_D29BCA77_struct { // size is 0x44 on FW 0.990-3.60
	SceSize size; // Size of this structure
	void *get_dword_from_offset_0x184;
	void *get_dword_from_offset_0x188;
	void *get_dword_from_offset_0x18C;
	void *sceKernelAllocCurrentProcessHeap;
	void *sceKernelFreeCurrentProcessHeap;
	void *sceKernelAllocRemoteProcessHeap;
	void *sceKernelFreeRemoteProcessHeap;
	void *sceKernelGetProcessLibdb;
	void *sceKernelSetProcessLibdb;
	void *ProcessmgrModuleStart2;
	void *sceKernelRegisterKPLS;
	void *sceKernelGetRemoteKPLS;
	void *sceKernelGetCurrentKPLS;
	void *sceKernelInhibitProcEvent;
	void *sceKernelPermitProcEvent;
	void *sceKernelGetProcessHeapID;
} SceSysrootForKernel_D29BCA77_struct;

typedef struct SceSysrootForDriver_733C243E_struct_old { // size is 0x28 on FW 0.990
	SceSize size; // Size of this structure
	SceUID (* sceKernelGetCurrentProcessId)(void);
	int (* sceKernelGetEntryHeap)(SceUID pid, int *pHeap);
	int (* SceProcessmgrForKernel_C77C2085)(SceUID pid);
	int (* sceKernelPIDtoAddressSpaceCB)(SceUID pid, void **pASCb);
	int (* FUN_81000000)(int* dst, int *src);
	int (* sceKernelGetProcessType)(SceUID pid);
	int (* sceKernelGetProcessSelfAuthInfo)(SceUID pid, SceSelfAuthInfo *self_auth_info);
	int (* sceKernelSetProcessSelfAuthInfo)(SceUID pid, SceSelfAuthInfo *self_auth_info);
	int (* sceKernelGetProcessAccessLevel)(SceUID pid);
} SceSysrootForDriver_733C243E_struct_old;

typedef struct SceSysrootForDriver_733C243E_struct { // size is 0x20 on FW 3.60
	SceSize size; // Size of this structure
	int (__cdecl *get_something)(SceUID pid, int *);
	int (__cdecl *SceProcessmgrForKernel_C77C2085)(SceUID pid);
	int (__cdecl *get_something)(SceUID pid, int *);
	int (__cdecl *sceKernelGetProcessSelfAuthInfo)(SceUID pid, SceSelfAuthInfo *self_auth_info);
	int (__cdecl *sceKernelGetProcessTitleId)(SceUID pid, char *title_id, SceSize len);
	int (__cdecl *sceKernelIncProcessResource)(SceUInt32 type);
	int (__cdecl *sceKernelDecProcessResource)(SceUInt32 type);
} SceSysrootForDriver_733C243E_struct;

typedef struct SceSysrootProcessHandler {
	SceSize size;                                                       // Size of this structure
	void (* unk_4)(SceUID pid, SceUID modid, int flags, uint64_t time); //!< process start shared modules
	void (* exit)(SceUID pid, int flags, uint64_t time);
	void (* kill)(SceUID pid);                                          //!< by SceShell
	void (* unk_10)(SceUID pid, SceUID modid, uint64_t time);
	void (* unk_14)(SceUID pid, SceUID modid, uint64_t time);
	void (* unk_18)(SceUID pid, SceUID modid, uint64_t time);
	int (* on_process_created)(int a1, int a2, int a3);                 //!< called when process is created
	void (* unk_20)(SceUID pid, SceUID modid, uint64_t time);
	void (* unk_24)(SceUID pid, SceUID modid, int flags, uint64_t time);
} SceSysrootProcessHandler;

typedef struct SceSysrootModulemgrHandlers { // size is 0x18 on FW 3.60
	SceSize size; // Size of this structure
	int (* sceKernelGetProcessSyscallInfo)(SceUID pid, const void *module_addr, void *pInfo); // SceKernelModulemgr + 0x20D0 on 3.60
	int (* cb2)(SceUID pid, const void *module_addr); // SceKernelModulemgr + 0x1F44 on 3.60
	void *sceKernelGetModuleInfoMinByAddr;
	void *sceKernelBacktraceInternal;
	void *sceKernelPrintBacktrace;
} SceSysrootModulemgrHandlers;

// ScePamgrCallbacks
typedef struct SceSysrootForDriver_C94C76FA_struct { // size is 0x10 on FW 3.60
	SceSize size; // Size of this structure
	int (__cdecl *unk_cb_4)();
	int (__cdecl *unk_cb_8)();
	int (__cdecl *unk_cb_C)();
} SceSysrootForDriver_C94C76FA_struct;

typedef struct SceKernelFreeMemorySizeInfo {
	SceSize size;
	SceSize sizeMain;
	SceSize sizeCdram;
	SceSize sizePhycont;
} SceKernelFreeMemorySizeInfo;

typedef int (*SceClassCallback)(void *item);

typedef struct SceClass_0990 { // size is 0x10 on FW 0.990
	SceSize size; // Size of this structure
	struct SceClass *next;
	struct SceClass *root; // to confirm
	struct SceClass *prev; // to confirm
} SceClass_0990;

typedef struct SceClass_wrong { // size is 0x2C on FW 3.60
	struct SceClass *next;				// 0x00
	struct SceClass *root;				// 0x04
	struct SceClass *prev;				// 0x08
	const char *name;				// 0x0C
	struct SceClass *uid_class;			// 0x10
	unsigned int attr;				// 0x14
	unsigned short item_size;			// 0x18
	unsigned short unk_1A;				// 0x1A
	SceClassCallback constructor;			// 0x1C
	SceClassCallback destructor;			// 0x20
	const unsigned int magic;			// 0x24 - 0xABCE9DA5
	SceClassCallback allocMethod;			// 0x28
} SceClass_wrong;

// Aka SceObjectBase in vitasdk
typedef struct SceKernelObject {
	void *pObject;
	SceClass *pClass;
	uintptr_t data[];
} SceKernelObject;

// Added with the wrong struct, but this could be another SceUIDXxxClass struct
typedef struct SceKernelObject_wrong { // size is at least 0x24
	void *pObject;			// 0x0
	SceClass pClass;		// 0x4
	uint32_t type;			// 0x8
	uint16_t lcount;		// 0xC
	uint16_t ucount;		// 0xE
	uint16_t ccount;		// 0x10
	uint32_t unk_12;		// 0x12 - 0x54c3
	uint16_t unk_16;		// 0x16
	uint32_t uid;			// 0x18
	char unk_1C[4];			// 0x1C
	const char *name;		// 0x20
	uint32_t indexRaw;		// 0x24
} SceKernelObject_wrong;

/** @name Memory types that can be specified with sceKernelAllocMemBlock
 */
/*@{*/

/**
 * @brief User readable / writable LPDDR2 memory
 *
 * This type secures a readable / writable memory block in user space.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_RW			0x0c20d060U

#define SCE_KERNEL_MEMBLOCK_TYPE_USER_RWDATA			SCE_KERNEL_MEMBLOCK_TYPE_USER_RW

/**
 * @brief User readable / writable LPDDR2 non-cache memory
 *
 * A type to secure a memory block on LPDDR2 that is readable
 * and writable in user space and does not use cache.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_NC_RW			0x0c208060U

/**
 * @brief An alias for SCE_KERNEL_MEMBLOCK_TYPE_USER_NC_RW.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE		SCE_KERNEL_MEMBLOCK_TYPE_USER_NC_RW

/**
 * @brief An alias for SCE_KERNEL_MEMBLOCK_TYPE_USER_NC_RW.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_RWDATA_UNCACHE		SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE

/**
 * @brief User readable and writable LPDDR2 physical continuous memory
 *
 * A type that can read and write in user space and secure
 * memory blocks from the physical continuous memory area.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_RW		0x0c80d060U

/**
 * @brief User-readable and non-cacheable physical continuous memory
 *
 * A type for on-cacheable read / write in user space and to secure
 * memory blocks from the physical continuous memory area.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW	0x0d808060U

/**
 * @brief User-readable and non-cacheable CDRAM memory
 *
 * A type that can be read and written in user space and secures
 * memory blocks on CDRAM.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW			0x09408060U

/**
 * @brief An alias for SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW.
 */
#define SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RWDATA		SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW

/*@}*/

/**
 * @brief A type representing a memory type
 *
 * A type that represents the type of memory block secured by sceKernelAllocMemBlock.
 */
typedef int		SceKernelMemoryType;

/**
 * @brief Memory block information structure
 *
 * A structure for obtaining information about memory blocks. Size is 0x14 bytes on FW 0.990.
 */
typedef struct SceKernelMemBlockInfo0990 {
	SceSize				size;			/**< Size of the structure itself */
	void				*mappedBase;		/**< Map base address */
	SceSize				mappedSize;		/**< Mapped size */
	SceKernelMemoryType		memoryType;		/**< Memory type */
	SceUInt32			access;			/**< Access right */
} SceKernelMemBlockInfo0990;

/**
 * @brief Memory block information structure
 *
 * A structure for obtaining information about memory blocks. Size is 0x18 bytes on FWs 0.996+.
 */
typedef struct SceKernelMemBlockInfo {
	SceSize				size;			/**< Size of the structure itself */
	void				*mappedBase;		/**< Map base address */
	SceSize				mappedSize;		/**< Mapped size */
	SceKernelMemoryType		memoryType;		/**< Memory type */
	SceUInt32			access;			/**< Access right */
	SceKernelMemBlockType		type;			/**< Memory block type */
} SceKernelMemBlockInfo;

typedef struct SceKernelMemBlockInfoExDetails {
	SceKernelMemBlockType type;
	SceUID memblk_uid;
	const char *name;
	void *mappedBase;
	SceSize mappedSize;
	SceSize memblock_some_size_or_alignment;
	int extraLow;
	int extraHigh;
	int unk20;
	SceUID unk24; // ex: 0x10045, maybe some pid
	SceKernelObject *SceUIDPhyMemPartClass_obj;
} SceKernelMemBlockInfoExDetails;

typedef struct SceKernelMemBlockInfoEx { // size is 0xAC on FW 0.990, 0xB8 on FW 3.60
	SceSize size; // Size of this structure
	SceKernelMemBlockInfoExDetails details;
	SceSize unk30; // paddr num
	SceSize unk34; // paddr size num?
	void *paddr_list[0x10];
	SceSize size_list[0x10];
} SceKernelMemBlockInfoEx;

typedef struct SceKernelMemBlockInfoSimple { // size is 0x24 on FW 0.990
	SceSize size; // Size of this structure
	SceKernelMemBlockType type;
	SceUID uid;
	char *name; // "SceNULL" by default
	char unk_0x10[0x14];
} SceKernelMemBlockInfoSimple;

/*----- memory access permission -----*/

/**
 * @brief readable memory
 */
#define SCE_KERNEL_MEMORY_ACCESS_R		0x04U

/**
 * @brief writable memory
 */
#define SCE_KERNEL_MEMORY_ACCESS_W		0x02U

/**
 * @brief executable memory (kernel only)
 */
#define SCE_KERNEL_MEMORY_ACCESS_X		0x01U

/*----- memory type -----*/

/**
 * @brief uncache normal memory
 */
#define SCE_KERNEL_MEMORY_TYPE_NORMAL_NC	0x80

/**
 * @brief cache normal memory
 */
#define SCE_KERNEL_MEMORY_TYPE_NORMAL		0xD0

/**
 * Optional parameter of sceKernelAllocMemBlock for FWs <=0.940.
 */
 typedef struct SceKernelAllocMemBlockOpt0940 { // size is 0x14 on FW 0.940-0.990
	SceSize		size;				/**< Size of this structure */
	SceUInt32	attr;				/**< Attributes field */
	SceSize		alignment;			/**< Specify alignment.
							SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_ALIGNMENT must be set for the attr member. */
	SceUID		uidBaseBlock;			/**< Base memory block UID */
	const char	*strBaseBlockName;		/**< Base memory block UID name */
} SceKernelAllocMemBlockOpt0940;

/**
 * Option parameter of sceKernelAllocMemBlock
 */
 typedef struct SceKernelAllocMemBlockOpt { // size is 0x14/0x38/0x3C/0x40 on FW 3.60
	/**
	 * Size of this structure
	 */
	SceSize		size;

	/**
	 * Attributes field
	 */
	SceUInt32	attr;

	/**
	 * Specify alignment.
	 * SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_ALIGNMENT must be set for the attr member.
	 */
	SceSize		alignment;

	/**
	 * reserved
	 */
	 SceUInt32	uidBaseBlock;

	/**
	 * reserved2
	 */
	const char	*strBaseBlockName;

#if 0
	/**
	 * mapped base address [out]
	 */
	void		*mappedBase;

	/**
	 * mapped size [out]
	 */
	SceSize		mappedSize;

	/**
	 * memory type [out]
	 */
	SceKernelMemoryType	memoryType;

	SceUInt32	access;
#endif
} SceKernelAllocMemBlockOpt;

/**
 * Option parameter of kernel sceKernelAllocMemBlock on old FWs (as seen on FWs 0.900-0.990)
 */
typedef struct SceKernelAllocMemBlockOptKernel_old { // size is 0x28 on 0.900, 0x2C on 0.910, 0x30 on 0.931-0.990, 0x34 on ?.??
	SceSize size;			// Size of this structure
	SceUInt32 unk_4;
	SceUInt32 attr;
	void *vbase;
	void *pbase;			// Physical address to use as base
	SceSize alignment;
	SceUInt32 extraLow;
	SceUInt32 extraHigh;
	void *base;
	SceUID pid;
	SceKernelPAVector *pPAV;
	SceSize vsize;
	SceUInt32 unk_30;
} SceKernelAllocMemBlockOptKernel_old;

/**
 * Option parameter of kernel sceKernelAllocMemBlock on recent FWs (as seen on FW 3.60)
 */
typedef struct SceKernelAllocMemBlockOptKernel { // size is 0x58 on FW 3.60
	SceSize size;			// Size of this structure
	SceUInt32 unk_4; // maybe unused
	SceUInt32 attr;
	void *vbase;
	void *pbase;			// Physical address to use as base
	SceSize alignment;
	SceUInt32 extraLow;
	SceUInt32 extraHigh;
	void *base;
	SceUID pid;
	SceKernelPAVector *pPAV;
	SceSize vsize;
	SceUInt8  unk_30; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_FIELD_30
	SceUInt32 unk_34; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_38; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_3C; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_40; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_44; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_48; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_4C; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_50; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
	SceUInt32 unk_54; // Related to SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20
} SceKernelAllocMemBlockOptKernel;

/**
 * Attributes to enable some SceKernelAllocMemBlockOpt members.
 */
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_VBASE        0x00000001
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_PBASE        0x00000002
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_ALIGNMENT    0x00000004
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_EXTRA_LOW    0x00000008
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_EXTRA_HIGH   0x00000010
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_0x20         0x00000020
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_BASE         0x00000040
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_PID          0x00000080
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_BASENAME     0x00000200 // Need to find where basename is located in the structure
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_PPAV         0x00001000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_SIZE         0x00002000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_HAS_FIELD_30     0x00010000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_NOPHYPAGE        0x00020000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_PHYCONT	        0x00200000 // Memory area is physically continuous.
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_UNK              0x00400000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_SHARE_VBASE      0x00800000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_SHARE_PHYPAGE    0x01000000
#define SCE_KERNEL_ALLOC_MEMBLOCK_ATTR_ALLOW_PARTIAL_OP 0x04000000 // Allow partial operation. ?What does that mean?

/**
 * UID is created by sceKernelOpen***()
 */
#define SCE_UID_ATTR_OPEN_FLAG			0x00080000U

typedef struct SceKernelHeapInfo { // size is 0xCC on FW 0.990
	SceSize size;			// Size of this structure
	char unk_4[0xC8];
} SceKernelHeapInfo;

typedef struct SceKernelHeapObject { // size is 0x40 on FW 0.990
	SceSize size;				// Size of this structure
	uint32_t unk_4;				// 0x4
	uint32_t unk_8;				// 0x8
	uint32_t unk_C;				// 0xC
	uint32_t unk_10;			// 0x10
	uint32_t unk_14;			// 0x14
	uint32_t unk_18;			// 0x18
	uint32_t unk_1C;			// 0x1C
	uint32_t unk_20;			// 0x20
	uint32_t unk_24;			// 0x24
	uint32_t unk_28;			// 0x28
	uint32_t unk_2C;			// 0x2C
	uint32_t unk_30;			// 0x30
	uint32_t magic;				// 0x34 - 0xD2BBDEC3
	uint32_t unk_38;			// 0x38
	uint32_t unk_3C;			// 0x3C
	uint32_t unk_40;			// 0x40
} SceKernelHeapObject;

typedef struct SceKernelFixedHeap { // size is 0x40 on FW 0.990
	SceSize size;				// Size of this structure
	SceClass pClass;			// 0x4
	uint32_t unk_8;				// 0x8
	uint32_t unk_C;				// 0xC
	uint32_t unk_10;			// 0x10
	uint32_t unk_14;			// 0x14
	uint32_t pageSize;			// 0x18 - min 0x1000 on FW 0.990
	uint16_t itemSize;			// 0x1C
	uint16_t unk_1E;			// 0x1E
	uint32_t unk_20;			// 0x20
	uint32_t unk_24;			// 0x24
	uint32_t magic;				// 0x28 - 0xFD9B28A6
	uint16_t sizeInWords;			// 0x2C
	uint16_t index;				// 0x2E
	SceKernelHeapObject *heapObject;	// 0x30
	uint32_t unk_34;			// 0x34
	uint32_t unk_38;			// 0x38
	uint16_t unk_3C;			// 0x3C
} SceKernelFixedHeap;

typedef struct SceKernelFixedHeapInfo { // size is 0x14 on FW 0.990
	SceSize size;			// Size of this structure
	uint32_t unk_4;			// = (uint32_t)*(uint16_t *)(pObject + 0x1C)
	uint32_t unk_8;			// = *(uint32_t *)(pObject + 0x18) + (uint32_t)*(uint16_t *)(pObject + 0x2E)
	uint32_t unk_C;			// = (uint32_t)*(uint16_t *)(pObject + 0x1E)
	uint32_t unk_10;		// = (uint32_t)*(uint16_t *)(pObject + 0x20)
} SceKernelFixedHeapInfo;

typedef struct SceKernelHeapMemoryOpt { // size is 0x14 on FW 0.990
	SceSize size;			// Size of this structure
	uint32_t unk_4;
	SceSize alignment;		// ex: 0x10
	uint32_t unk_C;			// ex: 0x20
	uint32_t unk_10;
} SceKernelHeapMemoryOpt;

typedef struct SceAddressSpace { // size is at least 0xEC
	char unk[0x14];
	SceKernelMMUContext *context;
	char unk[0xC4];
	void *funcAlloc;
	char unk2[0x8];
	uint32_t magic;			// always 0x4d95AEEC
} SceAddressSpace;

typedef struct SceKernelAddressSpace { // size is 0x10 bytes on FW 0.940-3.60
    SceSize size; // Size of this structure
    int flag;
    void *data_0x08; // info dst buff ptr, need AddrSpace.flag  = 2;
    void *data_0x0C; // info dst buff ptr, need AddrSpace.flag |= 4;
} SceKernelAddressSpace;

typedef struct SceKernelVARange {
	uint32_t addr;
	SceSize size;
} SceKernelVARange;

typedef struct SceKernelPARange {
	uint32_t addr;
	SceSize size;
} SceKernelPARange;

typedef struct SceKernelPAVector { // size is 0x14 on FW 0.990
	SceSize size;			// Size of this structure
	uint32_t pRanges_size;		// Ex: 8
	uint32_t nDataInVector;		// Must be <= 8
	uint32_t count;
	SceKernelPARange *pRanges;
} SceKernelPAVector;

#define SCE_KERNEL_PROCESS_ID_SELF 0 // Current running process ID is always 0.

typedef struct SceKernelPhyMemPart { // size is at least 0x9C on FWs 0.931-3.60
	uint32_t field_0x0;
	uint32_t field_0x4;
	uint32_t some_counter; // always positive
	uint32_t field_0xc;
	char *name;
	int type; // 0x10000 for Lpddr2Main, 0x30000 for Cdram
	int mutex;
	uint32_t field_0x1c;
	SceSize totalSize;
	int field_0x24;
	void *pRoot;
	uint32_t field_0x2c;
	uint32_t field_0x30;
	uint32_t field_0x34;
	uint32_t field_0x38;
	int status;
	int pindex40; //1
	int field_0x44;
	int pindex48; //2
	int field_0x4c;
	int pindex50; //3
	int field_0x54;
	int pindex58; //4
	int field_0x5c;
	int pindex60; //5
	int field_0x64;
	int pindex68; //6
	int field_0x6c;
	int pindex70; //7
	int field_0x74;
	int pindex78; //8
	int field_0x7c;
	int pindex80; //9
	SceSize psize2;
	int min;
	int pindex8C; //10
	int field_0x90;
	SceUInt32 nClient;
	SceSize freeSize;
} SceKernelPhyMemPart;

typedef struct ScePhyMemPartInfoCore { // size is 0x10 on FWs 0.990-3.60
	SceUInt32 unk_0; // same as SceKernelPhyMemPart field 0x1C
	SceSize totalSize;
	SceSize freeSize;
	SceUInt32 unk_C; // maybe some counter
} ScePhyMemPartInfoCore;

/**
 * An enumeration to represent the various logging levels which can be output by sceDbgLoggingHandler().
 */
typedef enum SceDbgLogLevel {
	SCE_DBG_LOG_LEVEL_TRACE = 0, /* An extremely verbose logging level, mostly useful for internal developers. */
	SCE_DBG_LOG_LEVEL_DEBUG,     /* A diagnostic logging level. */
	SCE_DBG_LOG_LEVEL_INFO,      /* An informational logging level. */
	SCE_DBG_LOG_LEVEL_WARNING,   /* A logging level that gives warnings of situations detrimental to proper execution. */
	SCE_DBG_LOG_LEVEL_ERROR,     /* A logging level that will report erroneous conditions in execution. */
	SCE_DBG_NUM_LOG_LEVELS       /* The number of logging levels available. */
} SceDbgLogLevel;

/*
Target Manager (Communication Processor) Logging levels.
These levels can be set using psp2ctrl set-logging-level <level>.
LOG_LEVEL_NONE (0)
LOG_LEVEL_ERROR (1)
LOG_LEVEL_WARNING (2)
LOG_LEVEL_SERVICE (3)
LOG_LEVEL_INFO (4)
LOG_LEVEL_INTERNAL (5)
LOG_LEVEL_MAX (6)
*/

typedef struct SceSyscallInfo { // size is 0x3C on FW 3.60
	SceSize size; // Size of this structure
	SceUInt32 moduleFingerprint;
	SceUInt32 maybeModuleAttr;
	char moduleName[0x20];
	char *libName;
	SceUInt32 maybeLibAttr;
	SceUInt32 libVer;
	SceUInt32 libNid;
} SceSyscallInfo;

typedef struct SceSyscallFrame { // size is at least 0x5C on FW 3.60
	SceUInt32 r0; // 0x00
	SceUInt32 r1; // 0x04
	SceUInt32 r2; // 0x08
	SceUInt32 r3; // 0x0C
	SceUInt32 r4; // 0x10
	SceUInt32 r5; // 0x14
	SceUInt32 r6; // 0x18
	SceUInt32 r7; // 0x1C
	SceUInt32 r8; // 0x20
	SceUInt32 r9; // 0x24
	SceUInt32 r10; // 0x28
	SceUInt32 r11; // 0x2C
	SceUInt32 r12; // 0x30
	SceUInt32 unk_34; // 0x34
	void *entry; // 0x38
	SceUInt32 unk_3C; // 0x3C
	SceUInt32 resultType; // 0x40, 0-3
	int unk_44[3]; // 0x44
	SceUInt32 SP; // 0x50
	SceUInt32 LR; // 0x54
	SceUInt32 PC; // 0x58
} SceSyscallFrame;

// process
typedef struct SceKernelDebugEventLog1 { // size is 0x1C
	int data_0x40;
	SceUID pid;
	int budget_type;
	int data_0x4C;    // 0xA
	char titleid[0xC];
} __attribute__((packed)) SceKernelDebugEventLog1;

// Related to network
typedef struct SceKernelDebugEventLog2 { // size is 0x4
	int data_0x40;    // 0 or 0x80412118?
} __attribute__((packed)) SceKernelDebugEventLog2;

// Related to network
typedef struct SceKernelDebugEventLog3 { // size is 0x54
	int data_0x40;    // 0?
	char ip1[0x10];
	char ip2[0x10];
	char ip3[0x10];
	char ip4[0x10];
	char ip5[0x10];
} __attribute__((packed)) SceKernelDebugEventLog3;

typedef struct SceKernelDebugEventLog {
	SceSize size;
	int data_0x04;    // 0xA, titleid size?
	char titleid[0xC];
	int flags;
	SceUID ppid;
	SceUID data_0x1C; // thid?
	int rsvd[4];
	SceUInt64 time;
	int data_0x38;
	SceSize item_size;
	union {
		SceKernelDebugEventLog1 type1;
		SceKernelDebugEventLog2 type2;
		SceKernelDebugEventLog3 type3;
	};
} __attribute__((packed)) SceKernelDebugEventLog;