为什么80%的码农都做不了架构师?>>>   hot3.png

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).[1]

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 declarations for the extended (subsystem-specific part of) TIB.[citation needed] 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.[1]

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

  • 1 Contents of the TIB on Windows
  • 2 Accessing the TIB
  • 3 See also
  • 4 References
  • 5 Further reading
  • 6 External links

Contents of the TIB on Windows

Bytes/

Type

offset

(32 bits, FS)

offset

(64 bits, GS)

Windows Versions Description
pointer FS:[0x00] GS:[0x00] Win9x and NT Current Structured Exception Handling (SEH) frame
pointer FS:[0x04] GS:[0x08] Win9x and NT Stack Base / Bottom of stack (high address)
pointer FS:[0x08] GS:[0x10] Win9x and NT Stack Limit / Ceiling of stack (low address)
pointer FS:[0x0C] GS:[0x18] NT SubSystemTib
pointer FS:[0x10] GS:[0x20] NT Fiber data
pointer FS:[0x14] GS:[0x28] Win9x and NT Arbitrary data slot
pointer FS:[0x18] GS:[0x30] Win9x and NT Linear address of TEB
---- End of NT subsystem independent part ----
pointer FS:[0x1C] GS:[0x38] NT Environment Pointer
pointer FS:[0x20] GS:[0x40] NT Process ID (in some windows distributions this field is used as 'DebugContext')
4 FS:[0x24] GS:[0x48] NT Current thread ID
4 FS:[0x28]   NT Active RPC Handle
4 FS:[0x2C]   Win9x and NT Linear address of the thread-local storage array
4 FS:[0x30] GS:[0x60] NT Linear address of Process Environment Block (PEB)
4 FS:[0x34] GS:[0x68] NT Last error number
4 FS:[0x38]   NT Count of owned critical sections
4 FS:[0x3C]   NT Address of CSR Client Thread
4 FS:[0x40]   NT Win32 Thread Information
124 FS:[0x44]   NT, Wine Win32 client information (NT), user32 private data (Wine), 0x60 = LastError (Win95), 0x74 = LastError (WinME)
4 FS:[0xC0]   NT Reserved for Wow64. Contains a pointer to FastSysCall in Wow64.
4 FS:[0xC4]   NT Current Locale
4 FS:[0xC8]   NT FP Software Status Register
216 FS:[0xCC]   NT, Wine Reserved for OS (NT), kernel32 private data (Wine)
herein: FS:[0x124] 4 NT Pointer to KTHREAD (ETHREAD) structure
4 FS:[0x1A4]   NT Exception code
18 FS:[0x1A8]   NT Activation context stack
24 FS:[0x1BC]   NT, Wine Spare bytes (NT), ntdll private data (Wine)
40 FS:[0x1D4]   NT, Wine Reserved for OS (NT), ntdll private data (Wine)
1248 FS:[0x1FC]   NT, Wine GDI TEB Batch (OS), vm86 private data (Wine)
4 FS:[0x6DC]   NT GDI Region
4 FS:[0x6E0]   NT GDI Pen
4 FS:[0x6E4]   NT GDI Brush
4 FS:[0x6E8]   NT Real Process ID
4 FS:[0x6EC]   NT Real Thread ID
4 FS:[0x6F0]   NT GDI cached process handle
4 FS:[0x6F4]   NT GDI client process ID (PID)
4 FS:[0x6F8]   NT GDI client thread ID (TID)
4 FS:[0x6FC]   NT GDI thread locale information
20 FS:[0x700]   NT Reserved for user application
1248 FS:[0x714]   NT Reserved for GL
4 FS:[0xBF4] GS:[0x1250] NT Last Status Value
532 FS:[0xBF8] GS:[0x1258] NT Static UNICODE_STRING buffer
pointer FS:[0xE0C] GS:[0x1478] NT Address of memory allocated for stack
pointer[] FS:[0xE10] GS:[0x1480] NT TLS slots, 4/8 bytes per slot, 64 slots
8 FS:[0xF10] GS:[0x1680] NT TLS links (LIST_ENTRY structure)
4 FS:[0xF18]   NT VDM
4 FS:[0xF1C]   NT Reserved for RPC
4 FS:[0xF28]   NT Thread 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() {__asm mov EAX, FS:[18h]
}

// Using Microsoft's intrinsics instead of inline assembly (works for both X86 and X64 architectures)
void *getTIB() {
#ifdef _M_IX86return (void *)__readfsdword(0x18);
#elif _M_AMD64return (void *)__readgsqword(0x30);
#endif
}

See also

  • Structured Exception Handling

References

  1. Pietrek, Matt (May 1996). "Under The Hood". Microsoft Systems Journal. Retrieved 2010-07-07.

Further reading

  • Pietrek, Matt (March 1996). Windows 95 Programming Secrets (PDF). IDG. pp. 136–138. ISBN 978-1-56884-318-6. Archived from the original (pdf) on 2011-05-14. Retrieved 2010-07-17.

External links

  • TEB layout on NTinternals.net
  • Structured Exception Handling and the TIB
  • Description of the first slots of the TIB
  • Description of TEB, field by field
