Kernel Objects

Kernel Objects

KBlockInfo

Size : 0x8 bytes

OffsetTypeDescription
0x0u32Pointer to memory section start in FCRAM using kernel vmem addresses
0x4u32Page count

KBlockInfo objects start with the FS KProcess on the kernel heap and continue in order. Each KProcess gets 3 or more KBlockInfo objects for (in order) .text pointer and page count, .rodata pointer and page count, and .data pointer and page count. Apps that require more space than is available in a given block will get multiple KBlockInfo objects for each section to split it up into open spaces.

KClassToken

Size : 0x5 bytes

OffsetTypeDescription
0x0const char *Pointer to kernel type string
0x4u8Kernel object descriptive bitflags

Each type of kernel object has a token that describes it. The token is used to make sure that a kernel object of a certain type is able to perform a function requested by the kernel.

Bitflags #

BitDescription
0Can synchronize
1Is interruptible
2
3
4
5
6
7

Bitflags and their corresponding objects #

Bits
765
000
000
000
001
001
001
010
010
010
011
011
011
100
100
100
101
101
101
110
110

Category:Kernel objects

KCoreContext

Size: 0x9000 bytes (effective size: 0x6000 bytes)

There’s one instance of this structure per core. The instance for the current core is aliased at 0xFFFF1000

OffsetTypeDescription
0x0u32[0x400]N/A (unmapped memory)
0x1000u32[0x1000]L1 translation table (TTB1). The unused part of it is used as stack for exception modes other than supervisor
0x5000u32[0x400]N/A
0x6000KThreadContextContext for the scheduler’s thread
0x7000u32[0x400]N/A
0x8000KCoreObjectContextCurrently used objects, see below

KCoreObjectContext

KDebugThread

Size : 0x18 bytes

OffsetTypeDescription
0x0KThread *Pointer to KThread object this KDebugThread is linked to
0x4u8Indicates that svcBreak was used with type != (UN)LOAD_RO
0x5u8Indicates that the thread has been locked by KDebug-related functions
0x6u8Indicates that the thread shall be locked, set by KDebug-related functions
0x7u8For SCHEDULE IN/OUT debug events: 0 for IN, 1 for OUT
0x8u8Thread is attached
0x9u8For SYSCALL IN/OUT debug events: 0 for IN, 1 for OUT
0xAu8[2]Padding
0xCu32Thread exit reason
0x10u32ID of the creator thread
0x14u32Fault Address Register (when applicable)

Category:Kernel objects

KEventInfo

Size : 0x38 bytes

It is converted to struct DebugEventInfo by using svcContinueDebugEvent.

Object definition #

OffsetTypeDescription
0x0u32Event type
0x4u32Current KThread ID
0x8u32Flags. In all observed cases, bit0 means that svcContinueDebugEvent needs to be called for this event (except for EXIT PROCESS events, for which you need to call svcContinueDebugEvent even if this bit is clear)
0xCu8ATTACH PROCESS/THREAD events: 1 if the object was attached by svcDebugActiveProcess, 0 otherwise (this is always 1 for processes)
0xDu8Equal to bit0 of field 0x8 in all observed cases: indicates that svcContinueDebugEvent needs to be called for this event (except for EXIT PROCESS events, for which you need to call svcContinueDebugEvent even if this bit is clear)
0xEboolIgnore continue
0xFu8Indicates that the event has been handled and should be deleted
0x10union { ... }Event-specific data, see below (slightly different from DebugEventInfo)

Event-specific data #

ATTACH PROCESS event #

TypeField
KProcess *Process

ATTACH THREAD event #

TypeField
u32Creator thread ID (0 if attached by svcDebugActiveProcess)
void *Thread local storage
u32 *Entrypoint = .text load address of the parent process

EXIT THREAD/PROCESS events #

TypeField
u32Exit reason

EXCEPTION event #

TypeField
u32Exception type
u32Exception address
u32Exception category: 4 for DEBUGGER BREAK, 3 for USER BREAK, 2 for STOP POINT, 1 for DATA ABORT/UNALIGNED DATA ACCESS/UNDEFINED SYSCALL, 0 otherwise
union { ... }Type-specific data, see below

UNDEFINED INSTRUCTION/PREFETCH ABORT/DATA ABORT/UNALIGNED DATA ACCESS/UNDEFINED SYSCALL/STOP POINT events #

TypeField
u32Fault information: Fault Address Register (for watchpoints, DATA ABORT and UNALIGNED DATA ACCESS), attempted SVC ID (for UNDEFINED SYSCALL), otherwise 0
u32Stop point type that caused the event (when applicable): 0 = svc 0xFF, 1 = breakpoint, 2 = watchpoint

USER BREAK event #

TypeField
u32Break reason
u32[2]User-provided parameters for debug reasons, or 0

DEBUGGER BREAK event #

TypeField
s32[4]IDs of the attached process’s threads that were running on each core at the time of the @ref svcBreakDebugProcess call, or -1 (only the first 2 values are meaningful on O3DS).

