wut v1.8.0
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 "time.h"
7#include "threadqueue.h"
8#include "exception.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
134
136{
137 WUT_UNKNOWN_BYTES(0x68);
139 void *eh_mem_manage[9];
140 void *eh_store_globals[6];
141 void *eh_store_globals_tdeh[76];
142};
143WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0x68, eh_globals);
144WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0x6c, eh_mem_manage);
145WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0x90, eh_store_globals);
146WUT_CHECK_OFFSET(OSThreadGHSExceptionHandling, 0xa8, eh_store_globals_tdeh);
147WUT_CHECK_SIZE(OSThreadGHSExceptionHandling, 0x1d8);
148
150{
153 void *parent;
154 WUT_UNKNOWN_BYTES(4);
155};
156WUT_CHECK_OFFSET(OSMutexQueue, 0x0, head);
157WUT_CHECK_OFFSET(OSMutexQueue, 0x4, tail);
158WUT_CHECK_OFFSET(OSMutexQueue, 0x8, parent);
159WUT_CHECK_SIZE(OSMutexQueue, 0x10);
160
166WUT_CHECK_OFFSET(OSFastMutexQueue, 0x00, head);
167WUT_CHECK_OFFSET(OSFastMutexQueue, 0x04, tail);
168WUT_CHECK_SIZE(OSFastMutexQueue, 0x08);
169
171{
172 void* data;
173 WUT_UNKNOWN_BYTES(4);
174};
175WUT_CHECK_OFFSET(OSTLSSection, 0x00, data);
176WUT_CHECK_SIZE(OSTLSSection, 0x08);
177
178#define OS_THREAD_TAG 0x74487244u
179#pragma pack(push, 1)
180struct WUT_ALIGNAS(8) OSThread
181{
183
185 uint32_t tag;
186
189
192
194 uint16_t id;
195
198
200 int32_t priority;
201
204
206 int32_t exitValue;
207
209 OSThreadQueue *coreRunQueue[3];
210 OSThreadLink coreRunQueueLink[3];
211
214
217
220
223
226
229
232
234 void *stackEnd;
235
238
241
243
245 void *specific[0x10];
246
248
250 const char *name;
251
253
256
259
262
265
268
270 int32_t needSuspend;
271
274
277
278 WUT_UNKNOWN_BYTES(0x4);
279
282
285
287 uint64_t wakeCount;
288
293
295 OSExceptionCallbackFn dsiCallback[3];
297 OSExceptionCallbackFn isiCallback[3];
299 OSExceptionCallbackFn programCallback[3];
301 OSExceptionCallbackFn perfMonCallback[3];
302
305
308
309 WUT_UNKNOWN_BYTES(0x2);
310
313
316
319
322
324 OSExceptionCallbackFn alignCallback[3];
325
327 uint32_t reserved[5];
328};
329#pragma pack(pop)
330WUT_CHECK_OFFSET(OSThread, 0x320, tag);
331WUT_CHECK_OFFSET(OSThread, 0x324, state);
332WUT_CHECK_OFFSET(OSThread, 0x325, attr);
333WUT_CHECK_OFFSET(OSThread, 0x326, id);
334WUT_CHECK_OFFSET(OSThread, 0x328, suspendCounter);
335WUT_CHECK_OFFSET(OSThread, 0x32c, priority);
336WUT_CHECK_OFFSET(OSThread, 0x330, basePriority);
337WUT_CHECK_OFFSET(OSThread, 0x334, exitValue);
338WUT_CHECK_OFFSET(OSThread, 0x338, coreRunQueue);
339WUT_CHECK_OFFSET(OSThread, 0x344, coreRunQueueLink);
340WUT_CHECK_OFFSET(OSThread, 0x35c, queue);
341WUT_CHECK_OFFSET(OSThread, 0x360, link);
342WUT_CHECK_OFFSET(OSThread, 0x368, joinQueue);
343WUT_CHECK_OFFSET(OSThread, 0x378, mutex);
344WUT_CHECK_OFFSET(OSThread, 0x37c, mutexQueue);
345WUT_CHECK_OFFSET(OSThread, 0x38c, activeLink);
346WUT_CHECK_OFFSET(OSThread, 0x394, stackStart);
347WUT_CHECK_OFFSET(OSThread, 0x398, stackEnd);
348WUT_CHECK_OFFSET(OSThread, 0x39c, entryPoint);
349WUT_CHECK_OFFSET(OSThread, 0x3a0, ghsExceptionHandling);
350WUT_CHECK_OFFSET(OSThread, 0x57c, specific);
351WUT_CHECK_OFFSET(OSThread, 0x5bc, type);
352WUT_CHECK_OFFSET(OSThread, 0x5c0, name);
353WUT_CHECK_OFFSET(OSThread, 0x5c4, waitEventTimeoutAlarm);
354WUT_CHECK_OFFSET(OSThread, 0x5c8, userStackPointer);
355WUT_CHECK_OFFSET(OSThread, 0x5cc, cleanupCallback);
356WUT_CHECK_OFFSET(OSThread, 0x5d0, deallocator);
357WUT_CHECK_OFFSET(OSThread, 0x5d4, cancelState);
358WUT_CHECK_OFFSET(OSThread, 0x5d8, requestFlag);
359WUT_CHECK_OFFSET(OSThread, 0x5dc, needSuspend);
360WUT_CHECK_OFFSET(OSThread, 0x5e0, suspendResult);
361WUT_CHECK_OFFSET(OSThread, 0x5e4, suspendQueue);
362WUT_CHECK_OFFSET(OSThread, 0x5f8, runQuantumTicks);
363WUT_CHECK_OFFSET(OSThread, 0x600, coreTimeConsumedNs);
364WUT_CHECK_OFFSET(OSThread, 0x608, wakeCount);
365WUT_CHECK_OFFSET(OSThread, 0x610, unk0x610);
366WUT_CHECK_OFFSET(OSThread, 0x618, unk0x618);
367WUT_CHECK_OFFSET(OSThread, 0x620, unk0x620);
368WUT_CHECK_OFFSET(OSThread, 0x628, unk0x628);
369WUT_CHECK_OFFSET(OSThread, 0x630, dsiCallback);
370WUT_CHECK_OFFSET(OSThread, 0x63c, isiCallback);
371WUT_CHECK_OFFSET(OSThread, 0x648, programCallback);
372WUT_CHECK_OFFSET(OSThread, 0x654, perfMonCallback);
373WUT_CHECK_OFFSET(OSThread, 0x664, tlsSectionCount);
374WUT_CHECK_OFFSET(OSThread, 0x668, tlsSections);
375WUT_CHECK_OFFSET(OSThread, 0x66c, fastMutex);
376WUT_CHECK_OFFSET(OSThread, 0x670, contendedFastMutexes);
377WUT_CHECK_OFFSET(OSThread, 0x678, fastMutexQueue);
378WUT_CHECK_OFFSET(OSThread, 0x680, alignCallback);
379WUT_CHECK_OFFSET(OSThread, 0x68c, reserved);
380WUT_CHECK_SIZE(OSThread, 0x6a0);
381
388void
390
391
395int32_t
397
398
402int32_t
404
405
409void
411
412
416void
418
419
432BOOL
435 int32_t argc,
436 char *argv,
437 void *stack,
438 uint32_t stackSize,
439 int32_t priority,
440 OSThreadAttributes attributes);
441
442
446void
448
449
455void
456OSExitThread(int32_t result);
457
458
462void
464 OSThreadLink *link);
465
466
470OSThread *
472
473
481OSThread *
482OSGetDefaultThread(uint32_t coreID);
483
484
488uint32_t
490
491
495uint32_t
497
498
502const char *
504
505
509int32_t
511
512
516void *
518
519
523BOOL
525
526
530BOOL
532
533
543BOOL
545 int *threadResult);
546
547
556int32_t
558
559
565BOOL
568 int argc,
569 const char **argv);
570
571
575BOOL
577 uint32_t affinity);
578
579
586BOOL
588
589
596
597
603 OSThreadDeallocatorFn deallocator);
604
605
609void
611 const char *name);
612
613
617BOOL
619 int32_t priority);
620
621
628BOOL
630 uint32_t quantum);
631
637void
639 void *value);
640
641
645BOOL
647
648
654void
656
657
661void
663
664
673uint32_t
675
676void
678
692void
694
695
701void
703
704
711void
713
714
715#ifdef __cplusplus
716}
717#endif
718
BOOL(* OSExceptionCallbackFn)(OSContext *context)
Definition exception.h:15
OSThreadLink activeLink
Link for global active thread queue.
Definition thread.h:228
OSFastMutexQueue contendedFastMutexes
The fast mutexes we are currently contended on.
Definition thread.h:318
OSMutex * head
Definition thread.h:151
uint64_t coreTimeConsumedNs
The total amount of core time consumed by this thread (Does not include time while Running)
Definition thread.h:284
OSThreadAttributes attr
Bitfield of OS_THREAD_ATTRIB.
Definition thread.h:191
OSFastMutex * tail
Definition thread.h:164
OSThreadState state
Bitfield of OS_THREAD_STATE.
Definition thread.h:188
OSMutexQueue mutexQueue
Queue of mutexes this thread owns.
Definition thread.h:225
OSTime unk0x620
Definition thread.h:291
uint32_t tag
Should always be set to the value OS_THREAD_TAG.
Definition thread.h:185
OSFastMutex * fastMutex
The fast mutex we are currently waiting for.
Definition thread.h:315
void * userStackPointer
The stack pointer passed in OSCreateThread.
Definition thread.h:255
OSTLSSection * tlsSections
TLS Sections.
Definition thread.h:312
OSThreadDeallocatorFn deallocator
Called just after a thread is terminated, set with OSSetThreadDeallocator.
Definition thread.h:261
BOOL alarmCancelled
Definition thread.h:242
OSThreadGHSExceptionHandling ghsExceptionHandling
GHS Exception handling thread-specifics.
Definition thread.h:240
int32_t needSuspend
Pending suspend request count.
Definition thread.h:270
int32_t priority
Actual priority of thread.
Definition thread.h:200
OSTime unk0x618
Definition thread.h:290
uint16_t id
Unique thread ID.
Definition thread.h:194
OSThreadEntryPointFn entryPoint
Thread entry point.
Definition thread.h:237
OSAlarm * waitEventTimeoutAlarm
Definition thread.h:252
uint64_t wakeCount
The number of times this thread has been awoken.
Definition thread.h:287
void * parent
Definition thread.h:153
OSMutex * tail
Definition thread.h:152
int32_t basePriority
Base priority of thread, 0 is highest priority, 31 is lowest priority.
Definition thread.h:203
void * data
Definition thread.h:172
OSMutex * mutex
Mutex this thread is waiting to lock.
Definition thread.h:222
const char * name
Thread name, accessed with OSSetThreadName and OSGetThreadName.
Definition thread.h:250
OSTime unk0x610
Definition thread.h:289
uint16_t tlsSectionCount
Number of TLS sections.
Definition thread.h:307
OSThreadRequest requestFlag
Current thread request, used for cancelleing and suspending the thread.
Definition thread.h:267
OSTime unk0x628
Definition thread.h:292
BOOL cancelState
If TRUE then a thread can be cancelled or suspended, set with OSSetThreadCancelState.
Definition thread.h:264
int32_t exitValue
Exit value.
Definition thread.h:206
OSThreadQueue * queue
Queue the thread is currently waiting on.
Definition thread.h:213
OSContext context
Definition thread.h:182
int32_t suspendCounter
Suspend count (increased by OSSuspendThread).
Definition thread.h:197
OSThreadQueue suspendQueue
Queue of threads waiting for a thread to be suspended.
Definition thread.h:276
int32_t suspendResult
Result of thread suspend.
Definition thread.h:273
int64_t runQuantumTicks
How many ticks the thread should run for before suspension.
Definition thread.h:281
void * stackStart
Stack start (top, highest address)
Definition thread.h:231
OSThreadCleanupCallbackFn cleanupCallback
Called just before thread is terminated, set with OSSetThreadCleanupCallback.
Definition thread.h:258
BOOL stackSyncObjAllowed
Checks for synchronization objects placed on stack in debug mode when set to true.
Definition thread.h:304
OSFastMutex * head
Definition thread.h:163
OSThreadType type
Definition thread.h:247
OSThreadQueue joinQueue
Queue of threads waiting to join this thread.
Definition thread.h:219
OSFastMutexQueue fastMutexQueue
The fast mutexes we currently own locks on.
Definition thread.h:321
OSThreadLink link
Link used for thread queue.
Definition thread.h:216
void * stackEnd
Stack end (bottom, lowest address)
Definition thread.h:234
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:129
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:132
@ OS_THREAD_TYPE_IO
Definition thread.h:131
@ OS_THREAD_TYPE_DRIVER
Definition thread.h:130
int64_t OSTime
Definition time.h:18
int32_t BOOL
Definition wut_types.h:7