请输入您要查询的百科知识:

 

词条 Win32 Thread Information Block
释义

  1. Contents of the TIB on Windows

  2. Accessing the TIB

  3. See also

  4. References

  5. Further reading

  6. External links

{{update|date=December 2013}}

In computing, the Win32 Thread Information Block (TIB) is a data structure in Win32 on x86 that stores information about the currently running thread. This structure is also known as the Thread Environment Block (TEB).

The TIB is officially undocumented for Windows 9x. The Windows NT series DDK includes a struct NT_TIB in winnt.h that documents the subsystem independent part. Wine includes [https://github.com/wine-mirror/wine/blob/d744f367d263a131feee96e103fb8220e8400b53/include/winternl.h#L347 header declarations] for the extended (subsystem-specific part of) TIB. Yet so many Win32 programs use these undocumented fields that they are effectively a part of the API. The first field, in particular, is directly referenced by the code produced by Microsoft's own compiler.

The TIB can be used to get a lot of information on the process without calling Win32 API. Examples include emulating GetLastError(), GetVersion(). 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 when operating on 32 bits, and from GS in 64 bits.

Contents of the TIB on Windows

Bytes/

Type

offset

(32 bits, FS)

offset

(64 bits, GS)

Windows Versions Description
pointerFS:[0x00]GS:[0x00]Win9x and NTCurrent Structured Exception Handling (SEH) frame
pointerFS:[0x04]GS:[0x08]Win9x and NTStack Base / Bottom of stack (high address)
pointerFS:[0x08]GS:[0x10]Win9x and NTStack Limit / Ceiling of stack (low address)
pointerFS:[0x0C]GS:[0x18]NTSubSystemTib
pointerFS:[0x10]GS:[0x20]NTFiber data
pointerFS:[0x14]GS:[0x28]Win9x and NTArbitrary data slot
pointerFS:[0x18]GS:[0x30]Win9x and NTLinear address of TEB
---- End of NT subsystem independent part ----
pointerFS:[0x1C]GS:[0x38]NTEnvironment Pointer
pointerFS:[0x20]GS:[0x40]NTProcess ID (in some windows distributions this field is used as 'DebugContext')
4FS:[0x24]GS:[0x48]NTCurrent thread ID
4FS:[0x28]GS:[0x50]NTActive RPC Handle
4FS:[0x2C]GS:[0x58]Win9x and NTLinear address of the thread-local storage array
4FS:[0x30]GS:[0x60]NTLinear address of Process Environment Block (PEB)
4FS:[0x34]GS:[0x68]NTLast error number
4FS:[0x38]NTCount of owned critical sections
4FS:[0x3C]NTAddress of CSR Client Thread
4FS:[0x40]NTWin32 Thread Information
124FS:[0x44]NT, WineWin32 client information (NT), user32 private data (Wine), 0x60 = LastError (Win95), 0x74 = LastError (WinME)
4FS:[0xC0]NTReserved for Wow64. Contains a pointer to FastSysCall in Wow64.
4FS:[0xC4]NTCurrent Locale
4FS:[0xC8]NTFP Software Status Register
216FS:[0xCC]NT, WineReserved for OS (NT), kernel32 private data (Wine)
herein: FS:[0x124] 4 NT Pointer to KTHREAD (ETHREAD) structure
4FS:[0x1A4]NTException code
18FS:[0x1A8]NTActivation context stack
24FS:[0x1BC]NT, WineSpare bytes (NT), ntdll private data (Wine)
40FS:[0x1D4]NT, WineReserved for OS (NT), ntdll private data (Wine)
1248FS:[0x1FC]NT, WineGDI TEB Batch (OS), vm86 private data (Wine)
4FS:[0x6DC]NTGDI Region
4FS:[0x6E0]NTGDI Pen
4FS:[0x6E4]NTGDI Brush
4FS:[0x6E8]NTReal Process ID
4FS:[0x6EC]NTReal Thread ID
4FS:[0x6F0]NTGDI cached process handle
4FS:[0x6F4]NTGDI client process ID (PID)
4FS:[0x6F8]NTGDI client thread ID (TID)
4FS:[0x6FC]NTGDI thread locale information
20FS:[0x700]NTReserved for user application
1248FS:[0x714]NTReserved for GL
4FS:[0xBF4]GS:[0x1250]NTLast Status Value
532FS:[0xBF8]GS:[0x1258]NTStatic UNICODE_STRING buffer
pointerFS:[0xE0C]GS:[0x1478]NTAlso known as DeallocationStack, it establishes the real start address of the stack buffer, hence the real stack limit: it is a few pages less than the stack limit field (which hides the guard pages used to detect stack overflows).
pointer[]FS:[0xE10]GS:[0x1480]NTTLS slots, 4/8 bytes per slot, 64 slots
8FS:[0xF10]GS:[0x1680]NTTLS links (LIST_ENTRY structure)
4FS:[0xF18]NTVDM
4FS:[0xF1C]NTReserved for RPC
4FS:[0xF28]NTThread error mode (RtlSetThreadErrorMode)

FS 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.

Note: The above description ONLY refers to 32-bit Windows on x86. On x86-64 (64-bit) Windows, GS (and not FS) is used as the segment register that points to the TIB. Additionally some of the variable slots in the structure above have a different size (typically 8 instead of 4 bytes for pointer-sized data slots).

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 FS:[0], but rather first getting a linear self-referencing pointer to it stored at FS:[0x18]. 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

__declspec(naked)

void *getTIB() {

}

// Using Microsoft's intrinsics instead of inline assembly (works for both X86 and X64 architectures)

void *getTIB() {

  1. ifdef _M_IX86
  2. elif _M_AMD64
  3. endif

}

See also

  • Structured Exception Handling

References


}}

Further reading

  • {{cite book|url=http://cs.mipt.ru/docs/comp/eng/os/win32/win95_sys_progr_secr/main.pdf|title=Windows 95 Programming Secrets |author-last=Pietrek |author-first=Matt |author-link=Matt Pietrek |date=March 1996|publisher=IDG|isbn=978-1-56884-318-6|pages=136–138|format=pdf|accessdate=2010-07-17|deadurl=yes|archiveurl=https://web.archive.org/web/20110514140137/http://cs.mipt.ru/docs/comp/eng/os/win32/win95_sys_progr_secr/main.pdf|archivedate=2011-05-14|df=}}

External links

  • TEB layout on NTinternals.net
  • Structured Exception Handling and the TIB
  • [https://www.nirsoft.net/kernel_struct/vista/NT_TIB.html Description of the first slots of the TIB]
  • [https://www.geoffchappell.com/studies/windows/win32/ntdll/structs/teb/index.htm Description of TEB, field by field]
  • [https://www.vergiliusproject.com/kernels/x64/Windows%2010%20%7C%202016/1809%20Redstone%205%20(October%20Update)/_TEB TEB definitions for various Windows versions]

3 : Windows NT architecture|Microsoft application programming interfaces|Threads (computing)

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/10 12:45:45