wut v1.9.1
Wii U Toolchain
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1#pragma once
2#include <wut.h>
3#include <time.h>
4#include "alarm.h"
5#include "context.h"
6#include "exception.h"
7#include "threadqueue.h"
8#include "time.h"
9
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36typedef struct OSFastMutex OSFastMutex;
38typedef struct OSMutex OSMutex;
40typedef struct OSThread OSThread;
43
45typedef uint8_t OSThreadState;
46
48typedef uint32_t OSThreadRequest;
49
51typedef uint8_t OSThreadAttributes;
52
54typedef uint32_t OSThreadType;
55
56typedef int (*OSThreadEntryPointFn)(int argc, const char **argv);
57typedef void (*OSThreadCleanupCallbackFn)(OSThread *thread, void *stack);
58typedef void (*OSThreadDeallocatorFn)(OSThread *thread, void *stack);
59
81
98
105
128
135
137{
138 WUT_UNKNOWN_BYTES(0x68);
140 void *eh_mem_manage[9];
141 void *eh_store_globals[6];
142 void *eh_store_globals_tdeh[76];
143};
144WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0x68, eh_globals);
145WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0x6c, eh_mem_manage);
146WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0x90, eh_store_globals);
147WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0xa8, eh_store_globals_tdeh);
148WUT_CHECK_SIZE(OSThreadGHSExceptionHandling, 0x1d8);
149
151{
154 void *parent;
155 WUT_UNKNOWN_BYTES(4);
156};
157WUT_CHECK_OFFSET(OSMutexQueue, 0x0, head);
158WUT_CHECK_OFFSET(OSMutexQueue, 0x4, tail);
159WUT_CHECK_OFFSET(OSMutexQueue, 0x8, parent);
160WUT_CHECK_SIZE(OSMutexQueue, 0x10);
161
167WUT_CHECK_OFFSET(OSFastMutexQueue, 0x00, head);
168WUT_CHECK_OFFSET(OSFastMutexQueue, 0x04, tail);
169WUT_CHECK_SIZE(OSFastMutexQueue, 0x08);
170
172{
173 void *data;
174 WUT_UNKNOWN_BYTES(4);
175};
176WUT_CHECK_OFFSET(OSTLSSection, 0x00, data);
177WUT_CHECK_SIZE(OSTLSSection, 0x08);
178
179#define OS_THREAD_TAG 0x74487244u
180#pragma pack(push, 1)
181struct WUT_ALIGNAS(8) OSThread
182{
184
186 uint32_t tag;
187
190
193
195 uint16_t id;
196
199
201 int32_t priority;
202
205
207 int32_t exitValue;
208
210 OSThreadQueue *coreRunQueue[3];
211 OSThreadLink coreRunQueueLink[3];
212
215
218
221
224
227
230
233
235 void *stackEnd;
236
239
242
244
246 void *specific[0x10];
247
249
251 const char *name;
252
254
257
260
263
266
269
271 int32_t needSuspend;
272
275
278
279 WUT_UNKNOWN_BYTES(0x4);
280
283
286
288 uint64_t wakeCount;
289
294
296 OSExceptionCallbackFn dsiCallback[3];
298 OSExceptionCallbackFn isiCallback[3];
300 OSExceptionCallbackFn programCallback[3];
302 OSExceptionCallbackFn perfMonCallback[3];
303
306
309
310 WUT_UNKNOWN_BYTES(0x2);
311
314
317
320
323
325 OSExceptionCallbackFn alignCallback[3];
326
328 uint32_t reserved[5];
329};
330#pragma pack(pop)
331WUT_CHECK_OFFSET(OSThread, 0x320, tag);
332WUT_CHECK_OFFSET(OSThread, 0x324, state);
333WUT_CHECK_OFFSET(OSThread, 0x325, attr);
334WUT_CHECK_OFFSET(OSThread, 0x326, id);
335WUT_CHECK_OFFSET(OSThread, 0x328, suspendCounter);
336WUT_CHECK_OFFSET(OSThread, 0x32c, priority);
337WUT_CHECK_OFFSET(OSThread, 0x330, basePriority);
338WUT_CHECK_OFFSET(OSThread, 0x334, exitValue);
339WUT_CHECK_OFFSET(OSThread, 0x338, coreRunQueue);
340WUT_CHECK_OFFSET(OSThread, 0x344, coreRunQueueLink);
341WUT_CHECK_OFFSET(OSThread, 0x35c, queue);
342WUT_CHECK_OFFSET(OSThread, 0x360, link);
343WUT_CHECK_OFFSET(OSThread, 0x368, joinQueue);
344WUT_CHECK_OFFSET(OSThread, 0x378, mutex);
345WUT_CHECK_OFFSET(OSThread, 0x37c, mutexQueue);
346WUT_CHECK_OFFSET(OSThread, 0x38c, activeLink);
347WUT_CHECK_OFFSET(OSThread, 0x394, stackStart);
348WUT_CHECK_OFFSET(OSThread, 0x398, stackEnd);
349WUT_CHECK_OFFSET(OSThread, 0x39c, entryPoint);
350WUT_CHECK_OFFSET(OSThread, 0x3a0, ghsExceptionHandling);
351WUT_CHECK_OFFSET(OSThread, 0x57c, specific);
352WUT_CHECK_OFFSET(OSThread, 0x5bc, type);
353WUT_CHECK_OFFSET(OSThread, 0x5c0, name);
354WUT_CHECK_OFFSET(OSThread, 0x5c4, waitEventTimeoutAlarm);
355WUT_CHECK_OFFSET(OSThread, 0x5c8, userStackPointer);
356WUT_CHECK_OFFSET(OSThread, 0x5cc, cleanupCallback);
357WUT_CHECK_OFFSET(OSThread, 0x5d0, deallocator);
358WUT_CHECK_OFFSET(OSThread, 0x5d4, cancelState);
359WUT_CHECK_OFFSET(OSThread, 0x5d8, requestFlag);
360WUT_CHECK_OFFSET(OSThread, 0x5dc, needSuspend);
361WUT_CHECK_OFFSET(OSThread, 0x5e0, suspendResult);
362WUT_CHECK_OFFSET(OSThread, 0x5e4, suspendQueue);
363WUT_CHECK_OFFSET(OSThread, 0x5f8, runQuantumTicks);
364WUT_CHECK_OFFSET(OSThread, 0x600, coreTimeConsumedNs);
365WUT_CHECK_OFFSET(OSThread, 0x608, wakeCount);
366WUT_CHECK_OFFSET(OSThread, 0x610, unk0x610);
367WUT_CHECK_OFFSET(OSThread, 0x618, unk0x618);
368WUT_CHECK_OFFSET(OSThread, 0x620, unk0x620);
369WUT_CHECK_OFFSET(OSThread, 0x628, unk0x628);
370WUT_CHECK_OFFSET(OSThread, 0x630, dsiCallback);
371WUT_CHECK_OFFSET(OSThread, 0x63c, isiCallback);
372WUT_CHECK_OFFSET(OSThread, 0x648, programCallback);
373WUT_CHECK_OFFSET(OSThread, 0x654, perfMonCallback);
374WUT_CHECK_OFFSET(OSThread, 0x664, tlsSectionCount);
375WUT_CHECK_OFFSET(OSThread, 0x668, tlsSections);
376WUT_CHECK_OFFSET(OSThread, 0x66c, fastMutex);
377WUT_CHECK_OFFSET(OSThread, 0x670, contendedFastMutexes);
378WUT_CHECK_OFFSET(OSThread, 0x678, fastMutexQueue);
379WUT_CHECK_OFFSET(OSThread, 0x680, alignCallback);
380WUT_CHECK_OFFSET(OSThread, 0x68c, reserved);
381WUT_CHECK_SIZE(OSThread, 0x6a0);
382
389void
391
392
396int32_t
398
399
403int32_t
405
406
410void
412
413
417void
419
420
433BOOL
436 int32_t argc,
437 char *argv,
438 void *stack,
439 uint32_t stackSize,
440 int32_t priority,
441 OSThreadAttributes attributes);
442
443
447void
449
450
456void
457OSExitThread(int32_t result);
458
459
463void
465 OSThreadLink *link);
466
467
471OSThread *
473
474
482OSThread *
483OSGetDefaultThread(uint32_t coreID);
484
485
489uint32_t
491
492
496uint32_t
498
499
503const char *
505
506
510int32_t
512
513
517void *
519
520
524BOOL
526
527
531BOOL
533
534
544BOOL
546 int *threadResult);
547
548
557int32_t
559
560
566BOOL
569 int argc,
570 const char **argv);
571
572
576BOOL
578 uint32_t affinity);
579
580
587BOOL
589
590
597
598
604 OSThreadDeallocatorFn deallocator);
605
606
610void
612 const char *name);
613
614
618BOOL
620 int32_t priority);
621
622
629BOOL
631 uint32_t quantum);
632
638void
640 void *value);
641
642
646BOOL
648
649
655void
657
658
662void
664
665
674uint32_t
676
677void
679
693void
695
696
702void
704
705
712void
714
715
716#ifdef __cplusplus
717}
718#endif
719
BOOL(* OSExceptionCallbackFn)(OSContext *context)
Definition exception.h:15
OSThreadLink activeLink
Link for global active thread queue.
Definition thread.h:229
OSFastMutexQueue contendedFastMutexes
The fast mutexes we are currently contended on.
Definition thread.h:319
OSMutex * head
Definition thread.h:152
uint64_t coreTimeConsumedNs
The total amount of core time consumed by this thread (Does not include time while Running)
Definition thread.h:285
OSThreadAttributes attr
Bitfield of OS_THREAD_ATTRIB.
Definition thread.h:192
OSFastMutex * tail
Definition thread.h:165
OSThreadState state
Bitfield of OS_THREAD_STATE.
Definition thread.h:189
OSMutexQueue mutexQueue
Queue of mutexes this thread owns.
Definition thread.h:226
OSTime unk0x620
Definition thread.h:292
uint32_t tag
Should always be set to the value OS_THREAD_TAG.
Definition thread.h:186
OSFastMutex * fastMutex
The fast mutex we are currently waiting for.
Definition thread.h:316
void * userStackPointer
The stack pointer passed in OSCreateThread.
Definition thread.h:256
OSTLSSection * tlsSections
TLS Sections.
Definition thread.h:313
OSThreadDeallocatorFn deallocator
Called just after a thread is terminated, set with OSSetThreadDeallocator.
Definition thread.h:262
BOOL alarmCancelled
Definition thread.h:243
OSThreadGHSExceptionHandling ghsExceptionHandling
GHS Exception handling thread-specifics.
Definition thread.h:241
int32_t needSuspend
Pending suspend request count.
Definition thread.h:271
int32_t priority
Actual priority of thread.
Definition thread.h:201
OSTime unk0x618
Definition thread.h:291
uint16_t id
Unique thread ID.
Definition thread.h:195
OSThreadEntryPointFn entryPoint
Thread entry point.
Definition thread.h:238
OSAlarm * waitEventTimeoutAlarm
Definition thread.h:253
uint64_t wakeCount
The number of times this thread has been awoken.
Definition thread.h:288
void * parent
Definition thread.h:154
OSMutex * tail
Definition thread.h:153
int32_t basePriority
Base priority of thread, 0 is highest priority, 31 is lowest priority.
Definition thread.h:204
void * data
Definition thread.h:173
OSMutex * mutex
Mutex this thread is waiting to lock.
Definition thread.h:223
const char * name
Thread name, accessed with OSSetThreadName and OSGetThreadName.
Definition thread.h:251
OSTime unk0x610
Definition thread.h:290
uint16_t tlsSectionCount
Number of TLS sections.
Definition thread.h:308
OSThreadRequest requestFlag
Current thread request, used for cancelleing and suspending the thread.
Definition thread.h:268
OSTime unk0x628
Definition thread.h:293
BOOL cancelState
If TRUE then a thread can be cancelled or suspended, set with OSSetThreadCancelState.
Definition thread.h:265
int32_t exitValue
Exit value.
Definition thread.h:207
OSThreadQueue * queue
Queue the thread is currently waiting on.
Definition thread.h:214
OSContext context
Definition thread.h:183
int32_t suspendCounter
Suspend count (increased by OSSuspendThread).
Definition thread.h:198
OSThreadQueue suspendQueue
Queue of threads waiting for a thread to be suspended.
Definition thread.h:277
int32_t suspendResult
Result of thread suspend.
Definition thread.h:274
int64_t runQuantumTicks
How many ticks the thread should run for before suspension.
Definition thread.h:282
void * stackStart
Stack start (top, highest address)
Definition thread.h:232
OSThreadCleanupCallbackFn cleanupCallback
Called just before thread is terminated, set with OSSetThreadCleanupCallback.
Definition thread.h:259
BOOL stackSyncObjAllowed
Checks for synchronization objects placed on stack in debug mode when set to true.
Definition thread.h:305
OSFastMutex * head
Definition thread.h:164
OSThreadType type
Definition thread.h:248
OSThreadQueue joinQueue
Queue of threads waiting to join this thread.
Definition thread.h:220
OSFastMutexQueue fastMutexQueue
The fast mutexes we currently own locks on.
Definition thread.h:322
OSThreadLink link
Link used for thread queue.
Definition thread.h:217
void * stackEnd
Stack end (bottom, lowest address)
Definition thread.h:235
BOOL OSIsThreadSuspended(OSThread *thread)
Returns TRUE if a thread is suspended.
void __OSSuspendThreadNolock(OSThread *thread)
int32_t OSCheckActiveThreads()
Returns the count of active threads.
BOOL OSIsThreadTerminated(OSThread *thread)
Returns TRUE if a thread is terminated.
OSThread * OSGetCurrentThread()
Return pointer to OSThread object for the current thread.
const char * OSGetThreadName(OSThread *thread)
Get a thread's name.
uint8_t OSThreadState
A value from enum OS_THREAD_STATE.
Definition thread.h:45
OS_THREAD_STATE
Definition thread.h:83
void OSWakeupThread(OSThreadQueue *queue)
Wake up all threads in queue.
uint32_t OSThreadRequest
A value from enum OS_THREAD_REQUEST.
Definition thread.h:48
int32_t OSCheckThreadStackUsage(OSThread *thread)
Get the maximum amount of stack the thread has used.
BOOL OSSetThreadStackUsage(OSThread *thread)
Set thread stack usage tracking.
void OSTestThreadCancel()
Check to see if the current thread should be cancelled or suspended.
OSThreadSpecificID
Definition thread.h:61
void OSSleepThread(OSThreadQueue *queue)
Sleep the current thread and add it to a thread queue.
uint32_t OSGetStackPointer()
Return current stack pointer, value of r1 register.
uint8_t OSThreadAttributes
A bitfield of enum OS_THREAD_ATTRIB.
Definition thread.h:51
void OSExitThread(int32_t result)
Exit the current thread with a exit code.
void OSCancelThread(OSThread *thread)
Cancels a thread.
void * OSGetThreadSpecific(OSThreadSpecificID id)
Get a thread's specific value set by OSSetThreadSpecific.
void OSGetActiveThreadLink(OSThread *thread, OSThreadLink *link)
Get the next and previous thread in the thread's active queue.
BOOL OSCreateThread(OSThread *thread, OSThreadEntryPointFn entry, int32_t argc, char *argv, void *stack, uint32_t stackSize, int32_t priority, OSThreadAttributes attributes)
Create a new thread.
BOOL OSSetThreadCancelState(BOOL state)
Set a thread's cancellation state.
void OSDetachThread(OSThread *thread)
Detach thread.
uint32_t OSGetThreadAffinity(OSThread *thread)
Get a thread's affinity.
BOOL OSSetThreadAffinity(OSThread *thread, uint32_t affinity)
Set a thread's affinity.
void OSContinueThread(OSThread *thread)
Clears a thread's suspend counter and resumes it.
void(* OSThreadCleanupCallbackFn)(OSThread *thread, void *stack)
Definition thread.h:57
int32_t OSResumeThread(OSThread *thread)
Resumes a thread.
OS_THREAD_ATTRIB
Definition thread.h:107
uint32_t OSSuspendThread(OSThread *thread)
Suspend a thread.
OSThread * OSGetDefaultThread(uint32_t coreID)
Returns the default thread for a specific core.
int32_t OSGetThreadPriority(OSThread *thread)
Get a thread's base priority.
BOOL OSRunThread(OSThread *thread, OSThreadEntryPointFn entry, int argc, const char **argv)
Run a function on an already created thread.
void OSYieldThread()
Yield execution to waiting threads with same priority.
int(* OSThreadEntryPointFn)(int argc, const char **argv)
Definition thread.h:56
OSThreadDeallocatorFn OSSetThreadDeallocator(OSThread *thread, OSThreadDeallocatorFn deallocator)
Set the callback to be called just after a thread is terminated.
BOOL OSJoinThread(OSThread *thread, int *threadResult)
Wait until thread is terminated.
BOOL OSSetThreadRunQuantum(OSThread *thread, uint32_t quantum)
Set a thread's run quantum.
OS_THREAD_REQUEST
Definition thread.h:100
void(* OSThreadDeallocatorFn)(OSThread *thread, void *stack)
Definition thread.h:58
uint32_t OSThreadType
A bitfield of enum OS_THREAD_TYPE.
Definition thread.h:54
void OSSetThreadSpecific(OSThreadSpecificID id, void *value)
Set a thread specific value.
OSThreadCleanupCallbackFn OSSetThreadCleanupCallback(OSThread *thread, OSThreadCleanupCallbackFn callback)
Set the callback to be called just before a thread is terminated.
OS_THREAD_TYPE
Definition thread.h:130
void OSSleepTicks(OSTime ticks)
Sleep the current thread for a period of time.
void OSClearThreadStackUsage(OSThread *thread)
Disable tracking of thread stack usage.
void OSSetThreadName(OSThread *thread, const char *name)
Set a thread's name.
BOOL OSSetThreadPriority(OSThread *thread, int32_t priority)
Set a thread's priority.
@ OS_THREAD_STATE_NONE
Definition thread.h:84
@ OS_THREAD_STATE_MORIBUND
Thread is about to terminate.
Definition thread.h:96
@ OS_THREAD_STATE_WAITING
Thread is waiting, i.e. on a mutex.
Definition thread.h:93
@ OS_THREAD_STATE_READY
Thread is ready to run.
Definition thread.h:87
@ OS_THREAD_STATE_RUNNING
Thread is running.
Definition thread.h:90
@ OS_THREAD_SPECIFIC_0
These can be used by applications.
Definition thread.h:63
@ OS_THREAD_SPECIFIC_1
Definition thread.h:64
@ OS_THREAD_SPECIFIC_3
Definition thread.h:66
@ OS_THREAD_SPECIFIC_11
Definition thread.h:74
@ OS_THREAD_SPECIFIC_10
Definition thread.h:73
@ OS_THREAD_SPECIFIC_13
Definition thread.h:76
@ OS_THREAD_SPECIFIC_8
Definition thread.h:71
@ OS_THREAD_SPECIFIC_5
Definition thread.h:68
@ OS_THREAD_SPECIFIC_2
Definition thread.h:65
@ OS_THREAD_SPECIFIC_4
Definition thread.h:67
@ OS_THREAD_SPECIFIC_WUT_RESERVED_1
Definition thread.h:79
@ OS_THREAD_SPECIFIC_WUT_RESERVED_0
These are reserved to wut for internal use.
Definition thread.h:78
@ OS_THREAD_SPECIFIC_7
Definition thread.h:70
@ OS_THREAD_SPECIFIC_9
Definition thread.h:72
@ OS_THREAD_SPECIFIC_6
Definition thread.h:69
@ OS_THREAD_SPECIFIC_12
Definition thread.h:75
@ OS_THREAD_ATTRIB_AFFINITY_CPU2
Allow the thread to run on CPU2.
Definition thread.h:115
@ OS_THREAD_ATTRIB_AFFINITY_CPU0
Allow the thread to run on CPU0.
Definition thread.h:109
@ OS_THREAD_ATTRIB_DETACHED
Start the thread detached.
Definition thread.h:121
@ OS_THREAD_ATTRIB_STACK_USAGE
Enables tracking of stack usage.
Definition thread.h:124
@ OS_THREAD_ATTRIB_AFFINITY_ANY
Allow the thread to run any CPU.
Definition thread.h:118
@ OS_THREAD_ATTRIB_UNKNOWN
Definition thread.h:126
@ OS_THREAD_ATTRIB_AFFINITY_CPU1
Allow the thread to run on CPU1.
Definition thread.h:112
@ OS_THREAD_REQUEST_NONE
Definition thread.h:101
@ OS_THREAD_REQUEST_SUSPEND
Definition thread.h:102
@ OS_THREAD_REQUEST_CANCEL
Definition thread.h:103
@ OS_THREAD_TYPE_APP
Definition thread.h:133
@ OS_THREAD_TYPE_IO
Definition thread.h:132
@ OS_THREAD_TYPE_DRIVER
Definition thread.h:131
int64_t OSTime
Definition time.h:18
int32_t BOOL
Definition wut_types.h:7