summaryrefslogtreecommitdiff
path: root/include/kernel/kernel/threadmgr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/kernel/kernel/threadmgr.h')
-rw-r--r--include/kernel/kernel/threadmgr.h274
1 files changed, 257 insertions, 17 deletions
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