<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
call	B-General_Concept
stack	I-General_Concept
is	O
a	O
stack	B-Application
data	I-Application
structure	I-Application
that	O
stores	O
information	O
about	O
the	O
active	O
subroutines	O
of	O
a	O
computer	B-Application
program	I-Application
.	O
</s>
<s>
This	O
kind	O
of	O
stack	B-Application
is	O
also	O
known	O
as	O
an	O
execution	O
stack	B-Application
,	O
program	O
stack	B-Application
,	O
control	B-General_Concept
stack	I-General_Concept
,	O
run-time	B-General_Concept
stack	I-General_Concept
,	O
or	O
machine	O
stack	B-Application
,	O
and	O
is	O
often	O
shortened	O
to	O
just	O
"	O
the	O
stack	B-Application
"	O
.	O
</s>
<s>
Although	O
maintenance	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
is	O
important	O
for	O
the	O
proper	O
functioning	O
of	O
most	O
software	O
,	O
the	O
details	O
are	O
normally	O
hidden	O
and	O
automatic	O
in	O
high-level	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
Many	O
computer	O
instruction	B-General_Concept
sets	I-General_Concept
provide	O
special	O
instructions	O
for	O
manipulating	O
stacks	B-Application
.	O
</s>
<s>
A	O
call	B-General_Concept
stack	I-General_Concept
is	O
used	O
for	O
several	O
related	O
purposes	O
,	O
but	O
the	O
main	O
reason	O
for	O
having	O
one	O
is	O
to	O
keep	O
track	O
of	O
the	O
point	O
to	O
which	O
each	O
active	O
subroutine	O
should	O
return	O
control	O
when	O
it	O
finishes	O
executing	O
.	O
</s>
<s>
Such	O
activations	O
of	O
subroutines	O
may	O
be	O
nested	O
to	O
any	O
level	O
(	O
recursive	O
as	O
a	O
special	O
case	O
)	O
,	O
hence	O
the	O
stack	B-Application
structure	O
.	O
</s>
<s>
To	O
accomplish	O
this	O
,	O
the	O
address	B-General_Concept
following	O
the	O
instruction	O
that	O
jumps	O
to	O
DrawLine	O
,	O
the	O
return	B-Language
address	I-Language
,	O
is	O
pushed	O
onto	O
the	O
top	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
with	O
each	O
call	O
.	O
</s>
<s>
Since	O
the	O
call	B-General_Concept
stack	I-General_Concept
is	O
organized	O
as	O
a	O
stack	B-Application
,	O
the	O
caller	O
pushes	O
the	O
return	B-Language
address	I-Language
onto	O
the	O
stack	B-Application
,	O
and	O
the	O
called	O
subroutine	O
,	O
when	O
it	O
finishes	O
,	O
pulls	B-Application
or	I-Application
pops	I-Application
the	O
return	B-Language
address	I-Language
off	O
the	O
call	B-General_Concept
stack	I-General_Concept
and	O
transfers	O
control	O
to	O
that	O
address	B-General_Concept
.	O
</s>
<s>
If	O
a	O
called	O
subroutine	O
calls	O
on	O
yet	O
another	O
subroutine	O
,	O
it	O
will	O
push	O
another	O
return	B-Language
address	I-Language
onto	O
the	O
call	B-General_Concept
stack	I-General_Concept
,	O
and	O
so	O
on	O
,	O
with	O
the	O
information	O
stacking	O
up	O
and	O
unstacking	O
as	O
the	O
program	O
dictates	O
.	O
</s>
<s>
If	O
the	O
pushing	O
consumes	O
all	O
of	O
the	O
space	O
allocated	O
for	O
the	O
call	B-General_Concept
stack	I-General_Concept
,	O
an	O
error	O
called	O
a	O
stack	B-Error_Name
overflow	I-Error_Name
occurs	O
,	O
generally	O
causing	O
the	O
program	O
to	O
crash	B-General_Concept
.	O
</s>
<s>
Adding	O
a	O
subroutine	O
's	O
entry	O
to	O
the	O
call	B-General_Concept
stack	I-General_Concept
is	O
sometimes	O
called	O
"	O
winding	O
"	O
;	O
conversely	O
,	O
removing	O
entries	O
is	O
"	O
unwinding	O
"	O
.	O
</s>
<s>
There	O
is	O
usually	O
exactly	O
one	O
call	B-General_Concept
stack	I-General_Concept
associated	O
with	O
a	O
running	O
program	O
(	O
or	O
more	O
accurately	O
,	O
with	O
each	O
task	B-General_Concept
or	O
thread	B-Operating_System
of	O
a	O
process	B-Operating_System
)	O
,	O
although	O
additional	O
stacks	B-Application
may	O
be	O
created	O
for	O
signal	B-Operating_System
handling	I-Operating_System
or	O
cooperative	B-Operating_System
multitasking	I-Operating_System
(	O
as	O
with	O
setcontext	B-Operating_System
)	O
.	O
</s>
<s>
Since	O
there	O
is	O
only	O
one	O
in	O
this	O
important	O
context	O
,	O
it	O
can	O
be	O
referred	O
to	O
as	O
the	O
stack	B-Application
(	O
implicitly	O
,	O
"	O
of	O
the	O
task	B-General_Concept
"	O
)	O
;	O
however	O
,	O
in	O
the	O
Forth	B-Application
programming	I-Application
language	I-Application
the	O
data	O
stack	B-Application
or	O
parameter	O
stack	B-Application
is	O
accessed	O
more	O
explicitly	O
than	O
the	O
call	B-General_Concept
stack	I-General_Concept
and	O
is	O
commonly	O
referred	O
to	O
as	O
the	O
stack	B-Application
(	O
see	O
below	O
)	O
.	O
</s>
<s>
In	O
high-level	B-Language
programming	I-Language
languages	I-Language
,	O
the	O
specifics	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
are	O
usually	O
hidden	O
from	O
the	O
programmer	O
.	O
</s>
<s>
They	O
are	O
given	O
access	O
only	O
to	O
a	O
set	O
of	O
functions	O
,	O
and	O
not	O
the	O
memory	O
on	O
the	O
stack	B-Application
itself	O
.	O
</s>
<s>
This	O
is	O
an	O
example	O
of	O
abstraction	B-Application
.	O
</s>
<s>
Most	O
assembly	B-Language
languages	I-Language
,	O
on	O
the	O
other	O
hand	O
,	O
require	O
programmers	O
to	O
be	O
involved	O
with	O
manipulating	O
the	O
stack	B-Application
.	O
</s>
<s>
The	O
actual	O
details	O
of	O
the	O
stack	B-Application
in	O
a	O
programming	O
language	O
depend	O
upon	O
the	O
compiler	B-Language
,	O
operating	B-General_Concept
system	I-General_Concept
,	O
and	O
the	O
available	O
instruction	B-General_Concept
set	I-General_Concept
.	O
</s>
<s>
As	O
noted	O
above	O
,	O
the	O
primary	O
purpose	O
of	O
a	O
call	B-General_Concept
stack	I-General_Concept
is	O
to	O
store	O
the	O
return	O
addresses	O
.	O
</s>
<s>
When	O
a	O
subroutine	O
is	O
called	O
,	O
the	O
location	O
(	O
address	B-General_Concept
)	O
of	O
the	O
instruction	O
at	O
which	O
the	O
calling	O
routine	O
can	O
later	O
resume	O
needs	O
to	O
be	O
saved	O
somewhere	O
.	O
</s>
<s>
Using	O
a	O
stack	B-Application
to	O
save	O
the	O
return	B-Language
address	I-Language
has	O
important	O
advantages	O
over	O
some	O
alternative	O
calling	O
conventions	O
,	O
such	O
as	O
saving	O
the	O
return	B-Language
address	I-Language
before	O
the	O
beginning	O
of	O
the	O
called	O
subroutine	O
or	O
in	O
some	O
other	O
fixed	O
location	O
.	O
</s>
<s>
One	O
is	O
that	O
each	O
task	B-General_Concept
can	O
have	O
its	O
own	O
stack	B-Application
,	O
and	O
thus	O
the	O
subroutine	O
can	O
be	O
thread-safe	B-Operating_System
,	O
that	O
is	O
,	O
can	O
be	O
active	O
simultaneously	O
for	O
different	O
tasks	O
doing	O
different	O
things	O
.	O
</s>
<s>
Another	O
benefit	O
is	O
that	O
by	O
providing	O
reentrancy	B-Operating_System
,	O
recursion	O
is	O
automatically	O
supported	O
.	O
</s>
<s>
When	O
a	O
function	O
calls	O
itself	O
recursively	O
,	O
a	O
return	B-Language
address	I-Language
needs	O
to	O
be	O
stored	O
for	O
each	O
activation	O
of	O
the	O
function	O
so	O
that	O
it	O
can	O
later	O
be	O
used	O
to	O
return	O
from	O
the	O
function	O
activation	O
.	O
</s>
<s>
Stack	B-Application
structures	O
provide	O
this	O
capability	O
automatically	O
.	O
</s>
<s>
Depending	O
on	O
the	O
language	O
,	O
operating	B-General_Concept
system	I-General_Concept
,	O
and	O
machine	O
environment	O
,	O
a	O
call	B-General_Concept
stack	I-General_Concept
may	O
serve	O
additional	O
purposes	O
,	O
including	O
for	O
example	O
:	O
</s>
<s>
It	O
is	O
often	O
convenient	O
to	O
allocate	O
space	O
for	O
this	O
use	O
by	O
simply	O
moving	O
the	O
top	O
of	O
the	O
stack	B-Application
by	O
enough	O
to	O
provide	O
the	O
space	O
.	O
</s>
<s>
This	O
is	O
very	O
fast	O
when	O
compared	O
to	O
dynamic	B-General_Concept
memory	I-General_Concept
allocation	I-General_Concept
,	O
which	O
uses	O
the	O
heap	B-General_Concept
space	I-General_Concept
.	O
</s>
<s>
Note	O
that	O
each	O
separate	O
activation	O
of	O
a	O
subroutine	O
gets	O
its	O
own	O
separate	O
space	O
in	O
the	O
stack	B-Application
for	O
locals	O
.	O
</s>
<s>
Subroutines	O
often	O
require	O
that	O
values	O
for	O
parameters	O
be	O
supplied	O
to	O
them	O
by	O
the	O
code	O
which	O
calls	O
them	O
,	O
and	O
it	O
is	O
not	O
uncommon	O
that	O
space	O
for	O
these	O
parameters	O
may	O
be	O
laid	O
out	O
in	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
Generally	O
if	O
there	O
are	O
only	O
a	O
few	O
small	O
parameters	O
,	O
processor	B-General_Concept
registers	I-General_Concept
will	O
be	O
used	O
to	O
pass	O
the	O
values	O
,	O
but	O
if	O
there	O
are	O
more	O
parameters	O
than	O
can	O
be	O
handled	O
this	O
way	O
,	O
memory	O
space	O
will	O
be	O
needed	O
.	O
</s>
<s>
The	O
call	B-General_Concept
stack	I-General_Concept
works	O
well	O
as	O
a	O
place	O
for	O
these	O
parameters	O
,	O
especially	O
since	O
each	O
call	O
to	O
a	O
subroutine	O
,	O
which	O
will	O
have	O
differing	O
values	O
for	O
parameters	O
,	O
will	O
be	O
given	O
separate	O
space	O
on	O
the	O
call	B-General_Concept
stack	I-General_Concept
for	O
those	O
values	O
.	O
</s>
<s>
In	O
object-oriented	B-Language
languages	I-Language
such	O
as	O
C++	B-Language
,	O
the	O
list	O
of	O
parameters	O
may	O
also	O
include	O
the	O
this	B-Application
pointer	I-Application
.	O
</s>
<s>
The	O
stack	B-Application
of	O
such	O
operands	O
,	O
rather	O
like	O
that	O
in	O
an	O
RPN	O
calculator	O
,	O
is	O
called	O
an	O
evaluation	O
stack	B-Application
,	O
and	O
may	O
occupy	O
space	O
in	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
Some	O
programming	O
languages	O
(	O
e.g.	O
,	O
Pascal	B-Application
and	O
Ada	B-Language
)	O
support	O
declaration	O
of	O
nested	O
subroutines	O
,	O
which	O
are	O
allowed	O
to	O
access	O
the	O
context	O
of	O
their	O
enclosing	O
routines	O
,	O
i.e.	O
,	O
the	O
parameters	O
and	O
local	O
variables	O
within	O
the	O
scope	O
of	O
the	O
outer	O
routines	O
.	O
</s>
<s>
Usually	O
a	O
routine	O
's	O
display	O
is	O
located	O
in	O
its	O
own	O
stack	B-Application
frame	O
,	O
but	O
the	O
Burroughs	B-Device
B6500	I-Device
implemented	O
such	O
a	O
display	O
in	O
hardware	O
which	O
supported	O
up	O
to	O
32	O
levels	O
of	O
static	O
nesting	O
.	O
</s>
<s>
Beside	O
the	O
return	B-Language
address	I-Language
,	O
in	O
some	O
environments	O
there	O
may	O
be	O
other	O
machine	O
or	O
software	O
states	O
that	O
need	O
to	O
be	O
restored	O
when	O
a	O
subroutine	O
returns	O
.	O
</s>
<s>
If	O
needed	O
,	O
this	O
may	O
be	O
stored	O
in	O
the	O
call	B-General_Concept
stack	I-General_Concept
just	O
as	O
the	O
return	B-Language
address	I-Language
is	O
.	O
</s>
<s>
The	O
typical	O
call	B-General_Concept
stack	I-General_Concept
is	O
used	O
for	O
the	O
return	B-Language
address	I-Language
,	O
locals	O
,	O
and	O
parameters	O
(	O
known	O
as	O
a	O
call	O
frame	O
)	O
.	O
</s>
<s>
In	O
some	O
environments	O
there	O
may	O
be	O
more	O
or	O
fewer	O
functions	O
assigned	O
to	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
In	O
the	O
Forth	B-Application
programming	I-Application
language	I-Application
,	O
for	O
example	O
,	O
ordinarily	O
only	O
the	O
return	B-Language
address	I-Language
,	O
counted	O
loop	O
parameters	O
and	O
indexes	O
,	O
and	O
possibly	O
local	O
variables	O
are	O
stored	O
on	O
the	O
call	B-General_Concept
stack	I-General_Concept
(	O
which	O
in	O
that	O
environment	O
is	O
named	O
the	O
return	O
stack	B-Application
)	O
,	O
although	O
any	O
data	O
can	O
be	O
temporarily	O
placed	O
there	O
using	O
special	O
return-stack	O
handling	O
code	O
so	O
long	O
as	O
the	O
needs	O
of	O
calls	O
and	O
returns	O
are	O
respected	O
;	O
parameters	O
are	O
ordinarily	O
stored	O
on	O
a	O
separate	O
data	O
stack	B-Application
or	O
parameter	O
stack	B-Application
,	O
typically	O
called	O
the	O
stack	B-Application
in	O
Forth	O
terminology	O
even	O
though	O
there	O
is	O
a	O
call	B-General_Concept
stack	I-General_Concept
since	O
it	O
is	O
usually	O
accessed	O
more	O
explicitly	O
.	O
</s>
<s>
Some	O
Forths	O
also	O
have	O
a	O
third	O
stack	B-Application
for	O
floating-point	B-Algorithm
parameters	O
.	O
</s>
<s>
A	O
call	B-General_Concept
stack	I-General_Concept
is	O
composed	O
of	O
stack	B-Application
frames	O
(	O
also	O
called	O
activation	O
records	O
or	O
activation	O
frames	O
)	O
.	O
</s>
<s>
These	O
are	O
machine	B-Architecture
dependent	I-Architecture
and	O
ABI-dependent	O
data	B-General_Concept
structures	I-General_Concept
containing	O
subroutine	O
state	O
information	O
.	O
</s>
<s>
Each	O
stack	B-Application
frame	O
corresponds	O
to	O
a	O
call	O
to	O
a	O
subroutine	O
which	O
has	O
not	O
yet	O
terminated	O
with	O
a	O
return	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
a	O
subroutine	O
named	O
DrawLine	O
is	O
currently	O
running	O
,	O
having	O
been	O
called	O
by	O
a	O
subroutine	O
DrawSquare	O
,	O
the	O
top	O
part	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
might	O
be	O
laid	O
out	O
like	O
in	O
the	O
adjacent	O
picture	O
.	O
</s>
<s>
A	O
diagram	O
like	O
this	O
can	O
be	O
drawn	O
in	O
either	O
direction	O
as	O
long	O
as	O
the	O
placement	O
of	O
the	O
top	O
,	O
and	O
so	O
direction	O
of	O
stack	B-Application
growth	O
,	O
is	O
understood	O
.	O
</s>
<s>
Furthermore	O
,	O
independently	O
of	O
this	O
,	O
architectures	O
differ	O
as	O
to	O
whether	O
call	B-General_Concept
stacks	I-General_Concept
grow	O
towards	O
higher	O
addresses	O
or	O
towards	O
lower	O
addresses	O
.	O
</s>
<s>
The	O
stack	B-Application
frame	O
at	O
the	O
top	O
of	O
the	O
stack	B-Application
is	O
for	O
the	O
currently	O
executing	O
routine	O
,	O
which	O
can	O
access	O
information	O
within	O
its	O
frame	O
(	O
such	O
as	O
parameters	O
or	O
local	O
variables	O
)	O
in	O
any	O
order	O
.	O
</s>
<s>
The	O
stack	B-Application
frame	O
usually	O
includes	O
at	O
least	O
the	O
following	O
items	O
(	O
in	O
push	O
order	O
)	O
:	O
</s>
<s>
the	O
return	B-Language
address	I-Language
back	O
to	O
the	O
routine	O
's	O
caller	O
(	O
e.g.	O
</s>
<s>
When	O
stack	B-Application
frame	O
sizes	O
can	O
differ	O
,	O
such	O
as	O
between	O
different	O
functions	O
or	O
between	O
invocations	O
of	O
a	O
particular	O
function	O
,	O
popping	O
a	O
frame	O
off	O
the	O
stack	B-Application
does	O
not	O
constitute	O
a	O
fixed	O
decrement	O
of	O
the	O
stack	B-Application
pointer	O
.	O
</s>
<s>
At	O
function	O
return	O
,	O
the	O
stack	B-Application
pointer	O
is	O
instead	O
restored	O
to	O
the	O
frame	O
pointer	O
,	O
the	O
value	O
of	O
the	O
stack	B-Application
pointer	O
just	O
before	O
the	O
function	O
was	O
called	O
.	O
</s>
<s>
Each	O
stack	B-Application
frame	O
contains	O
a	O
stack	B-Application
pointer	O
to	O
the	O
top	O
of	O
the	O
frame	O
immediately	O
below	O
.	O
</s>
<s>
The	O
stack	B-Application
pointer	O
is	O
a	O
mutable	O
register	O
shared	O
between	O
all	O
invocations	O
.	O
</s>
<s>
A	O
frame	O
pointer	O
of	O
a	O
given	O
invocation	O
of	O
a	O
function	O
is	O
a	O
copy	O
of	O
the	O
stack	B-Application
pointer	O
as	O
it	O
was	O
before	O
the	O
function	O
was	O
invoked	O
.	O
</s>
<s>
The	O
locations	O
of	O
all	O
other	O
fields	O
in	O
the	O
frame	O
can	O
be	O
defined	O
relative	O
either	O
to	O
the	O
top	O
of	O
the	O
frame	O
,	O
as	O
negative	O
offsets	O
of	O
the	O
stack	B-Application
pointer	O
,	O
or	O
relative	O
to	O
the	O
top	O
of	O
the	O
frame	O
below	O
,	O
as	O
positive	O
offsets	O
of	O
the	O
frame	O
pointer	O
.	O
</s>
<s>
The	O
location	O
of	O
the	O
frame	O
pointer	O
itself	O
must	O
inherently	O
be	O
defined	O
as	O
a	O
negative	O
offset	O
of	O
the	O
stack	B-Application
pointer	O
.	O
</s>
<s>
In	O
most	O
systems	O
a	O
stack	B-Application
frame	O
has	O
a	O
field	O
to	O
contain	O
the	O
previous	O
value	O
of	O
the	O
frame	O
pointer	B-General_Concept
register	I-General_Concept
,	O
the	O
value	O
it	O
had	O
while	O
the	O
caller	O
was	O
executing	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
stack	B-Application
frame	O
of	O
DrawLine	O
would	O
have	O
a	O
memory	B-General_Concept
location	I-General_Concept
holding	O
the	O
frame	O
pointer	O
value	O
that	O
DrawSquare	O
uses	O
(	O
not	O
shown	O
in	O
the	O
diagram	O
above	O
)	O
.	O
</s>
<s>
Having	O
such	O
a	O
field	O
in	O
a	O
known	O
location	O
in	O
the	O
stack	B-Application
frame	O
enables	O
code	O
to	O
access	O
each	O
frame	O
successively	O
underneath	O
the	O
currently	O
executing	O
routine	O
's	O
frame	O
,	O
and	O
also	O
allows	O
the	O
routine	O
to	O
easily	O
restore	O
the	O
frame	O
pointer	O
to	O
the	O
caller	O
's	O
frame	O
,	O
just	O
before	O
it	O
returns	O
.	O
</s>
<s>
Programming	O
languages	O
that	O
support	O
nested	O
subroutines	O
also	O
have	O
a	O
field	O
in	O
the	O
call	O
frame	O
that	O
points	O
to	O
the	O
stack	B-Application
frame	O
of	O
the	O
latest	O
activation	O
of	O
the	O
procedure	O
that	O
most	O
closely	O
encapsulates	O
the	O
callee	O
,	O
i.e.	O
</s>
<s>
Some	O
architectures	O
,	O
compilers	B-Language
,	O
or	O
optimization	O
cases	O
store	O
one	O
link	O
for	O
each	O
enclosing	O
level	O
(	O
not	O
just	O
the	O
immediately	O
enclosing	O
)	O
,	O
so	O
that	O
deeply	O
nested	O
routines	O
that	O
access	O
shallow	O
data	O
do	O
not	O
have	O
to	O
traverse	O
several	O
links	O
;	O
this	O
strategy	O
is	O
often	O
called	O
a	O
"	O
display	O
"	O
.	O
</s>
<s>
Access	O
links	O
can	O
be	O
optimized	O
away	O
when	O
an	O
inner	O
function	O
does	O
not	O
access	O
any	O
(	O
non-constant	O
)	O
local	O
data	O
in	O
the	O
encapsulation	O
,	O
as	O
is	O
the	O
case	O
with	O
pure	O
functions	O
communicating	O
only	O
via	O
arguments	O
and	O
return	B-Language
values	I-Language
,	O
for	O
example	O
.	O
</s>
<s>
Some	O
historical	O
computers	O
,	O
such	O
as	O
the	O
Electrologica	B-Device
X8	I-Device
and	O
somewhat	O
later	O
the	O
Burroughs	B-Device
large	I-Device
systems	I-Device
,	O
had	O
special	O
"	O
display	O
registers	O
"	O
to	O
support	O
nested	O
functions	O
,	O
while	O
compilers	B-Language
for	O
most	O
modern	O
machines	O
(	O
such	O
as	O
the	O
ubiquitous	O
x86	O
)	O
simply	O
reserve	O
a	O
few	O
words	O
on	O
the	O
stack	B-Application
for	O
the	O
pointers	O
,	O
as	O
needed	O
.	O
</s>
<s>
For	O
some	O
purposes	O
,	O
the	O
stack	B-Application
frame	O
of	O
a	O
subroutine	O
and	O
that	O
of	O
its	O
caller	O
can	O
be	O
considered	O
to	O
overlap	O
,	O
the	O
overlap	O
consisting	O
of	O
the	O
area	O
where	O
the	O
parameters	O
are	O
passed	O
from	O
the	O
caller	O
to	O
the	O
callee	O
.	O
</s>
<s>
In	O
some	O
environments	O
,	O
the	O
caller	O
pushes	O
each	O
argument	O
onto	O
the	O
stack	B-Application
,	O
thus	O
extending	O
its	O
stack	B-Application
frame	O
,	O
then	O
invokes	O
the	O
callee	O
.	O
</s>
<s>
In	O
other	O
environments	O
,	O
the	O
caller	O
has	O
a	O
preallocated	O
area	O
at	O
the	O
top	O
of	O
its	O
stack	B-Application
frame	O
to	O
hold	O
the	O
arguments	O
it	O
supplies	O
to	O
other	O
subroutines	O
it	O
calls	O
.	O
</s>
<s>
Under	O
this	O
approach	O
,	O
the	O
size	O
of	O
the	O
area	O
is	O
calculated	O
by	O
the	O
compiler	B-Language
to	O
be	O
the	O
largest	O
needed	O
by	O
any	O
called	O
subroutine	O
.	O
</s>
<s>
Usually	O
the	O
call	B-General_Concept
stack	I-General_Concept
manipulation	O
needed	O
at	O
the	O
site	O
of	O
a	O
call	O
to	O
a	O
subroutine	O
is	O
minimal	O
(	O
which	O
is	O
good	O
since	O
there	O
can	O
be	O
many	O
call	O
sites	O
for	O
each	O
subroutine	O
to	O
be	O
called	O
)	O
.	O
</s>
<s>
The	O
values	O
for	O
the	O
actual	O
arguments	O
are	O
evaluated	O
at	O
the	O
call	O
site	O
,	O
since	O
they	O
are	O
specific	O
to	O
the	O
particular	O
call	O
,	O
and	O
either	O
pushed	O
onto	O
the	O
stack	B-Application
or	O
placed	O
into	O
registers	O
,	O
as	O
determined	O
by	O
the	O
used	O
calling	O
convention	O
.	O
</s>
<s>
In	O
the	O
called	O
subroutine	O
,	O
the	O
first	O
code	O
executed	O
is	O
usually	O
termed	O
the	O
subroutine	B-Language
prologue	I-Language
,	O
since	O
it	O
does	O
the	O
necessary	O
housekeeping	O
before	O
the	O
code	O
for	O
the	O
statements	O
of	O
the	O
routine	O
is	O
begun	O
.	O
</s>
<s>
For	O
instruction	B-General_Concept
set	I-General_Concept
architectures	I-General_Concept
in	O
which	O
the	O
instruction	O
used	O
to	O
call	O
a	O
subroutine	O
puts	O
the	O
return	B-Language
address	I-Language
into	O
a	O
register	O
,	O
rather	O
than	O
pushing	O
it	O
onto	O
the	O
stack	B-Application
,	O
the	O
prologue	O
will	O
commonly	O
save	O
the	O
return	B-Language
address	I-Language
by	O
pushing	O
the	O
value	O
onto	O
the	O
call	B-General_Concept
stack	I-General_Concept
,	O
although	O
if	O
the	O
called	O
subroutine	O
does	O
not	O
call	O
any	O
other	O
routines	O
it	O
may	O
leave	O
the	O
value	O
in	O
the	O
register	O
.	O
</s>
<s>
Similarly	O
,	O
the	O
current	O
stack	B-Application
pointer	O
and/or	O
frame	O
pointer	O
values	O
may	O
be	O
pushed	O
.	O
</s>
<s>
If	O
frame	O
pointers	O
are	O
being	O
used	O
,	O
the	O
prologue	O
will	O
typically	O
set	O
the	O
new	O
value	O
of	O
the	O
frame	O
pointer	B-General_Concept
register	I-General_Concept
from	O
the	O
stack	B-Application
pointer	O
.	O
</s>
<s>
Space	O
on	O
the	O
stack	B-Application
for	O
local	O
variables	O
can	O
then	O
be	O
allocated	O
by	O
incrementally	O
changing	O
the	O
stack	B-Application
pointer	O
.	O
</s>
<s>
The	O
Forth	B-Application
programming	I-Application
language	I-Application
allows	O
explicit	O
winding	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
(	O
called	O
there	O
the	O
"	O
return	O
stack	B-Application
"	O
)	O
.	O
</s>
<s>
This	O
will	O
typically	O
restore	O
saved	O
register	O
values	O
(	O
such	O
as	O
the	O
frame	O
pointer	O
value	O
)	O
from	O
the	O
stack	B-Application
frame	O
,	O
pop	O
the	O
entire	O
stack	B-Application
frame	O
off	O
the	O
stack	B-Application
by	O
changing	O
the	O
stack	B-Application
pointer	O
value	O
,	O
and	O
finally	O
branch	O
to	O
the	O
instruction	O
at	O
the	O
return	B-Language
address	I-Language
.	O
</s>
<s>
Under	O
many	O
calling	O
conventions	O
the	O
items	O
popped	O
off	O
the	O
stack	B-Application
by	O
the	O
epilogue	O
include	O
the	O
original	O
argument	O
values	O
,	O
in	O
which	O
case	O
there	O
usually	O
are	O
no	O
further	O
stack	B-Application
manipulations	O
that	O
need	O
to	O
be	O
done	O
by	O
the	O
caller	O
.	O
</s>
<s>
With	O
some	O
calling	O
conventions	O
,	O
however	O
,	O
it	O
is	O
the	O
caller	O
's	O
responsibility	O
to	O
remove	O
the	O
arguments	O
from	O
the	O
stack	B-Application
after	O
the	O
return	O
.	O
</s>
<s>
Returning	O
from	O
the	O
called	O
function	O
will	O
pop	O
the	O
top	O
frame	O
off	O
the	O
stack	B-Application
,	O
perhaps	O
leaving	O
a	O
return	B-Language
value	I-Language
.	O
</s>
<s>
The	O
more	O
general	O
act	O
of	O
popping	O
one	O
or	O
more	O
frames	O
off	O
the	O
stack	B-Application
to	O
resume	O
execution	O
elsewhere	O
in	O
the	O
program	O
is	O
called	O
stack	B-Application
unwinding	O
and	O
must	O
be	O
performed	O
when	O
non-local	O
control	O
structures	O
are	O
used	O
,	O
such	O
as	O
those	O
used	O
for	O
exception	O
handling	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
stack	B-Application
frame	O
of	O
a	O
function	O
contains	O
one	O
or	O
more	O
entries	O
specifying	O
exception	O
handlers	O
.	O
</s>
<s>
When	O
an	O
exception	O
is	O
thrown	O
,	O
the	O
stack	B-Application
is	O
unwound	O
until	O
a	O
handler	O
is	O
found	O
that	O
is	O
prepared	O
to	O
handle	O
(	O
catch	O
)	O
the	O
type	O
of	O
the	O
thrown	O
exception	O
.	O
</s>
<s>
Pascal	B-Application
allows	O
a	O
global	O
goto	B-Application
statement	O
to	O
transfer	O
control	O
out	O
of	O
a	O
nested	O
function	O
and	O
into	O
a	O
previously	O
invoked	O
outer	O
function	O
.	O
</s>
<s>
This	O
operation	O
requires	O
the	O
stack	B-Application
to	O
be	O
unwound	O
,	O
removing	O
as	O
many	O
stack	B-Application
frames	O
as	O
necessary	O
to	O
restore	O
the	O
proper	O
context	O
to	O
transfer	O
control	O
to	O
the	O
target	O
statement	O
within	O
the	O
enclosing	O
outer	O
function	O
.	O
</s>
<s>
Similarly	O
,	O
C	O
has	O
the	O
setjmp	B-Language
and	O
longjmp	B-Language
functions	O
that	O
act	O
as	O
non-local	O
gotos	O
.	O
</s>
<s>
Common	B-Language
Lisp	I-Language
allows	O
control	O
of	O
what	O
happens	O
when	O
the	O
stack	B-Application
is	O
unwound	O
by	O
using	O
the	O
unwind-protect	O
special	O
operator	O
.	O
</s>
<s>
When	O
applying	O
a	O
continuation	O
,	O
the	O
stack	B-Application
is	O
(	O
logically	O
)	O
unwound	O
and	O
then	O
rewound	O
with	O
the	O
stack	B-Application
of	O
the	O
continuation	O
.	O
</s>
<s>
This	O
is	O
not	O
the	O
only	O
way	O
to	O
implement	O
continuations	O
;	O
for	O
example	O
,	O
using	O
multiple	O
,	O
explicit	O
stacks	B-Application
,	O
application	O
of	O
a	O
continuation	O
can	O
simply	O
activate	O
its	O
stack	B-Application
and	O
wind	O
a	O
value	O
to	O
be	O
passed	O
.	O
</s>
<s>
The	O
Scheme	B-Language
programming	I-Language
language	I-Language
allows	O
arbitrary	O
thunks	B-Application
to	O
be	O
executed	O
in	O
specified	O
points	O
on	O
"	O
unwinding	O
"	O
or	O
"	O
rewinding	O
"	O
of	O
the	O
control	B-General_Concept
stack	I-General_Concept
when	O
a	O
continuation	O
is	O
invoked	O
.	O
</s>
<s>
The	O
call	B-General_Concept
stack	I-General_Concept
can	O
sometimes	O
be	O
inspected	O
as	O
the	O
program	O
is	O
running	O
.	O
</s>
<s>
Depending	O
on	O
how	O
the	O
program	O
is	O
written	O
and	O
compiled	B-Language
,	O
the	O
information	O
on	O
the	O
stack	B-Application
can	O
be	O
used	O
to	O
determine	O
intermediate	O
values	O
and	O
function	O
call	O
traces	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
the	O
GNU	B-Language
Debugger	I-Language
(	O
GDB	B-Language
)	O
implements	O
interactive	O
inspection	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
of	O
a	O
running	O
,	O
but	O
paused	O
,	O
C	O
program	O
.	O
</s>
<s>
Taking	O
regular-time	O
samples	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
can	O
be	O
useful	O
in	O
profiling	O
the	O
performance	O
of	O
programs	O
,	O
because	O
if	O
a	O
subroutine	O
's	O
pointer	O
appears	O
on	O
the	O
call	B-General_Concept
stack	I-General_Concept
sampling	O
data	O
many	O
times	O
,	O
it	O
is	O
likely	O
a	O
code	O
bottleneck	O
and	O
should	O
be	O
inspected	O
for	O
performance	O
problems	O
.	O
</s>
<s>
In	O
a	O
language	O
with	O
free	O
pointers	O
or	O
non-checked	O
array	O
writes	O
(	O
such	O
as	O
in	O
C	O
)	O
,	O
the	O
mixing	O
of	O
control	O
flow	O
data	O
which	O
affects	O
the	O
execution	O
of	O
code	O
(	O
the	O
return	O
addresses	O
or	O
the	O
saved	O
frame	O
pointers	O
)	O
and	O
simple	O
program	O
data	O
(	O
parameters	O
or	O
return	B-Language
values	I-Language
)	O
in	O
a	O
call	B-General_Concept
stack	I-General_Concept
is	O
a	O
security	O
risk	O
,	O
possibly	O
exploitable	O
through	O
stack	B-General_Concept
buffer	I-General_Concept
overflows	I-General_Concept
as	O
the	O
most	O
common	O
type	O
of	O
buffer	B-General_Concept
overflows	I-General_Concept
.	O
</s>
<s>
One	O
of	O
such	O
attacks	O
involves	O
filling	O
one	O
buffer	O
with	O
arbitrary	O
executable	O
code	O
,	O
and	O
then	O
overflowing	O
the	O
same	O
or	O
some	O
other	O
buffer	O
to	O
overwrite	O
some	O
return	B-Language
address	I-Language
with	O
a	O
value	O
that	O
points	O
directly	O
to	O
the	O
executable	O
code	O
.	O
</s>
<s>
Similar	O
attacks	O
can	O
succeed	O
even	O
with	O
W^X	O
protection	O
enabled	O
,	O
including	O
the	O
return-to-libc	B-Language
attack	I-Language
or	O
the	O
attacks	O
coming	O
from	O
return-oriented	O
programming	O
.	O
</s>
<s>
Various	O
mitigations	O
have	O
been	O
proposed	O
,	O
such	O
as	O
storing	O
arrays	O
in	O
a	O
completely	O
separate	O
location	O
from	O
the	O
return	O
stack	B-Application
,	O
as	O
is	O
the	O
case	O
in	O
the	O
Forth	B-Application
programming	I-Application
language	I-Application
.	O
</s>
