<s>
In	O
computing	O
,	O
the	O
Win32	B-Operating_System
Thread	I-Operating_System
Information	I-Operating_System
Block	I-Operating_System
(	O
TIB	O
)	O
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
in	O
Win32	B-Library
on	O
x86	B-Operating_System
that	O
stores	O
information	O
about	O
the	O
currently	O
running	O
thread	B-Operating_System
.	O
</s>
<s>
It	O
is	O
also	O
known	O
as	O
the	O
Thread	B-Operating_System
Environment	I-Operating_System
Block	I-Operating_System
(	O
TEB	O
)	O
for	O
Win32	B-Library
.	O
</s>
<s>
It	O
descended	O
from	O
,	O
and	O
is	O
backward-compatible	O
on	O
32-bit	O
systems	O
with	O
,	O
a	O
similar	O
structure	O
in	O
OS/2	B-Application
.	O
</s>
<s>
The	O
Windows	B-Device
NT	I-Device
series	I-Device
DDK	O
(	O
as	O
well	O
as	O
the	O
MinGW/ReactOS	O
implementation	O
)	O
includes	O
a	O
struct	B-Language
NT_TIB	O
in	O
winnt.h	O
that	O
documents	O
the	O
subsystem	O
independent	O
part	O
.	O
</s>
<s>
Even	O
before	O
TIB	O
was	O
effectively	O
documented	O
,	O
many	O
applications	O
have	O
already	O
started	O
using	O
its	O
fields	O
that	O
they	O
are	O
effectively	O
a	O
part	O
of	O
the	O
API	B-Application
.	O
</s>
<s>
The	O
Win32	B-Library
subsystem-specific	O
part	O
of	O
the	O
TEB	O
is	O
undocumented	O
,	O
but	O
Wine	B-Application
includes	O
a	O
TEB	O
definition	O
in	O
winternl.h.	O
</s>
<s>
The	O
TIB	O
can	O
be	O
used	O
to	O
get	O
a	O
lot	O
of	O
information	O
on	O
the	O
process	O
without	O
calling	O
Win32	B-Library
API	I-Library
.	O
</s>
<s>
Through	O
the	O
pointer	O
to	O
the	O
PEB	B-Data_Structure
one	O
can	O
obtain	O
access	O
to	O
the	O
import	O
tables	O
(	O
IAT	O
)	O
,	O
process	O
startup	O
arguments	O
,	O
image	O
name	O
,	O
etc	O
.	O
</s>
<s>
It	O
is	O
accessed	O
from	O
the	O
FS	O
segment	O
register	B-General_Concept
on	O
32-bit	B-Application
Windows	I-Application
and	O
GS	O
on	O
64-bit	O
Windows	O
.	O
</s>
<s>
This	O
table	O
is	O
based	O
on	O
Wine	B-Application
's	O
work	O
on	O
Microsoft	B-Application
Windows	I-Application
internals	O
.	O
</s>
<s>
Note	O
:	O
the	O
64-bit	O
version	O
of	O
Windows	O
uses	O
stack	B-General_Concept
unwinding	O
done	O
in	O
kernel	O
mode	O
instead.pointerFS:[0x04]GS:[0x08]Win9x	O
and	O
NTStack	O
Base	O
/	O
Bottom	O
of	O
stack	B-General_Concept
(	O
high	O
address	O
)	O
pointerFS:[0x08]GS:[0x10]Win9x	O
and	O
NTStack	O
Limit	O
/	O
Ceiling	O
of	O
stack	B-General_Concept
(	O
low	O
address	O
)	O
pointerFS:[0x0C]GS:[0x18]NTSubSystemTibpointerFS:[0x10]GS:[0x20]NTFiber	O
datapointerFS:[0x14]GS:[0x28]Win9x	O
and	O
NTArbitrary	O
data	O
slotpointerFS:[0x18]GS:[0x30]Win9x	O
and	O
NTLinear	O
address	O
of	O
TEB	O
End	O
of	O
NT	B-Device
subsystem	O
independent	O
part	O
;	O
below	O
are	O
Win32-dependentpointerFS:[0x1C]GS:[0x38]NTEnvironment	O
PointerpointerFS:[0x20]GS:[0x40]NTProcess	O
ID	O
(	O
in	O
some	O
Windows	O
distributions	O
this	O
field	O
is	O
used	O
as	O
'	O
DebugContext	O
 '	O
)	O
pointerFS:[0x24]GS:[0x48]NTCurrent	O
thread	B-Operating_System
IDpointerFS:[0x28]GS:[0x50]NTActive	O
RPC	O
HandlepointerFS:[0x2C]GS:[0x58]Win9x	O
and	O
NTLinear	O
address	O
of	O
the	O
thread-local	O
storage	O
arraypointerFS:[0x30]GS:[0x60]NTLinear	O
address	O
of	O
Process	B-Data_Structure
Environment	I-Data_Structure
Block	I-Data_Structure
(	O
PEB	B-Data_Structure
)	O
4FS:[0x34]GS:[0x68]NTLast	O
error	O
number4FS:[0x38]GS:[0x6C]NTCount	O
of	O
owned	O
critical	O
sectionspointerFS:[0x3C]GS:[0x70]NTAddress	O
of	O
CSR	O
Client	O
ThreadpointerFS:[0x40]GS:[0x78]NTWin32	O
Thread	B-Operating_System
Information124FS:[0x44]GS:[0x80]NT,	O
WineWin32	O
client	O
information	O
(	O
NT	B-Device
)	O
,	O
user32	O
private	O
data	O
(	O
Wine	B-Application
)	O
,	O
0x60	O
=	O
LastError	O
(	O
Win95&98	O
)	O
,	O
0x74	O
=	O
LastError	O
(	O
WinME	O
)	O
pointerFS:[0xC0]GS:[0x100]NTReserved	O
for	O
Wow64	O
.	O
</s>
<s>
Contains	O
a	O
pointer	O
to	O
FastSysCall	O
in	O
Wow64.4FS:[0xC4]GS:[0x108]NTCurrent	O
Locale4FS:[0xC8]GS:[0x10C]NTFP	O
Software	O
Status	O
Register216FS:[0xCC]GS:[0x110]NT,	O
WineReserved	O
for	O
OS	O
(	O
NT	B-Device
)	O
,	O
kernel32	O
private	O
data	O
(	O
Wine	B-Application
)	O
herein	O
:	O
FS:[0x124]	O
4	O
NT	B-Device
Pointer	O
to	O
KTHREAD	O
(	O
ETHREAD	O
)	O
structure	O
4FS:[0x1A4]GS:[0x2C0]NTException	O
code18FS:[0x1A8]GS:[0x2C8]NTActivation	O
context	O
stack24FS:[0x1BC]GS:[0x2E8]NT,	O
WineSpare	O
bytes	O
(	O
NT	B-Device
)	O
,	O
ntdll	O
private	O
data	O
(	O
Wine	B-Application
)	O
40FS:[0x1D4]GS:[0x300]NT,	O
WineReserved	O
for	O
OS	O
(	O
NT	B-Device
)	O
,	O
ntdll	O
private	O
data	O
(	O
Wine	B-Application
)	O
1248FS:[0x1FC]GS:[0x350]NT,	O
WineGDI	O
TEB	O
Batch	O
(	O
OS	O
)	O
,	O
vm86	O
private	O
data	O
(	O
Wine	B-Application
)	O
4FS:[0x6DC]GS:[0x838]NTGDI	O
Region4FS:[0x6E0]GS:[0x840]NTGDI	O
Pen4FS:[0x6E4]GS:[0x848]NTGDI	O
Brush4FS:[0x6E8]GS:[0x850]NTReal	O
Process	O
ID4FS:[0x6EC]GS:[0x858]NTReal	O
Thread	B-Operating_System
ID4FS:[0x6F0]GS:[0x860]NTGDI	O
cached	O
process	O
handle4FS:[0x6F4]GS:[0x868]NTGDI	O
client	O
process	O
ID	O
(	O
PID	O
)	O
4FS:[0x6F8]GS:[0x86C]NTGDI	O
client	O
thread	B-Operating_System
ID	O
(	O
TID	O
)	O
4FS:[0x6FC]GS:[0x870]NTGDI	O
thread	B-Operating_System
locale	O
information20FS:[0x700]GS:[0x878]NTReserved	O
for	O
user	O
application1248FS:[0x714]GS:[0x890]NTReserved	O
for	O
GL	O
(	O
See	O
wine	B-Application
ref	O
for	O
internals	O
)	O
4FS:[0xBF4]GS:[0x1250]NTLast	O
Status	O
Value532FS:[0xBF8]GS:[0x1258]NTStatic	O
UNICODE_STRING	O
bufferpointerFS:[0xE0C]GS:[0x1478]NTAlso	O
known	O
as	O
DeallocationStack	O
,	O
it	O
establishes	O
the	O
real	O
start	O
address	O
of	O
the	O
stack	B-General_Concept
buffer	O
,	O
hence	O
the	O
real	O
stack	B-General_Concept
limit	O
:	O
it	O
is	O
a	O
few	O
pages	O
less	O
than	O
the	O
stack	B-General_Concept
limit	O
field	O
(	O
which	O
hides	O
the	O
guard	O
pages	O
used	O
to	O
detect	O
stack	B-General_Concept
overflows	O
)	O
.pointer[]FS:[0xE10]GS:[0x1480]NTTLS	O
slots	O
,	O
4/8	O
bytes	O
per	O
slot	O
,	O
64	O
slots8FS:[0xF10]GS:[0x1680]NTTLS	O
links	O
(	O
LIST_ENTRY	O
structure	O
)	O
4FS:[0xF18]GS:[0x1690]NTVDM4FS:[0xF1C]GS:[0x1698]NTReserved	O
for	O
RPC4FS:[0xF28]GS:[0x16B0]NTThread	O
error	O
mode	O
(	O
RtlSetThreadErrorMode	O
)	O
4FS:[0xF78]GS:[0x1748]NTGuaranteed	O
stack	B-General_Concept
bytes	O
This	O
is	O
not	O
the	O
full	O
table	O
;	O
see	O
wine	B-Application
ref	O
for	O
all	O
fields	O
until	O
FS:[0xfb4]	O
/	O
GS:[17c8]	O
.	O
</s>
<s>
FS	O
(	O
for	O
32-bit	O
)	O
or	O
GS	O
(	O
for	O
64-bit	O
)	O
maps	O
to	O
a	O
TIB	O
which	O
is	O
embedded	O
in	O
a	O
data	O
block	O
known	O
as	O
the	O
TDB	O
(	O
thread	B-Operating_System
data	O
base	O
)	O
.	O
</s>
<s>
The	O
TIB	O
contains	O
the	O
thread-specific	O
exception	O
handling	O
chain	O
and	O
pointer	O
to	O
the	O
TLS	O
(	O
thread	B-Operating_System
local	O
storage	O
.	O
)	O
</s>
<s>
The	O
thread	B-Operating_System
local	O
storage	O
is	O
not	O
the	O
same	O
as	O
C	O
local	O
storage	O
.	O
</s>
<s>
A	O
process	O
should	O
be	O
free	O
to	O
move	O
the	O
stack	B-General_Concept
of	O
its	O
threads	B-Operating_System
as	O
long	O
as	O
it	O
updates	O
the	O
information	O
stored	O
in	O
the	O
TIB	O
accordingly	O
.	O
</s>
<s>
A	O
few	O
fields	O
are	O
key	O
to	O
this	O
matter	O
:	O
stack	B-General_Concept
base	O
,	O
stack	B-General_Concept
limit	O
,	O
deallocation	O
stack	B-General_Concept
,	O
and	O
guaranteed	O
stack	B-General_Concept
bytes	O
,	O
respectively	O
stored	O
at	O
offsets	O
0x8	O
,	O
0x10	O
,	O
0x1478	O
and	O
0x1748	O
in	O
64	O
bits	O
.	O
</s>
<s>
Different	O
Windows	O
kernel	O
functions	O
read	O
and	O
write	O
these	O
values	O
,	O
specially	O
to	O
distinguish	O
stack	B-General_Concept
overflows	O
from	O
other	O
read/write	O
page	O
faults	O
(	O
a	O
read	O
or	O
write	O
to	O
a	O
page	O
guarded	O
among	O
the	O
stack	B-General_Concept
limits	O
in	O
guaranteed	O
stack	B-General_Concept
bytes	O
will	O
generate	O
a	O
stack-overflow	O
exception	O
instead	O
of	O
an	O
access	O
violation	O
)	O
.	O
</s>
<s>
The	O
deallocation	O
stack	B-General_Concept
is	O
important	O
because	O
Windows	B-Library
API	I-Library
allows	O
to	O
change	O
the	O
amount	O
of	O
guarded	O
pages	O
:	O
the	O
function	O
SetThreadStackGuarantee	O
allows	O
both	O
read	O
the	O
current	O
space	O
and	O
to	O
grow	O
it	O
.	O
</s>
<s>
In	O
order	O
to	O
read	O
it	O
,	O
it	O
reads	O
the	O
GuaranteedStackBytes	O
field	O
,	O
and	O
to	O
grow	O
it	O
,	O
it	O
uses	O
has	O
to	O
uncommit	O
stack	B-General_Concept
pages	O
.	O
</s>
<s>
Setting	O
stack	B-General_Concept
limits	O
without	O
setting	O
DeallocationStack	O
will	O
probably	O
cause	O
odd	O
behavior	O
in	O
SetThreadStackGuarantee	O
.	O
</s>
<s>
For	O
example	O
,	O
it	O
will	O
overwrite	O
the	O
stack	B-General_Concept
limits	O
to	O
wrong	O
values	O
.	O
</s>
<s>
Different	O
libraries	O
call	O
SetThreadStackGuarantee	O
,	O
for	O
example	O
the	O
.NET	O
CLR	O
uses	O
it	O
for	O
setting	O
up	O
the	O
stack	B-General_Concept
of	O
their	O
threads	B-Operating_System
.	O
</s>
<s>
The	O
TIB	O
of	O
the	O
current	O
thread	B-Operating_System
can	O
be	O
accessed	O
as	O
an	O
offset	O
of	O
segment	O
register	B-General_Concept
FS	O
(	O
x86	B-Operating_System
)	O
or	O
GS	O
(	O
x64	O
)	O
.	O
</s>
<s>
That	O
pointer	O
can	O
be	O
used	O
with	O
pointer	O
arithmetic	O
or	O
be	O
cast	O
to	O
a	O
struct	B-Language
pointer	O
.	O
</s>
<s>
Using	O
Microsoft	B-Application
Windows	I-Application
SDK	I-Application
or	O
similar	O
,	O
a	O
programmer	O
could	O
use	O
an	O
inline	O
function	O
defined	O
in	O
winnt.h	O
named	O
NtCurrentTeb	O
which	O
returns	O
the	O
address	O
of	O
the	O
current	O
Thread	B-Operating_System
Information	I-Operating_System
Block	I-Operating_System
as	O
NT_TIB	O
*	O
.	O
</s>
<s>
Alternative	O
methods	O
of	O
access	O
for	O
IA-32	B-Device
architectures	O
are	O
as	O
follows	O
:	O
</s>
