Difference between revisions of "KThread"

From 3dbrew
Jump to navigation Jump to search
Line 32: Line 32:
 
| 0x14
 
| 0x14
 
| u32
 
| u32
| Start of 0x10 byte unnamed kernel object in KThread
+
| Pointer to vtable for KThread suspend timer interrupt object
 +
|-
 +
| 0x18
 +
| u32
 +
| Pointer to another suspend interrupt object
 +
|-
 +
| 0x1C
 +
| s64
 +
| Timer for suspended thread
 
|-
 
|-
 
| 0x24
 
| 0x24

Revision as of 09:33, 26 September 2015

class KThread extends KSynchronizationObject;

Size : 0xB0 bytes

Offset Type Description
0x0 u32 Pointer to vtable
0x4 u32 Reference count
0x8 u32 Count of KThreads that sync with this object - number of nodes in the linked list below
0xC KLinkedListNode* Pointer to first KLinkedListNode in node list of KThreads that sync with this object
0x10 KLinkedListNode* Pointer to last KLinkedListNode in node list of KThreads that sync with this object
0x14 u32 Pointer to vtable for KThread suspend timer interrupt object
0x18 u32 Pointer to another suspend interrupt object
0x1C s64 Timer for suspended thread
0x24 u32 Start of 0x8 byte unnamed kernel object in KThread
0x2C u32 Start of unnamed kernel object of undetermined size in KThread
0x34 u8 Used to signal (re)scheduling
0x35 u8 Used in syncing
0x36 s8 ?
0x37 u8 Used in syncing
0x38 KDebugThread* Pointer to KDebugThread object used with the current KThread
0x3C u32 Base thread priority
0x40 u32 Pointer to object the KThread is waiting on- can be a timer, event, session, etc.
0x48 u32 Double pointer to KThread of unknown use/creation - used in scheduler
0x4C u32 Arbitration address
0x5C KMutex*(?) Set to KMutex+0x14 in some very specific circumstances
0x60 u32 Count of KMutex objects this thread is using
0x64 KLinkedListNode* Pointer to first KLinkedListNode in node list of KMutex objects this thread is using
0x68 KLinkedListNode* Pointer to last KLinkedListNode in node list of KMutex objects this thread is using
0x6C s32 Dynamic thread priority
0x70 s32 Processor that created the thread
0x74 u32 ?
0x7C u8 ?
0x7D u8 ?
0x7E u8 Thread affinity mask - set differently depending on whether the thread is created via svc call or from inside the kernel
0x80 KProcess* Process the thread belongs to (virtual address)
0x84 u32 Thread id
0x88 u32* Ptr to svc mode register storage for KThread inside the thread context.
0x8C u32* End-address of the page for this thread context allocated in the 0xFF4XX000 region. Thus, if the beginning of this mapped page is 0xFF401000, this ptr would be 0xFF402000. Thread context page - used for thread svc stack, preserving svc mode registers and VFP exception register for thread.
0x90 s32 Ideal processor (processorid value from svcCreateThread)
0x94 void* Ptr to threadlocalstorage
0x98 void* Ptr to threadlocalstorage in FCRAM via kernel vmem
0xA0 KThread* Previous (virtual address)
0xA4 KThread* Next (virtual address)
0xA8 struct { KThread* first; KThread* last; } ptr Pointer to linked list that has stolen it, or 0 if in normal list


Thread Affinity Mask

If the thread is created via a call to SVC 8(CreateThread), which uses thread creation type 3, and the CPU ID is -2(meaning use the core specified in the exheader), the mask is just the affinity mask from the thread's owner KProcess. If the CPU ID is -1(meaning any core), the affinity mask is set to 0xF on the New3DS and 0x3 on the Old3DS. Otherwise, the affinity mask is (1 << cpu_id) | 1.

If the thread is created via a call by the kernel, which uses thread creation types 0-2, the checks for -1 and -2 are skipped and the mask is always (1 << cpu_id) | 1.