Win32 Thread Information Block - Accessing The TIB

Accessing The TIB

The TIB can be accessed as an offset of segment register FS.

It is not common to access the TIB fields by an offset from FS:, but rather first getting a linear self-referencing pointer to it stored at FS:. That pointer can be used with pointer arithmetics or be cast to a struct pointer.

Example in C inlined-assembly for 32-bit x86:

// gcc (AT&T-style inline assembly). void *getTIB { void *pTib; __asm__("movl %%fs:0x18, %0" : "=r" (pTib) : : ); return pTib; } // Microsoft C void *getTib { void *pTib; __asm { mov EAX, FS: mov, EAX } return pTib; } // Using Microsoft's intrinsics instead of inline assembly void *getTib { void *pTib = ( void * ) __readfsdword( 0x18 ); return pTib; }

Read more about this topic:  Win32 Thread Information Block