Merge pull request #328 from GrayJack/load-core

refactor: Update `SceModule` definition
This commit is contained in:
Wouter Wijsman
2025-09-15 23:00:46 +02:00
committed by GitHub
3 changed files with 201 additions and 58 deletions

View File

@@ -427,6 +427,9 @@ typedef struct ScePspDateTime {
unsigned int microsecond;
} ScePspDateTime;
/* Thread entry function type. */
typedef int (*SceKernelThreadEntry)(SceSize args, void *argp);
#ifdef __cplusplus
}
#endif

View File

@@ -26,32 +26,174 @@ extern "C" {
/** @addtogroup LoadCore Interface to the LoadCoreForKernel library. */
/**@{*/
/** Describes a module. This structure could change in future firmware revisions. */
/** Reboot preparation functions */
typedef s32 (*SceKernelRebootBeforeForKernel)(void *arg1, s32 arg2, s32 arg3, s32 arg4);
typedef s32 (*SceKernelRebootPhaseForKernel)(s32 arg1, void *arg2, s32 arg3, s32 arg4);
/** Module type attributes. */
enum SceModuleAttribute {
/** No module attributes. */
SCE_MODULE_ATTR_NONE = 0x0000,
/** Resident module - stays in memory. You cannot unload such a module. */
SCE_MODULE_ATTR_CANT_STOP = 0x0001,
/**
* Only one instance of the module (one version) can be loaded into the system. If you want to load another
* version of that module, you have to delete the loaded version first.
*/
SCE_MODULE_ATTR_EXCLUSIVE_LOAD = 0x0002,
/**
* Only one instance of the module (one version) can be started. If you want to start another
* version of that module, you have to stop the currently running version first.
*/
SCE_MODULE_ATTR_EXCLUSIVE_START = 0x0004,
};
/**
* Module Privilege Levels - These levels define the permissions a
* module can have.
*/
enum SceModulePrivilegeLevel {
/** Lowest permission. */
SCE_MODULE_USER = 0x0000,
/** POPS/Demo. */
SCE_MODULE_MS = 0x0200,
/** Module Gamesharing. */
SCE_MODULE_USB_WLAN = 0x0400,
/** Application module. */
SCE_MODULE_APP = 0x0600,
/** VSH module. */
SCE_MODULE_VSH = 0x0800,
/** Highest permission. */
SCE_MODULE_KERNEL = 0x1000,
/** The module uses KIRK's memlmd resident library. */
SCE_MODULE_KIRK_MEMLMD_LIB = 0x2000,
/** The module uses KIRK's semaphore resident library. */
SCE_MODULE_KIRK_SEMAPHORE_LIB = 0x4000,
};
/** Describes a loaded module in memory. This structure could change in future firmware revisions. */
typedef struct SceModule {
struct SceModule *next;
unsigned short attribute;
unsigned char version[2];
char modname[27];
char terminal;
unsigned int unknown1;
unsigned int unknown2;
SceUID modid;
unsigned int unknown3[4];
void * ent_top;
unsigned int ent_size;
void * stub_top;
unsigned int stub_size;
unsigned int unknown4[4];
unsigned int entry_addr;
unsigned int gp_value;
unsigned int text_addr;
unsigned int text_size;
unsigned int data_size;
unsigned int bss_size;
unsigned int nsegment;
unsigned int segmentaddr[4];
unsigned int segmentsize[4];
} __attribute__((packed)) SceModule;
/** Pointer to the next registered module. Modules are connected via a linked list. */
struct SceModule *next;
/** The attributes of a module. One or more of ::SceModuleAttribute and ::SceModulePrivilegeLevel. */
u16 attribute;
/**
* The version of the module. Consists of a major and minor part. There can be several modules
* loaded with the same name and version.
*/
u8 version[2];
/** The module's name. There can be several modules loaded with the same name. */
char modname[27];
/** String terminator (always '\0'). */
char terminal;
/**
* The status of the module. Contains information whether the module has been started, stopped,
* is a user module, etc.
*/
u16 mod_state;
char padding[2];
/** A secondary ID for the module. */
SceUID sec_id;
/** The module's UID. */
SceUID modid;
/** The thread ID of a user module. */
SceUID user_mod_thid;
/** The ID of the memory block belonging to the module. */
SceUID mem_id;
/** The ID of the TEXT segment's memory partition. */
u32 mpid_text;
/** The ID of the DATA segment's memory partition. */
u32 mpid_data;
/** Pointer to the first resident library entry table of the module. */
void * ent_top;
/** The size of all resident library entry tables of the module. */
SceSize ent_size;
/** Pointer to the first stub library entry table of the module. */
void * stub_top;
/** The size of all stub library entry tables of the module. */
SceSize stub_size;
/**
* A pointer to the (required) module's start entry function. This function is executed during
* the module's startup.
*/
SceKernelThreadEntry module_start;
/**
* A pointer to the (required) module's stop entry function. This function is executed during
* the module's stopping phase.
*/
SceKernelThreadEntry module_stop;
/**
* A pointer to a module's Bootstart entry function. This function is probably executed after
* a reboot.
*/
SceKernelThreadEntry module_bootstart;
/**
* A pointer to a module's rebootBefore entry function. This function is probably executed
* before a reboot.
*/
SceKernelRebootBeforeForKernel module_reboot_before;
/**
* A pointer to a module's rebootPhase entry function. This function is probably executed
* during a reboot.
*/
SceKernelRebootPhaseForKernel module_reboot_phase;
/**
* The entry address of the module. It is the offset from the start of the TEXT segment to the
* program's entry point.
*/
u32 entry_addr;
/** Contains the offset from the start of the TEXT segment of the program's GP register value. */
u32 gp_value;
/** The start address of the TEXT segment. */
u32 text_addr;
/** The size of the TEXT segment. */
u32 text_size;
/** The size of the DATA segment. */
u32 data_size;
/** The size of the BSS segment. */
u32 bss_size;
/** The number of segments the module consists of. */
u8 nsegment;
/** Reserved. */
u8 padding2[3];
/** An array containing the start address of each segment. */
u32 segmentaddr[4];
/** An array containing the size of each segment. */
SceSize segmentsize[4];
/** An array containing the alignment information of each segment. */
u32 segmentalign[4];
/** The priority of the module start thread. */
s32 module_start_thread_priority;
/** The stack size of the module start thread. */
SceSize module_start_thread_stacksize;
/** The attributes of the module start thread. */
SceUInt module_start_thread_attr;
/** The priority of the module stop thread. */
s32 module_stop_thread_priority;
/** The stack size of the module stop thread. */
SceSize module_stop_thread_stacksize;
/** The attributes of the module stop thread. */
SceUInt module_stop_thread_attr;
/** The priority of the module reboot before thread. */
s32 module_reboot_before_thread_priority;
/** The stack size of the module reboot before thread. */
SceSize module_reboot_before_thread_stacksize;
/** The attributes of the module reboot before thread. */
SceUInt module_reboot_before_thread_attr;
/** The value of the coprocessor 0's count register when the module is created. */
u32 count_reg_val;
/** The segment checksum of the module's segments. */
u32 segment_checksum;
/** TEXT segment checksum of the module. */
u32 text_segment_checksum;
/**
* Whether to compute the text segment checksum before starting the module (see prologue).
* If non-zero, the text segment checksum will be computed after the module's resident libraries
* have been registered, and its stub libraries have been linked.
*/
u32 compute_text_segment_checksum;
} SceModule;
/** Defines a library and its exported functions and variables. Use the len
member to determine the real size of the table (size = len * 4). */

View File

@@ -46,7 +46,7 @@ enum PspThreadAttributes
{
/** Enable VFPU access for the thread. */
PSP_THREAD_ATTR_VFPU = 0x00004000,
/** Start the thread in user mode (done automatically
/** Start the thread in user mode (done automatically
if the thread creating it is in user mode). */
PSP_THREAD_ATTR_USER = 0x80000000,
/** Thread is part of the USB/WLAN API. */
@@ -68,8 +68,6 @@ enum PspThreadAttributes
/* Threads. */
typedef int (*SceKernelThreadEntry)(SceSize args, void *argp);
/** Additional options used when creating threads. */
typedef struct SceKernelThreadOptParam {
/** Size of the ::SceKernelThreadOptParam structure. */
@@ -193,7 +191,7 @@ int sceKernelStartThread(SceUID thid, SceSize arglen, void *argp);
*/
int sceKernelExitThread(int status);
/**
/**
* Exit a thread and delete itself.
*
* @param status - Exit status
@@ -228,7 +226,7 @@ int sceKernelSuspendDispatchThread(void);
/**
* Resume the dispatch thread
*
* @param state - The state of the dispatch thread
* @param state - The state of the dispatch thread
* (from ::sceKernelSuspendDispatchThread)
*
* @return 0 on success, < 0 on error
@@ -289,7 +287,7 @@ int sceKernelSuspendThread(SceUID thid);
*/
int sceKernelResumeThread(SceUID thid);
/**
/**
* Wait until a thread has ended.
*
* @param thid - Id of the thread to wait for.
@@ -299,7 +297,7 @@ int sceKernelResumeThread(SceUID thid);
*/
int sceKernelWaitThreadEnd(SceUID thid, SceUInt *timeout);
/**
/**
* Wait until a thread has ended and handle callbacks if necessary.
*
* @param thid - Id of the thread to wait for.
@@ -364,7 +362,7 @@ int sceKernelChangeCurrentThreadAttr(int unknown, SceUInt attr);
/**
* Change the threads current priority.
*
*
* @param thid - The ID of the thread (from sceKernelCreateThread or sceKernelGetThreadId)
* @param priority - The new priority (the lower the number the higher the priority)
*
@@ -383,7 +381,7 @@ int sceKernelChangeThreadPriority(SceUID thid, int priority);
* Rotate thread ready queue at a set priority
*
* @param priority - The priority of the queue
*
*
* @return 0 on success, < 0 on error.
*/
int sceKernelRotateThreadReadyQueue(int priority);
@@ -397,7 +395,7 @@ int sceKernelRotateThreadReadyQueue(int priority);
*/
int sceKernelReleaseWaitThread(SceUID thid);
/**
/**
* Get the current thread Id
*
* @return The thread id of the calling thread.
@@ -437,9 +435,9 @@ int sceKernelCheckThreadStack(void);
*/
int sceKernelGetThreadStackFreeSize(SceUID thid);
/**
/**
* Get the status information for the specified thread.
*
*
* @param thid - Id of the thread to get status
* @param info - Pointer to the info structure to receive the data.
* Note: The structures size field should be set to
@@ -451,7 +449,7 @@ int sceKernelGetThreadStackFreeSize(SceUID thid);
* status.size = sizeof(SceKernelThreadInfo);
* if(sceKernelReferThreadStatus(thid, &status) == 0)
* { Do something... }
* @endcode
* @endcode
* @return 0 if successful, otherwise the error code.
*/
int sceKernelReferThreadStatus(SceUID thid, SceKernelThreadInfo *info);
@@ -506,7 +504,7 @@ typedef struct SceKernelSemaInfo {
*
* @param name - Specifies the name of the sema
* @param attr - Sema attribute flags (normally set to 0)
* @param initVal - Sema initial value
* @param initVal - Sema initial value
* @param maxVal - Sema maximum value
* @param option - Sema options (normally set to 0)
* @return A semaphore id
@@ -707,7 +705,7 @@ enum PspEventFlagWaitTypes
PSP_EVENT_WAITCLEAR = 0x20
};
/**
/**
* Create an event flag.
*
* @param name - The name of the event flag.
@@ -724,7 +722,7 @@ enum PspEventFlagWaitTypes
*/
SceUID sceKernelCreateEventFlag(const char *name, int attr, int bits, SceKernelEventFlagOptParam *opt);
/**
/**
* Set an event flag bit pattern.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
@@ -744,7 +742,7 @@ int sceKernelSetEventFlag(SceUID evid, u32 bits);
*/
int sceKernelClearEventFlag(SceUID evid, u32 bits);
/**
/**
* Poll an event flag for a given bit pattern.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
@@ -755,7 +753,7 @@ int sceKernelClearEventFlag(SceUID evid, u32 bits);
*/
int sceKernelPollEventFlag(int evid, u32 bits, u32 wait, u32 *outBits);
/**
/**
* Wait for an event flag for a given bit pattern.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
@@ -767,7 +765,7 @@ int sceKernelPollEventFlag(int evid, u32 bits, u32 wait, u32 *outBits);
*/
int sceKernelWaitEventFlag(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
/**
/**
* Wait for an event flag for a given bit pattern with callback.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
@@ -779,7 +777,7 @@ int sceKernelWaitEventFlag(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *
*/
int sceKernelWaitEventFlagCB(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
/**
/**
* Delete an event flag
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
@@ -788,9 +786,9 @@ int sceKernelWaitEventFlagCB(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt
*/
int sceKernelDeleteEventFlag(int evid);
/**
/**
* Get the status of an event flag.
*
*
* @param event - The UID of the event.
* @param status - A pointer to a ::SceKernelEventFlagInfo structure.
*
@@ -878,7 +876,7 @@ int sceKernelDeleteMbx(SceUID mbxid);
*
* @param mbxid - The mbx id returned from sceKernelCreateMbx
* @param message - A message to be forwarded to the receiver.
* The start of the message should be the
* The start of the message should be the
* ::SceKernelMsgPacket structure, the rest
*
* @return < 0 On error.
@@ -984,7 +982,7 @@ typedef struct SceKernelAlarmInfo {
void * common;
} SceKernelAlarmInfo;
/**
/**
* Set an alarm.
* @param clock - The number of micro seconds till the alarm occurrs.
* @param handler - Pointer to a ::SceKernelAlarmHandler
@@ -996,11 +994,11 @@ SceUID sceKernelSetAlarm(SceUInt clock, SceKernelAlarmHandler handler, void *com
/**
* Set an alarm using a ::SceKernelSysClock structure for the time
*
*
* @param clock - Pointer to a ::SceKernelSysClock structure
* @param handler - Pointer to a ::SceKernelAlarmHandler
* @param common - Common pointer for the alarm handler.
*
*
* @return A UID representing the created alarm, < 0 on error.
*/
SceUID sceKernelSetSysClockAlarm(SceKernelSysClock *clock, SceKernelAlarmHandler handler, void *common);
@@ -1142,7 +1140,7 @@ enum SceKernelIdListType
};
/**
* Get a list of UIDs from threadman. Allows you to enumerate
* Get a list of UIDs from threadman. Allows you to enumerate
* resources such as threads or semaphores.
*
* @param type - The type of resource to list, one of ::SceKernelIdListType.
@@ -1305,7 +1303,7 @@ typedef struct SceKernelMppInfo {
int numSendWaitThreads;
int numReceiveWaitThreads;
} SceKernelMppInfo;
/**
* Get the status of a Message Pipe
*
@@ -1369,7 +1367,7 @@ int sceKernelAllocateVpl(SceUID uid, unsigned int size, void **data, unsigned in
int sceKernelAllocateVplCB(SceUID uid, unsigned int size, void **data, unsigned int *timeout);
/**
* Try to allocate from the pool
* Try to allocate from the pool
*
* @param uid - The UID of the pool
* @param size - The size to allocate
@@ -1471,7 +1469,7 @@ int sceKernelAllocateFpl(SceUID uid, void **data, unsigned int *timeout);
int sceKernelAllocateFplCB(SceUID uid, void **data, unsigned int *timeout);
/**
* Try to allocate from the pool
* Try to allocate from the pool
*
* @param uid - The UID of the pool
* @param data - Receives the address of the allocated data
@@ -1527,7 +1525,7 @@ int sceKernelReferFplStatus(SceUID uid, SceKernelFplInfo *info);
void _sceKernelReturnFromTimerHandler(void);
/**
* Return from a callback (used as a syscall for the return
* Return from a callback (used as a syscall for the return
* of the callback function)
*/
void _sceKernelReturnFromCallback(void);
@@ -1544,7 +1542,7 @@ int sceKernelUSec2SysClock(unsigned int usec, SceKernelSysClock *clock);
/**
* Convert a number of microseconds to a wide time
*
*
* @param usec - Number of microseconds.
*
* @return The time
@@ -1762,7 +1760,7 @@ void _sceKernelExitThread(void);
* Get the type of a threadman uid
*
* @param uid - The uid to get the type from
*
*
* @return The type, < 0 on error
*/
enum SceKernelIdListType sceKernelGetThreadmanIdType(SceUID uid);