Contents
Win32 Thread Information Block
The Thread Information Block (TIB) or Thread Environment Block (TEB) is a data structure in Win32 on x86 that stores information about the currently running thread. It descended from, and is backward-compatible on 32-bit systems with, a similar structure in OS/2. The TIB is officially undocumented for Windows 9x. The Windows NT series DDK (as well as the MinGW/ReactOS implementation) includes a struct in that documents the subsystem independent part. Even before TIB was effectively documented, many applications have already started using its fields that they are effectively a part of the API. The first field containing the SEH frame, in particular, is directly referenced by the code produced by Microsoft's own compiler. The Win32 subsystem-specific part of the TEB is undocumented, but Wine includes a TEB definition in. The TIB can be used to get a lot of information on the process without calling Win32 API. Examples include emulating,. Through the pointer to the PEB one can obtain access to the import tables (IAT), process startup arguments, image name, etc. It is accessed from the FS segment register on 32-bit Windows and GS on 64-bit Windows.
Contents of the TIB on Windows
This table is based on Wine's work on Microsoft Windows internals. FS (for 32-bit) or GS (for 64-bit) maps to a TIB which is embedded in a data block known as the TDB (thread data base). The TIB contains the thread-specific exception handling chain and pointer to the TLS (thread local storage.) The thread local storage is not the same as C local storage.
Stack information stored in the TIB
A process should be free to move the stack of its threads as long as it updates the information stored in the TIB accordingly. A few fields are key to this matter: stack base, stack limit, deallocation stack, and guaranteed stack bytes, respectively stored at offsets, , and in 64 bits. Different Windows kernel functions read and write these values, specially to distinguish stack overflows from other read/write page faults (a read or write to a page guarded among the stack limits in guaranteed stack bytes will generate a stack-overflow exception instead of an access violation). The deallocation stack is important because Windows API allows to change the amount of guarded pages: the function allows both read the current space and to grow it. In order to read it, it reads the field, and to grow it, it uses has to uncommit stack pages. Setting stack limits without setting will probably cause odd behavior in. For example, it will overwrite the stack limits to wrong values. Different libraries call, for example the .NET CLR uses it for setting up the stack of their threads.
Accessing the TIB
The TIB of the current thread can be accessed as an offset of segment register FS (x86) or GS (x64). It is not common to access the TIB fields by an offset from, but rather first getting a linear self-referencing pointer to it stored at. That pointer can be used with pointer arithmetic or be cast to a struct pointer. Using Microsoft Windows SDK or similar, a programmer could use an inline function defined in named which returns the address of the current Thread Information Block as. Alternative methods of access for IA-32 architectures are as follows:
This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.
Wikipedia® is a registered trademark of the
Wikimedia Foundation, Inc.
Bliptext is not
affiliated with or endorsed by Wikipedia or the
Wikimedia Foundation.