<s>
In	O
computer	O
systems	O
a	O
loader	B-Operating_System
is	O
the	O
part	O
of	O
an	O
operating	B-General_Concept
system	I-General_Concept
that	O
is	O
responsible	O
for	O
loading	O
programs	B-Application
and	O
libraries	B-Library
.	O
</s>
<s>
It	O
is	O
one	O
of	O
the	O
essential	O
stages	O
in	O
the	O
process	O
of	O
starting	O
a	O
program	O
,	O
as	O
it	O
places	O
programs	B-Application
into	O
memory	O
and	O
prepares	O
them	O
for	O
execution	O
.	O
</s>
<s>
Loading	O
a	O
program	O
involves	O
either	O
memory-mapping	B-General_Concept
or	O
copying	O
the	O
contents	O
of	O
the	O
executable	B-Application
file	I-Application
containing	O
the	O
program	O
instructions	O
into	O
memory	O
,	O
and	O
then	O
carrying	O
out	O
other	O
required	O
preparatory	O
tasks	O
to	O
prepare	O
the	O
executable	B-Application
for	O
running	O
.	O
</s>
<s>
Once	O
loading	O
is	O
complete	O
,	O
the	O
operating	B-General_Concept
system	I-General_Concept
starts	O
the	O
program	O
by	O
passing	O
control	O
to	O
the	O
loaded	O
program	O
code	O
.	O
</s>
<s>
All	O
operating	B-General_Concept
systems	I-General_Concept
that	O
support	O
program	O
loading	O
have	O
loaders	B-Operating_System
,	O
apart	O
from	O
highly	O
specialized	O
computer	O
systems	O
that	O
only	O
have	O
a	O
fixed	O
set	O
of	O
specialized	O
programs	B-Application
.	O
</s>
<s>
Embedded	B-Architecture
systems	I-Architecture
typically	O
do	O
not	O
have	O
loaders	B-Operating_System
,	O
and	O
instead	O
,	O
the	O
code	O
executes	O
directly	O
from	O
ROM	O
or	O
similar	O
.	O
</s>
<s>
In	O
order	O
to	O
load	O
the	O
operating	B-General_Concept
system	I-General_Concept
itself	O
,	O
as	O
part	O
of	O
booting	B-Operating_System
,	O
a	O
specialized	O
boot	B-Application
loader	I-Application
is	O
used	O
.	O
</s>
<s>
In	O
many	O
operating	B-General_Concept
systems	I-General_Concept
,	O
the	O
loader	B-Operating_System
resides	O
permanently	O
in	O
memory	O
,	O
though	O
some	O
operating	B-General_Concept
systems	I-General_Concept
that	O
support	O
virtual	B-Architecture
memory	I-Architecture
may	O
allow	O
the	O
loader	B-Operating_System
to	O
be	O
located	O
in	O
a	O
region	O
of	O
memory	O
that	O
is	O
pageable	B-Architecture
.	O
</s>
<s>
In	O
the	O
case	O
of	O
operating	B-General_Concept
systems	I-General_Concept
that	O
support	O
virtual	B-Architecture
memory	I-Architecture
,	O
the	O
loader	B-Operating_System
may	O
not	O
actually	O
copy	O
the	O
contents	O
of	O
executable	B-Application
files	I-Application
into	O
memory	O
,	O
but	O
rather	O
may	O
simply	O
declare	O
to	O
the	O
virtual	B-Architecture
memory	I-Architecture
subsystem	O
that	O
there	O
is	O
a	O
mapping	O
between	O
a	O
region	O
of	O
memory	O
allocated	O
to	O
contain	O
the	O
running	O
program	O
's	O
code	O
and	O
the	O
contents	O
of	O
the	O
associated	O
executable	B-Application
file	I-Application
.	O
</s>
<s>
(	O
See	O
memory-mapped	B-General_Concept
file	I-General_Concept
.	O
)	O
</s>
<s>
The	O
virtual	B-Architecture
memory	I-Architecture
subsystem	O
is	O
then	O
made	O
aware	O
that	O
pages	O
with	O
that	O
region	O
of	O
memory	O
need	O
to	O
be	O
filled	O
on	O
demand	O
if	O
and	O
when	O
program	O
execution	O
actually	O
hits	O
those	O
areas	O
of	O
unfilled	O
memory	O
.	O
</s>
<s>
In	O
Unix	B-Application
,	O
the	O
loader	B-Operating_System
is	O
the	O
handler	O
for	O
the	O
system	B-Operating_System
call	I-Operating_System
execve( )	O
.	O
</s>
<s>
The	O
Unix	B-Application
loader	B-Operating_System
's	O
tasks	O
include	O
:	O
</s>
<s>
memory-mapping	B-General_Concept
the	O
executable	B-Application
object	O
from	O
the	O
disk	O
into	O
main	O
memory	O
;	O
</s>
<s>
copying	O
the	O
command-line	O
arguments	O
into	O
virtual	B-Architecture
memory	I-Architecture
;	O
</s>
<s>
initializing	O
registers	B-General_Concept
(	O
e.g.	O
,	O
the	O
stack	O
pointer	O
)	O
;	O
</s>
<s>
In	O
Microsoft	B-Application
Windows	I-Application
7	O
and	O
above	O
,	O
the	O
loader	B-Operating_System
is	O
the	O
LdrInitializeThunk	O
function	O
contained	O
in	O
ntdll.dll	B-Application
,	O
that	O
does	O
the	O
following	O
:	O
</s>
<s>
critical	B-Operating_System
sections	I-Operating_System
,	O
module	O
lists	O
)	O
;	O
</s>
<s>
validation	O
of	O
executable	B-Application
to	O
load	O
;	O
</s>
<s>
creation	O
of	O
a	O
heap	B-General_Concept
(	O
via	O
the	O
function	O
RtlCreateHeap	O
)	O
;	O
</s>
<s>
addition	O
of	O
executable	B-Application
and	O
NTDLL	B-Application
to	O
the	O
module	O
list	O
(	O
a	O
doubly-linked	B-Data_Structure
list	I-Data_Structure
)	O
;	O
</s>
<s>
loading	O
of	O
executable	B-Application
's	O
imports	O
(	O
i.e.	O
</s>
<s>
dynamic-link	O
libraries	B-Library
)	O
recursively	O
(	O
check	O
the	O
imports	O
 '	O
imports	O
,	O
their	O
imports	O
and	O
so	O
on	O
)	O
;	O
</s>
<s>
calling	O
NtContinue	O
on	O
the	O
context	O
parameter	O
given	O
to	O
the	O
loader	B-Operating_System
function	O
(	O
i.e.	O
</s>
<s>
Some	O
operating	B-General_Concept
systems	I-General_Concept
need	O
relocating	B-Library
loaders	I-Library
,	O
which	O
adjust	O
addresses	O
(	O
pointers	O
)	O
in	O
the	O
executable	B-Application
to	O
compensate	O
for	O
variations	O
in	O
the	O
address	O
at	O
which	O
loading	O
starts	O
.	O
</s>
<s>
The	O
operating	B-General_Concept
systems	I-General_Concept
that	O
need	O
relocating	B-Library
loaders	I-Library
are	O
those	O
in	O
which	O
a	O
program	O
is	O
not	O
always	O
loaded	O
into	O
the	O
same	O
location	O
in	O
the	O
(	O
virtual	O
)	O
address	O
space	O
and	O
in	O
which	O
pointers	O
are	O
absolute	O
addresses	O
rather	O
than	O
offsets	O
from	O
the	O
program	O
's	O
base	B-General_Concept
address	I-General_Concept
.	O
</s>
<s>
Some	O
well-known	O
examples	O
are	O
IBM	O
's	O
OS/360	B-Application
for	O
their	O
System/360	B-Application
mainframes	O
,	O
and	O
its	O
descendants	O
,	O
including	O
z/OS	B-Application
for	O
the	O
z/Architecture	B-Device
mainframes	O
.	O
</s>
<s>
In	O
OS/360	B-Application
and	O
descendant	O
systems	O
,	O
the	O
(	O
privileged	O
)	O
operating	B-General_Concept
system	I-General_Concept
facility	O
is	O
called	O
IEWFETCH	O
,	O
and	O
is	O
an	O
internal	O
component	O
of	O
the	O
OS	O
Supervisor	O
,	O
whereas	O
the	O
(	O
non-privileged	O
)	O
LOADER	B-Operating_System
application	O
can	O
perform	O
many	O
of	O
the	O
same	O
functions	O
,	O
plus	O
those	O
of	O
the	O
Linkage	O
Editor	O
,	O
and	O
is	O
entirely	O
external	O
to	O
the	O
OS	O
Supervisor	O
(	O
although	O
it	O
certainly	O
uses	O
many	O
Supervisor	O
services	O
)	O
.	O
</s>
<s>
IEWFETCH	O
utilizes	O
highly	O
specialized	O
channel	O
programs	B-Application
,	O
and	O
it	O
is	O
theoretically	O
possible	O
to	O
load	O
and	O
to	O
relocate	O
an	O
entire	O
executable	B-Application
within	O
one	O
revolution	O
of	O
the	O
DASD	O
media	O
(	O
about	O
16.6ms	O
maximum	O
,	O
8.3ms	O
average	O
,	O
on	O
"	O
legacy	O
"	O
3,600	O
rpm	O
drives	O
)	O
.	O
</s>
<s>
IEWFETCH	O
also	O
incorporates	O
facilities	O
for	O
so-called	O
overlay	O
structures	O
,	O
and	O
which	O
facilitates	O
running	O
potentially	O
very	O
large	O
executables	B-Application
in	O
a	O
minimum	O
memory	O
model	O
(	O
as	O
small	O
as	O
44KB	O
on	O
some	O
versions	O
of	O
the	O
OS	O
,	O
but	O
88KB	O
and	O
128KB	O
are	O
more	O
common	O
)	O
.	O
</s>
<s>
The	O
OS	O
's	O
nucleus	B-Operating_System
(	O
the	O
always	O
resident	O
portion	O
of	O
the	O
Supervisor	O
)	O
itself	O
is	O
formatted	O
in	O
a	O
way	O
that	O
is	O
compatible	O
with	O
a	O
stripped-down	O
version	O
of	O
IEWFETCH	O
.	O
</s>
<s>
Unlike	O
normal	O
executables	B-Application
,	O
the	O
OS	O
's	O
nucleus	B-Operating_System
is	O
"	O
scatter	O
loaded	O
"	O
:	O
parts	O
of	O
the	O
nucleus	B-Operating_System
are	O
loaded	O
into	O
different	O
portions	O
of	O
memory	O
;	O
in	O
particular	O
,	O
certain	O
system	O
tables	O
are	O
required	O
to	O
reside	O
below	O
the	O
initial	O
64KB	O
,	O
while	O
other	O
tables	O
and	O
code	O
may	O
reside	O
elsewhere	O
.	O
</s>
<s>
IEWL	O
's	O
main	O
function	O
is	O
to	O
associate	O
load	O
modules	O
(	O
executable	B-Application
programs	I-Application
)	O
and	O
object	O
modules	O
(	O
the	O
output	O
from	O
,	O
say	O
,	O
assemblers	O
and	O
compilers	O
)	O
,	O
including	O
"	O
automatic	O
calls	O
"	O
to	O
libraries	B-Library
(	O
high-level	O
language	O
"	O
built-in	O
functions	O
"	O
)	O
,	O
into	O
a	O
format	O
which	O
may	O
be	O
most	O
efficiently	O
loaded	O
by	O
IEWFETCH	O
.	O
</s>
<s>
The	O
load	O
module	O
format	O
includes	O
an	O
initial	O
"	O
text	O
record	O
"	O
,	O
followed	O
immediately	O
by	O
the	O
"	O
relocation	B-Library
and/or	O
control	O
record	O
"	O
for	O
that	O
text	O
record	O
,	O
followed	O
by	O
more	O
instances	O
of	O
text	O
record	O
and	O
relocation	B-Library
and/or	O
control	O
record	O
pairs	O
,	O
until	O
the	O
end	O
of	O
the	O
module	O
.	O
</s>
<s>
The	O
text	O
records	O
are	O
usually	O
very	O
large	O
;	O
the	O
relocation	B-Library
and/or	O
control	O
records	O
are	O
small	O
as	O
IEWFETCH	O
's	O
three	O
relocation	B-Library
and/or	O
control	O
record	O
buffers	O
are	O
fixed	O
at	O
260	O
bytes	O
(	O
smaller	O
relocation	B-Library
and/or	O
control	O
records	O
are	O
certainly	O
possible	O
,	O
but	O
260	O
bytes	O
is	O
the	O
maximum	O
possible	O
,	O
and	O
IEWL	O
ensures	O
that	O
this	O
limitation	O
is	O
complied	O
with	O
,	O
by	O
inserting	O
additional	O
relocation	B-Library
records	O
,	O
as	O
required	O
,	O
before	O
the	O
next	O
text	O
record	O
,	O
if	O
necessary	O
;	O
in	O
this	O
special	O
case	O
,	O
the	O
sequence	O
of	O
records	O
may	O
be	O
:	O
...	O
,	O
text	O
record	O
,	O
relocation	B-Library
record	O
,	O
...	O
,	O
control	O
record	O
,	O
text	O
record	O
,	O
...	O
)	O
.	O
</s>
<s>
A	O
special	O
byte	O
within	O
the	O
relocation	B-Library
and/or	O
control	O
record	O
buffer	O
is	O
used	O
as	O
a	O
"	O
disabled	O
bit	O
spin	O
"	O
communication	O
area	O
,	O
and	O
is	O
initialized	O
to	O
a	O
unique	O
value	O
.	O
</s>
<s>
The	O
Read	O
CCW	O
for	O
that	O
relocation	B-Library
and/or	O
control	O
record	O
has	O
the	O
Program	O
Controlled	O
Interrupt	O
bit	O
set	O
.	O
</s>
<s>
The	O
processor	O
is	O
thereby	O
notified	O
when	O
that	O
CCW	O
has	O
been	O
accessed	O
by	O
the	O
channel	O
via	O
a	O
special	O
IOS	B-Application
exit	O
.	O
</s>
<s>
Once	O
that	O
byte	O
changes	O
from	O
its	O
initialized	O
value	O
,	O
the	O
CPU	O
exits	O
the	O
bit	O
spin	O
,	O
and	O
relocation	B-Library
occurs	O
,	O
during	O
the	O
"	O
gap	O
"	O
within	O
the	O
media	O
between	O
the	O
relocation	B-Library
and/or	O
control	O
record	O
and	O
the	O
next	O
text	O
record	O
.	O
</s>
<s>
If	O
relocation	B-Library
is	O
finished	O
before	O
the	O
next	O
record	O
,	O
the	O
NOP	O
CCW	O
following	O
the	O
Read	O
will	O
be	O
changed	O
to	O
a	O
TIC	O
,	O
and	O
loading	O
and	O
relocating	O
will	O
proceed	O
using	O
the	O
next	O
buffer	O
;	O
if	O
not	O
,	O
then	O
the	O
channel	O
will	O
stop	O
at	O
the	O
NOP	O
CCW	O
,	O
until	O
it	O
is	O
restarted	O
by	O
IEWFETCH	O
via	O
another	O
special	O
IOS	B-Application
exit	O
.	O
</s>
<s>
Dynamic	B-Application
linking	I-Application
loaders	I-Application
are	O
another	O
type	O
of	O
loader	B-Operating_System
that	O
load	O
and	O
link	O
shared	O
libraries	B-Library
(	O
like	O
.so	O
files	O
,	O
.dll	O
files	O
or	O
.dylib	O
files	O
)	O
to	O
already	O
loaded	O
running	O
programs	B-Application
.	O
</s>
<s>
Where	O
such	O
shared	O
libraries	B-Library
can	O
be	O
shared	O
by	O
multiple	O
processes	O
,	O
with	O
only	O
one	O
single	O
copy	O
of	O
the	O
shared	O
code	O
possibly	O
appearing	O
at	O
a	O
different	O
(	O
virtual	O
)	O
address	O
in	O
each	O
process	O
's	O
address	O
space	O
,	O
the	O
code	O
in	O
the	O
shared	O
library	O
is	O
required	O
to	O
be	O
relocatable	O
,	O
ie	O
the	O
library	O
must	O
only	O
use	O
self-relative	O
or	O
code	O
segment	O
base-relative	O
internal	O
addresses	O
throughout	O
.	O
</s>