Categories:

  • Microsoft application programming interfaces
  • Threads (computing)

转载于:https://my.oschina.net/u/1777508/blog/2873386

Win32 Thread Information Block相关推荐

  1. Thread Environment Block(TEB)

    TEB简介 TEB(Thread Environment Block,线程环境块)指线程环境块,该结构体包含进程中运行线程的各种信息,进程中的每个线程都对应着一个TEB结构体.不同OS中TEB结构体的 ...

  2. CUDA之单thread单block多thread单block多thread多block

    用简单的立方和归约来举例: //单thread单block #include <stdio.h> #include <stdlib.h> #include <cuda_r ...

  3. CUDA编程——GPU架构,由sp,sm,thread,block,grid,warp说起

    目录 1.从硬件看 2.从软件看 3.对应关系 4.SIMT和SIMD 掌握部分硬件知识,有助于程序员编写更好的CUDA程序,提升CUDA程序性能,本文目的是理清sp,sm,thread,block, ...

  4. 【5G RRC】Master Information Block (NR-MIB)

    博主未授权任何人或组织机构转载博主任何原创文章,感谢各位对原创的支持! 博主链接 本人就职于国际知名终端厂商,负责modem芯片研发. 在5G早期负责终端数据业务层.核心网相关的开发工作,目前牵头6G ...

  5. Win32病毒入门 -- ring3篇

    Win32病毒入门 -- ring3篇 by pker / CVC.GB 1.声明 ------- 本文仅仅是一篇讲述病毒原理的理论性文章,任何人如果通过本文中讲述的技术或利用本文 中的代码写出恶性病 ...

  6. Win32病毒入门--ring3篇

    Win32病毒入门--ring3篇 声明 一篇讲述病毒原理的理论性文章,任何人如果通过本文中讲述的技术或利用本文中的代码写出恶性病毒,造成的任何影响均与作者无关. 前言 病毒是什么?病毒就是一个具有一 ...

  7. Win32 系统线程信息块(TIB)浅析

    作者:Matt Pietrek 编译:VCKBASE 原文出处:May 1996 Under The Hood Windows 操作系统各个版本之间虽然核心部分差异很大,但它们都共享一个关键的系统数据 ...

  8. [经典文章翻译]A Crash Course on the Depths of Win32 Structured Exception Handling

    转自:[已完工][经典文章翻译]A Crash Course on the Depths of Win32 Structured Exception Handling 原文题目: <<A ...

  9. A Crash Course on the Depths of Win32 Structured Exception Handling(文章翻译)

    [经典文章翻译]A Crash Course on the Depths of Win32 Structured Exception Handling 原文题目: <<A Crash Co ...

最新文章

  1. RethinkDB是什么?—— 面向文档的NOSQL数据库,MVCC+Btree索引,pushes JSON to your apps in realtime采用push思路,优化的ssd存储...
  2. STM32 备份寄存器操作
  3. caffe中Makefile.config详解
  4. 编写好代码的10条戒律
  5. Python爬虫人工智能大数据全栈视频史上最全合辑教程分享!
  6. 面试官系统精讲Java源码及大厂真题 - 48 一起看过的 Java 源码和面试真题
  7. Linux 服务器惊现比特币勒索事件,腾讯云安全专家来支招
  8. C++中的static 成员变量的一些注意点
  9. ckc交易什么意思_1379ip0在股市是什么意思,600875东方电气股票,股市交易手续费计算...
  10. 非参数检验统计量分析
  11. 上海航芯 | 从STM32F103到ACM32F403的U盘程序移植工程
  12. 套件端口 群晖_群晖NAS的各种端口
  13. 博弈论 | 博弈论简谈、常见的博弈定律、巴什博弈
  14. WinRAR 5.5 破解方法 - 自己动手, 更放心
  15. Unity第一视角流血受伤受攻击屏幕流血效果
  16. 文献阅读——金属伪影减少MAR问题
  17. plt 固定X轴、Y轴的范围 ax设置横纵坐标的范围 ax.set_ylim(ymin = 0, ymax = 130)ax.set_xlim(xmin = -5, xmax = 5)
  18. 微信小程序通过PHP控制云开发数据库的写入,读出,更新,删除
  19. 开放式耳机怎么选,最适合佩戴的几款耳机推荐
  20. 安卓优质大作业 前后端 通讯+社区+志愿服务功能

热门文章

  1. 将数组的列表结构转成树结构
  2. c语言追加字符串_Redis源码解析二--简单动态字符串
  3. img之间出现缝隙的原因_神马情况?美缝剂施工出现脱胶是什么原因?
  4. 操作指令详解_爱码小士丨 APP稳定性测试(附视频详解)
  5. 20200707:动态规划专题之不同路径
  6. MS DOS窗口进入JAVA源程序,从java程序运行MS-DOS命令
  7. 服务器不支持mysql_服务器不支持 MySql 数据库的解决方法
  8. 高级工计算机操作试题及答案,计算机系统操作高级工试题和答案[1]
  9. sqlite expert 未找到提供程序。该程序可能未正确安装_SolidWorks2019安装过程中出现常见问题及解决方案...
  10. html中使用style设置背景