1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
#pragma once
#include <wiiu/types.h>
#include "time.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSThread OSThread;
typedef int (*OSThreadEntryPointFn)(int argc, const char **argv);
typedef void (*OSThreadCleanupCallbackFn)(OSThread *thread, void *stack);
typedef void (*OSThreadDeallocatorFn)(OSThread *thread, void *stack);
enum OS_THREAD_STATE
{
OS_THREAD_STATE_NONE = 0,
/*! Thread is ready to run */
OS_THREAD_STATE_READY = 1 << 0,
/*! Thread is running */
OS_THREAD_STATE_RUNNING = 1 << 1,
/*! Thread is waiting, i.e. on a mutex */
OS_THREAD_STATE_WAITING = 1 << 2,
/*! Thread is about to terminate */
OS_THREAD_STATE_MORIBUND = 1 << 3,
};
typedef uint8_t OSThreadState;
enum OS_THREAD_REQUEST
{
OS_THREAD_REQUEST_NONE = 0,
OS_THREAD_REQUEST_SUSPEND = 1,
OS_THREAD_REQUEST_CANCEL = 2,
};
typedef uint32_t OSThreadRequest;
enum OS_THREAD_ATTRIB
{
/*! Allow the thread to run on CPU0. */
OS_THREAD_ATTRIB_AFFINITY_CPU0 = 1 << 0,
/*! Allow the thread to run on CPU1. */
OS_THREAD_ATTRIB_AFFINITY_CPU1 = 1 << 1,
/*! Allow the thread to run on CPU2. */
OS_THREAD_ATTRIB_AFFINITY_CPU2 = 1 << 2,
/*! Allow the thread to run any CPU. */
OS_THREAD_ATTRIB_AFFINITY_ANY = ((1 << 0) | (1 << 1) | (1 << 2)),
/*! Start the thread detached. */
OS_THREAD_ATTRIB_DETACHED = 1 << 3,
/*! Enables tracking of stack usage. */
OS_THREAD_ATTRIB_STACK_USAGE = 1 << 5
};
typedef uint8_t OSThreadAttributes;
#define OS_CONTEXT_TAG 0x4F53436F6E747874ull
typedef struct OSContext
{
/*! Should always be set to the value OS_CONTEXT_TAG. */
uint64_t tag;
uint32_t gpr[32];
uint32_t cr;
uint32_t lr;
uint32_t ctr;
uint32_t xer;
uint32_t srr0;
uint32_t srr1;
uint32_t __unknown[0x5];
uint32_t fpscr;
double fpr[32];
uint16_t spinLockCount;
uint16_t state;
uint32_t gqr[8];
uint32_t __unknown0;
double psf[32];
uint64_t coretime[3];
uint64_t starttime;
uint32_t error;
uint32_t __unknown1;
uint32_t pmc1;
uint32_t pmc2;
uint32_t pmc3;
uint32_t pmc4;
uint32_t mmcr0;
uint32_t mmcr1;
} OSContext;
typedef struct OSMutex OSMutex;
typedef struct OSFastMutex OSFastMutex;
typedef struct OSMutexQueue
{
OSMutex *head;
OSMutex *tail;
void *parent;
uint32_t __unknown;
} OSMutexQueue;
typedef struct OSFastMutexQueue
{
OSFastMutex *head;
OSFastMutex *tail;
} OSFastMutexQueue;
typedef struct
{
OSThread *prev;
OSThread *next;
} OSThreadLink;
typedef struct
{
OSThread *head;
OSThread *tail;
void *parent;
uint32_t __unknown;
} OSThreadQueue;
typedef struct
{
OSThread *head;
OSThread *tail;
} OSThreadSimpleQueue;
#define OS_THREAD_TAG 0x74487244u
#pragma pack(push, 1)
typedef struct __attribute__ ((aligned (8))) OSThread
{
OSContext context;
/*! Should always be set to the value OS_THREAD_TAG. */
uint32_t tag;
/*! Bitfield of OS_THREAD_STATE */
OSThreadState state;
/*! Bitfield of OS_THREAD_ATTRIB */
OSThreadAttributes attr;
/*! Unique thread ID */
uint16_t id;
/*! Suspend count (increased by OSSuspendThread). */
int32_t suspendCounter;
/*! Actual priority of thread. */
int32_t priority;
/*! Base priority of thread, 0 is highest priority, 31 is lowest priority. */
int32_t basePriority;
/*! Exit value */
int32_t exitValue;
uint32_t unknown0[0x9];
/*! Queue the thread is currently waiting on */
OSThreadQueue *queue;
/*! Link used for thread queue */
OSThreadLink link;
/*! Queue of threads waiting to join this thread */
OSThreadQueue joinQueue;
/*! Mutex this thread is waiting to lock */
OSMutex *mutex;
/*! Queue of mutexes this thread owns */
OSMutexQueue mutexQueue;
/*! Link for global active thread queue */
OSThreadLink activeLink;
/*! Stack start (top, highest address) */
void *stackStart;
/*! Stack end (bottom, lowest address) */
void *stackEnd;
/*! Thread entry point */
OSThreadEntryPointFn entryPoint;
uint32_t unknown1[0x77];
/*! Thread specific values, accessed with OSSetThreadSpecific and OSGetThreadSpecific. */
uint32_t specific[0x10];
uint32_t unknown2;
/*! Thread name, accessed with OSSetThreadName and OSGetThreadName. */
const char *name;
uint32_t unknown3;
/*! The stack pointer passed in OSCreateThread. */
void *userStackPointer;
/*! Called just before thread is terminated, set with OSSetThreadCleanupCallback */
OSThreadCleanupCallbackFn cleanupCallback;
/*! Called just after a thread is terminated, set with OSSetThreadDeallocator */
OSThreadDeallocatorFn deallocator;
/*! If TRUE then a thread can be cancelled or suspended, set with OSSetThreadCancelState */
BOOL cancelState;
/*! Current thread request, used for cancelleing and suspending the thread. */
OSThreadRequest requestFlag;
/*! Pending suspend request count */
int32_t needSuspend;
/*! Result of thread suspend */
int32_t suspendResult;
/*! Queue of threads waiting for a thread to be suspended. */
OSThreadQueue suspendQueue;
uint32_t unknown4[0x2B];
} OSThread;
#pragma pack(pop)
void
OSCancelThread(OSThread *thread);
int32_t OSCheckActiveThreads();
int32_t OSCheckThreadStackUsage(OSThread *thread);
void OSClearThreadStackUsage(OSThread *thread);
void OSContinueThread(OSThread *thread);
BOOL OSCreateThread(OSThread *thread, OSThreadEntryPointFn entry, int32_t argc, char *argv,
void *stack, uint32_t stackSize, int32_t priority, OSThreadAttributes attributes);
void OSDetachThread(OSThread *thread);
void OSExitThread(int32_t result);
void OSGetActiveThreadLink(OSThread *thread, OSThreadLink *link);
OSThread *OSGetCurrentThread();
OSThread *OSGetDefaultThread(uint32_t coreID);
uint32_t OSGetStackPointer();
uint32_t OSGetThreadAffinity(OSThread *thread);
const char *OSGetThreadName(OSThread *thread);
int32_t OSGetThreadPriority(OSThread *thread);
uint32_t OSGetThreadSpecific(uint32_t id);
BOOL OSIsThreadSuspended(OSThread *thread);
BOOL OSIsThreadTerminated(OSThread *thread);
BOOL OSJoinThread(OSThread *thread, int *threadResult);
int32_t OSResumeThread(OSThread *thread);
BOOL OSRunThread(OSThread *thread, OSThreadEntryPointFn entry, int argc, const char **argv);
BOOL OSSetThreadAffinity(OSThread *thread, uint32_t affinity);
BOOL OSSetThreadCancelState(BOOL state);
OSThreadCleanupCallbackFn OSSetThreadCleanupCallback(OSThread *thread,
OSThreadCleanupCallbackFn callback);
OSThreadDeallocatorFn OSSetThreadDeallocator(OSThread *thread, OSThreadDeallocatorFn deallocator);
void OSSetThreadName(OSThread *thread, const char *name);
BOOL OSSetThreadPriority(OSThread *thread, int32_t priority);
BOOL OSSetThreadRunQuantum(OSThread *thread, uint32_t quantum);
void OSSetThreadSpecific(uint32_t id, uint32_t value);
BOOL OSSetThreadStackUsage(OSThread *thread);
void OSSleepThread(OSThreadQueue *queue);
void OSSleepTicks(OSTime ticks);
uint32_t OSSuspendThread(OSThread *thread);
void OSTestThreadCancel();
void OSWakeupThread(OSThreadQueue *queue);
void OSYieldThread();
void OSInitThreadQueue(OSThreadQueue *queue);
void OSInitThreadQueueEx(OSThreadQueue *queue, void *parent);
#ifdef __cplusplus
}
#endif
|