SCHEDULE IN/OUT events #

TypeField
u64Clock tick
u32CPU ID
u32[5]Unknown
u32 (?)Event info, apparently 0

SYSCALL IN/OUT events #

TypeField
u64Clock tick
u32Syscall ID

OUTPUT STRING event #

TypeField
u32String address
u32String size

MAP event #

TypeField
u32Mapped address
u32Mapped size
u32MemoryPermission
u32MemoryState

Category:Kernel objects

KInterruptEventMailbox

Size : 0x14 bytes

There are only two instances of this class. The first mailbox contains pointers to KProcess instances (viewed as KSendableInterruptEvent), and its handling thread has a priority of 0; whereas the second mailbox contains pointers to KThread instances (viewed as KSendableInterruptEvent), and DMA-related interrupt events, and its handling thread has a priority of 16.

The handling thread executes the handler function, i.e. the first virtual function (then removes the interrupt event from the list) of all the KSendableInterruptEvent instances the mailbox contains. When that list is empty, it sets the mailbox’s “is busy” flag and unschedules itself.

KMemoryBlock

Size : 0x14 bytes

OffsetTypeDescription
0x0void*Base address of memory block.
0x4u32Block size in pages.
0x8u32Memory block permissions - rwx.
0xCu32Memory state bitflags - the lowest byte is the type of memory and the second byte is for specific properties of the block.
0x10u32Zero

Category:Kernel objects

KObjectLink

Size : 0x10 bytes

This is used to keep track of kernel objects and allocate new ones.

OffsetTypeDescription
0x0u32Pointer to next available kernel object
0x4u32Pointer to first kernel object
0x8u32Size of kernel heap allocation for this specific kernel object
0xCu32Size of this kernel object

Category:Kernel objects

KObjectList

Size : 0x28 bytes

This object

OffsetTypeDescription
0x0u32Current count for object
0x4KLinkedListNode*KLinkedListNode for first object in list
0x8KLinkedListNode*KLinkedListNode for last object in list
0xCKObjectMutexMutex
0x14u16Total objects of this type that have been created
0x16u16Alignment
0x18KObjectLinkObject info tracking

Category:Kernel objects

KProcessHwInfo

Struct inside the KProcess object. Starts at KProcess+0x1C.

Size : 0x4C bytes (on N3DS)

Offsets above 0x8 are only for N3DS.

OffsetTypeDescription
0x0KObjectMutexMutex
0x8u32[number of cores]TLB entries for process need invalidating on core(i)
0x18u32KMemoryBlock count for KProcess
0x1CKLinkedListNode*First KLinkedListNode in list of KMemoryBlocks
0x20KLinkedListNode*Last KLinkedListNode in list of KMemoryBlocks
0x24u32Unknown
0x28u32Unknown
0x2Cvoid*Translation table base
0x30u8Context ID
0x31boolIndicates that a global TLB flush is needed
0x32boolProcess is the current running game/app
0x34u32Unknown
0x38void*End of userland memory for process
0x3Cvoid*Linear memory start for process (since 8.0.0-18)
0x40u32Unknown (since 8.0.0-18)
0x44u32MMU table size
0x48u32*Pointer to the MMU table in kernel FCRAM vmem

Category:Kernel objects

KRecursiveLock

Size : 0x8 bytes

Used to implement critical sections, etc.

This class has 3 methods : Lock, Unlock, and LocalUnlock. The only difference between the two last methods is that the last one never triggers SGI #8 (rescheduling signal, associated to KScheduler objects)

Lock / Unlock blocks are always used with the same object.

Lock / LocalUnlock are always used with the associated attribute of the timer/watchdog timer interrupt object.

KSchedulableInterruptEventLinkedList

Size : 0x10 bytes

There is exactly one instance of this class per core.

On interrupt requests, when the interrupt handler of a KSchedulableInterruptEvent returns anything else than NULL or 1, it is added to this list.

After being added to this list, the thread handling this object (which is a thread created by the kernel main function) is scheduled and the context is switched. That thread pops the first interrupt event from the list and execute its second virtual function, then unschedules itself and switches context back.

KThreadContext

Size : 0x1000 bytes (1 page)

Each thread is allocated a 0x1000-byte page in this region for the thread context. Each thread has its context address stored as 2 members:

OffsetTypeDescription
0x88u32*Ptr to svc mode register storage for KThread inside the thread context.
0x8Cu32*End-address of the page for this thread context allocated in the 0xFF4XX000 region.

KThread offset 0x88 points to offset 0xF50 in the thread context and 0x8C points to the end of the thread context page. The kernel refers to the thread context page by subtracting from the end instead of adding from the beginning.

KThreadLocalPage

Size : 0x18 bytes

OffsetTypeDescription
0x0u32Pointer to memory page used for thread local regions for threads owned by a given process
0x4KProcess*Owner process
0x8u32Number of threads owned by the process
0xCchar[8]Used to track the usage of thread local regions in the local page.
0x14u32Zero

The 8-byte array used to track the regions in use in the page works like so: