<s>
The	O
Global	O
Descriptor	O
Table	O
(	O
GDT	O
)	O
is	O
a	O
data	O
structure	O
used	O
by	O
Intel	O
x86-family	O
processors	O
starting	O
with	O
the	O
80286	B-General_Concept
in	O
order	O
to	O
define	O
the	O
characteristics	O
of	O
the	O
various	O
memory	O
areas	O
used	O
during	O
program	O
execution	O
,	O
including	O
the	O
base	O
address	O
,	O
the	O
size	O
,	O
and	O
access	O
privileges	O
like	O
executability	O
and	O
writability	O
.	O
</s>
<s>
These	O
memory	O
areas	O
are	O
called	O
segments	B-Device
in	O
Intel	O
terminology	O
.	O
</s>
<s>
Each	O
entry	O
may	O
refer	O
to	O
a	O
segment	B-Operating_System
descriptor	I-Operating_System
,	O
Task	B-Device
State	I-Device
Segment	I-Device
(	O
TSS	B-Device
)	O
,	O
Local	B-General_Concept
Descriptor	I-General_Concept
Table	I-General_Concept
(	O
LDT	O
)	O
,	O
or	O
call	B-Device
gate	I-Device
.	O
</s>
<s>
Call	B-Device
gates	I-Device
were	O
designed	O
for	O
transferring	O
control	O
between	O
x86	B-Operating_System
privilege	O
levels	O
,	O
although	O
this	O
mechanism	O
is	O
not	O
used	O
on	O
most	O
modern	O
operating	B-General_Concept
systems	I-General_Concept
.	O
</s>
<s>
There	O
is	O
also	O
a	O
Local	B-General_Concept
Descriptor	I-General_Concept
Table	I-General_Concept
(	O
LDT	O
)	O
.	O
</s>
<s>
While	O
the	O
LDT	O
contains	O
memory	B-General_Concept
segments	I-General_Concept
which	O
are	O
private	O
to	O
a	O
specific	O
process	O
,	O
the	O
GDT	O
contains	O
global	O
segments	B-Device
.	O
</s>
<s>
The	O
x86	B-Operating_System
processors	O
have	O
facilities	O
for	O
automatically	O
switching	O
the	O
current	O
LDT	O
on	O
specific	O
machine	O
events	O
,	O
but	O
no	O
facilities	O
for	O
automatically	O
switching	O
the	O
GDT	O
.	O
</s>
<s>
On	O
the	O
80386	B-General_Concept
processor	O
and	O
later	O
,	O
because	O
of	O
32-bit	O
segment	O
offsets	O
and	O
limits	O
,	O
it	O
is	O
possible	O
to	O
make	O
segments	B-Device
cover	O
the	O
entire	O
addressable	O
memory	O
,	O
which	O
makes	O
segment-relative	O
addressing	O
transparent	O
to	O
the	O
user	O
.	O
</s>
<s>
Such	O
an	O
index	O
is	O
called	O
a	O
segment	B-Device
selector	I-Device
(	O
or	O
selector	O
)	O
.	O
</s>
<s>
The	O
selector	O
must	O
be	O
loaded	O
into	O
a	O
segment	B-General_Concept
register	I-General_Concept
to	O
be	O
used	O
.	O
</s>
<s>
Apart	O
from	O
the	O
machine	O
instructions	O
which	O
allow	O
one	O
to	O
set/get	O
the	O
position	O
of	O
the	O
GDT	O
,	O
and	O
of	O
the	O
Interrupt	B-General_Concept
Descriptor	I-General_Concept
Table	I-General_Concept
(	O
IDT	O
)	O
,	O
in	O
memory	O
,	O
every	O
machine	O
instruction	O
referencing	O
memory	O
has	O
an	O
implicit	O
segment	B-General_Concept
register	I-General_Concept
,	O
occasionally	O
two	O
.	O
</s>
<s>
Most	O
of	O
the	O
time	O
this	O
segment	B-General_Concept
register	I-General_Concept
can	O
be	O
overridden	O
by	O
adding	O
a	O
segment	O
prefix	O
before	O
the	O
instruction	O
.	O
</s>
<s>
Loading	O
a	O
selector	O
into	O
a	O
segment	B-General_Concept
register	I-General_Concept
reads	O
the	O
GDT	O
or	O
LDT	O
entry	O
at	O
the	O
time	O
it	O
is	O
loaded	O
,	O
and	O
caches	O
the	O
properties	O
of	O
the	O
segment	O
in	O
a	O
hidden	O
register	O
.	O
</s>
<s>
Subsequent	O
modifications	O
to	O
the	O
GDT	O
or	O
LDT	O
will	O
not	O
take	O
effect	O
until	O
the	O
segment	B-General_Concept
register	I-General_Concept
is	O
reloaded	O
.	O
</s>
<s>
The	O
GDT	O
is	O
still	O
present	O
in	O
64-bit	O
mode	O
;	O
a	O
GDT	O
must	O
be	O
defined	O
,	O
but	O
is	O
generally	O
never	O
changed	O
or	O
used	O
for	O
segmentation	B-General_Concept
.	O
</s>
<s>
However	O
,	O
the	O
base	O
of	O
FS	B-Device
and	I-Device
GS	I-Device
are	O
not	O
constrained	O
to	O
0	O
,	O
and	O
they	O
continue	O
to	O
be	O
used	O
as	O
pointers	O
to	O
the	O
offset	O
of	O
items	O
such	O
as	O
the	O
process	O
environment	O
block	O
and	O
the	O
thread	O
information	O
block	O
.	O
</s>
<s>
This	O
is	O
because	O
,	O
even	O
though	O
code/data	O
segments	B-Device
are	O
ignored	O
,	O
TSS	B-Device
are	O
not	O
,	O
but	O
the	O
TSS	B-Device
pointer	O
can	O
be	O
64bit	O
long	O
and	O
thus	O
the	O
descriptor	O
needs	O
more	O
space	O
to	O
insert	O
the	O
higher	O
dword	O
of	O
the	O
TSS	B-Device
pointer	O
.	O
</s>
<s>
64-bit	O
versions	O
of	O
Windows	O
forbid	O
hooking	O
of	O
the	O
GDT	O
;	O
attempting	O
to	O
do	O
so	O
will	O
cause	O
the	O
machine	O
to	O
bug	B-Error_Name
check	I-Error_Name
.	O
</s>
<s>
A	O
Local	B-General_Concept
Descriptor	I-General_Concept
Table	I-General_Concept
(	O
LDT	O
)	O
is	O
a	O
memory	O
table	O
used	O
in	O
the	O
x86	B-Operating_System
architecture	I-Operating_System
in	O
protected	B-Application
mode	I-Application
and	O
containing	O
memory	B-General_Concept
segment	I-General_Concept
descriptors	O
,	O
just	O
like	O
the	O
GDT	O
:	O
address	O
start	O
in	O
linear	O
memory	O
,	O
size	O
,	O
executability	O
,	O
writability	O
,	O
access	O
privilege	O
,	O
actual	O
presence	O
in	O
memory	O
,	O
etc	O
.	O
</s>
<s>
LDTs	O
are	O
the	O
siblings	O
of	O
the	O
Global	O
Descriptor	O
Table	O
(	O
GDT	O
)	O
,	O
and	O
each	O
define	O
up	O
to	O
8192	O
memory	B-General_Concept
segments	I-General_Concept
accessible	O
to	O
programs	O
-	O
note	O
that	O
unlike	O
the	O
GDT	O
,	O
the	O
zeroeth	O
entry	O
is	O
a	O
valid	O
entry	O
,	O
and	O
can	O
be	O
used	O
like	O
any	O
other	O
LDT	O
entry	O
.	O
</s>
<s>
Also	O
note	O
that	O
unlike	O
the	O
GDT	O
,	O
the	O
LDT	O
cannot	O
be	O
used	O
to	O
store	O
certain	O
system	O
entries	O
:	O
TSSs	B-Device
or	O
LDTs	O
.	O
</s>
<s>
Call	B-Device
Gates	I-Device
and	O
Task	B-Device
Gates	I-Device
are	O
fine	O
,	O
however	O
.	O
</s>
<s>
On	O
x86	B-Operating_System
processors	O
not	O
having	O
paging	B-Architecture
features	O
,	O
like	O
the	O
Intel	B-General_Concept
80286	I-General_Concept
,	O
the	O
LDT	O
is	O
essential	O
to	O
implementing	O
separate	O
address	B-General_Concept
spaces	I-General_Concept
for	O
multiple	O
processes	O
.	O
</s>
<s>
There	O
will	O
be	O
generally	O
one	O
LDT	O
per	O
user	O
process	O
,	O
describing	O
privately	O
held	O
memory	O
,	O
while	O
shared	B-Operating_System
memory	I-Operating_System
and	O
kernel	B-Operating_System
memory	O
will	O
be	O
described	O
by	O
the	O
GDT	O
.	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
will	O
switch	O
the	O
current	O
LDT	O
when	O
scheduling	O
a	O
new	O
process	O
,	O
using	O
the	O
LLDT	O
machine	O
instruction	O
or	O
when	O
using	O
a	O
TSS	B-Device
.	O
</s>
<s>
On	O
the	O
contrary	O
,	O
the	O
GDT	O
is	O
generally	O
not	O
switched	O
(	O
although	O
this	O
may	O
happen	O
if	O
virtual	B-Operating_System
machine	I-Operating_System
monitors	I-Operating_System
like	O
VMware	O
are	O
running	O
on	O
the	O
computer	O
)	O
.	O
</s>
<s>
The	O
lack	O
of	O
symmetry	O
between	O
both	O
tables	O
is	O
underlined	O
by	O
the	O
fact	O
that	O
the	O
current	O
LDT	O
can	O
be	O
automatically	O
switched	O
on	O
certain	O
events	O
,	O
notably	O
if	O
TSS-based	O
multitasking	O
is	O
used	O
,	O
while	O
this	O
is	O
not	O
possible	O
for	O
the	O
GDT	O
.	O
</s>
<s>
The	O
LDT	O
also	O
cannot	O
store	O
certain	O
privileged	O
types	O
of	O
memory	B-General_Concept
segments	I-General_Concept
(	O
e.g.	O
</s>
<s>
Creating	O
shared	B-Operating_System
memory	I-Operating_System
through	O
the	O
GDT	O
has	O
some	O
drawbacks	O
.	O
</s>
<s>
In	O
order	O
to	O
restrict	O
visibility	O
and	O
to	O
differentiate	O
the	O
protection	O
of	O
shared	B-Operating_System
memory	I-Operating_System
,	O
for	O
example	O
to	O
only	O
allow	O
read-only	O
access	O
for	O
some	O
processes	O
,	O
one	O
can	O
use	O
separate	O
LDT	O
entries	O
,	O
pointed	O
at	O
the	O
same	O
physical	O
memory	O
areas	O
and	O
only	O
created	O
in	O
the	O
LDTs	O
of	O
processes	O
which	O
have	O
requested	O
access	O
to	O
a	O
given	O
shared	B-Operating_System
memory	I-Operating_System
area	O
.	O
</s>
<s>
Aliases	O
are	O
also	O
typically	O
created	O
in	O
order	O
to	O
get	O
write	O
access	O
to	O
code	B-General_Concept
segments	I-General_Concept
:	O
an	O
executable	O
selector	O
cannot	O
be	O
used	O
for	O
writing	O
.	O
</s>
<s>
(	O
Protected	B-Application
mode	I-Application
programs	O
constructed	O
in	O
the	O
so-called	O
tiny	O
memory	B-General_Concept
model	I-General_Concept
,	O
where	O
everything	O
is	O
located	O
in	O
the	O
same	O
memory	B-General_Concept
segment	I-General_Concept
,	O
must	O
use	O
separate	O
selectors	O
for	O
code	O
and	O
data/stack	O
,	O
making	O
both	O
selectors	O
technically	O
"	O
aliases	O
"	O
as	O
well	O
.	O
)	O
</s>
<s>
In	O
the	O
case	O
of	O
the	O
GDT	O
,	O
aliases	O
are	O
also	O
created	O
in	O
order	O
to	O
get	O
access	O
to	O
system	O
segments	B-Device
like	O
the	O
TSSes	O
.	O
</s>
<s>
Segments	B-Device
have	O
a	O
"	O
Present	O
"	O
flag	O
in	O
their	O
descriptors	O
,	O
allowing	O
them	O
to	O
be	O
removed	O
from	O
memory	O
if	O
the	O
need	O
arises	O
.	O
</s>
<s>
For	O
example	O
,	O
code	B-General_Concept
segments	I-General_Concept
or	O
unmodified	O
data	O
segments	B-Device
can	O
be	O
thrown	O
away	O
,	O
and	O
modified	O
data	O
segments	B-Device
can	O
be	O
swapped	O
out	O
to	O
disk	O
.	O
</s>
<s>
However	O
,	O
because	O
entire	O
segments	B-Device
need	O
to	O
be	O
operated	O
on	O
as	O
a	O
unit	O
,	O
it	O
is	O
necessary	O
to	O
limit	O
their	O
size	O
in	O
order	O
to	O
ensure	O
that	O
swapping	O
can	O
happen	O
in	O
a	O
timely	O
fashion	O
.	O
</s>
<s>
However	O
,	O
using	O
smaller	O
,	O
more	O
easily	O
swappable	O
segments	B-Device
means	O
that	O
segment	B-General_Concept
registers	I-General_Concept
must	O
be	O
reloaded	O
more	O
frequently	O
which	O
is	O
itself	O
a	O
time-consuming	O
operation	O
.	O
</s>
<s>
The	O
Intel	B-General_Concept
80386	I-General_Concept
microprocessor	O
introduced	O
paging	B-Architecture
-	O
allocating	O
separate	O
physical	O
memory	O
pages	O
(	O
themselves	O
very	O
small	O
units	O
of	O
memory	O
)	O
at	O
the	O
same	O
virtual	O
addresses	O
,	O
with	O
the	O
advantage	O
that	O
disk	O
paging	B-Architecture
is	O
far	O
faster	O
and	O
more	O
efficient	O
than	O
segment	O
swapping	O
.	O
</s>
<s>
Therefore	O
,	O
modern	O
32-bit	O
x86	B-Operating_System
operating	B-General_Concept
systems	I-General_Concept
use	O
the	O
LDT	O
very	O
little	O
,	O
primarily	O
to	O
run	O
legacy	O
16-bit	B-Device
code	O
.	O
</s>
<s>
Should	O
16-bit	B-Device
code	O
need	O
to	O
run	O
in	O
a	O
32-bit	O
environment	O
while	O
sharing	O
memory	O
(	O
this	O
happens	O
e.g.	O
</s>
<s>
when	O
running	O
OS/2	B-Application
1.x	O
programs	O
on	O
OS/2	B-Application
2.0	O
and	O
later	O
)	O
,	O
the	O
LDT	O
must	O
be	O
written	O
in	O
such	O
a	O
way	O
that	O
every	O
flat	O
(	O
paged	O
)	O
address	O
has	O
also	O
a	O
selector	O
in	O
the	O
LDT	O
(	O
typically	O
this	O
results	O
in	O
the	O
LDT	O
being	O
filled	O
with	O
64	O
KiB	O
entries	O
)	O
.	O
</s>
<s>
The	O
limited	O
size	O
of	O
the	O
LDT	O
means	O
the	O
virtual	O
flat	O
address	B-General_Concept
space	I-General_Concept
has	O
to	O
be	O
limited	O
to	O
512	O
megabytes	O
(	O
8191	O
times	O
64	O
KiB	O
)	O
-	O
this	O
is	O
what	O
happens	O
on	O
OS/2	B-Application
,	O
although	O
this	O
limitation	O
was	O
fixed	O
in	O
version	O
4.5	O
.	O
</s>
<s>
It	O
is	O
also	O
necessary	O
to	O
make	O
sure	O
that	O
objects	O
allocated	O
in	O
the	O
32-bit	O
environment	O
do	O
not	O
cross	O
64	O
KiB	O
boundaries	O
;	O
this	O
generates	O
some	O
address	B-General_Concept
space	I-General_Concept
waste	O
.	O
</s>
<s>
If	O
32-bit	O
code	O
does	O
not	O
have	O
to	O
pass	O
arbitrary	O
memory	O
objects	O
to	O
16-bit	B-Device
code	O
,	O
e.g.	O
</s>
<s>
presumably	O
in	O
the	O
OS/2	B-Application
1.x	O
emulation	O
present	O
in	O
Windows	B-Device
NT	I-Device
or	O
in	O
the	O
Windows	O
3.1	O
emulation	B-Application
layer	I-Application
,	O
it	O
is	O
not	O
necessary	O
to	O
artificially	O
limit	O
the	O
size	O
of	O
the	O
32-bit	O
address	B-General_Concept
space	I-General_Concept
.	O
</s>
