summaryrefslogtreecommitdiff
path: root/src/runtime/proc.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-12-04 08:30:54 -0800
committerRuss Cox <rsc@golang.org>2008-12-04 08:30:54 -0800
commit3b5b1f01b1314f3dbd190842aa50c78aae7ba5c0 (patch)
treee2b3b906ca88ce3e8ce7a528bde4a4f3e69f94c2 /src/runtime/proc.c
parent7c270c6c5b9af69cac97f79a1dbc0a3558d0f5cc (diff)
downloadgo-3b5b1f01b1314f3dbd190842aa50c78aae7ba5c0.tar.gz
add stub routines stackalloc() and stackfree().
run oldstack on g0's stack, just like newstack does, so that oldstack can free the old stack. R=r DELTA=53 (44 added, 0 deleted, 9 changed) OCL=20404 CL=20433
Diffstat (limited to 'src/runtime/proc.c')
-rw-r--r--src/runtime/proc.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/runtime/proc.c b/src/runtime/proc.c
index 4a61358dc..fa30c1eab 100644
--- a/src/runtime/proc.c
+++ b/src/runtime/proc.c
@@ -567,6 +567,7 @@ oldstack(void)
Stktop *top;
uint32 siz2;
byte *sp;
+ uint64 oldsp, oldpc, oldbase, oldguard;
// printf("oldstack m->cret=%p\n", m->cret);
@@ -581,16 +582,37 @@ oldstack(void)
mcpy(top->oldsp+16, sp, siz2);
}
- // call no more functions after this point - stackguard disagrees with SP
- m->curg->stackbase = top->oldbase;
- m->curg->stackguard = top->oldguard;
- m->morestack.SP = top->oldsp+8;
- m->morestack.PC = (byte*)(*(uint64*)(top->oldsp+8));
-
+ oldsp = (uint64)top->oldsp + 8;
+ oldpc = *(uint64*)(top->oldsp + 8);
+ oldbase = (uint64)top->oldbase;
+ oldguard = (uint64)top->oldguard;
+
+ stackfree((byte*)m->curg->stackguard - 512 - 160);
+
+ m->curg->stackbase = (byte*)oldbase;
+ m->curg->stackguard = (byte*)oldguard;
+ m->morestack.SP = (byte*)oldsp;
+ m->morestack.PC = (byte*)oldpc;
+
+ // These two lines must happen in sequence;
+ // once g has been changed, must switch to g's stack
+ // before calling any non-assembly functions.
+ // TODO(rsc): Perhaps make the new g a parameter
+ // to gogoret and setspgoto, so that g is never
+ // explicitly assigned to without also setting
+ // the stack pointer.
+ g = m->curg;
gogoret(&m->morestack, m->cret);
}
void
+lessstack(void)
+{
+ g = m->g0;
+ setspgoto(m->sched.SP, oldstack, nil);
+}
+
+void
newstack(void)
{
int32 siz1, siz2;
@@ -611,7 +633,7 @@ newstack(void)
if(siz1 < 4096)
siz1 = 4096;
- stk = mal(siz1 + 1024);
+ stk = stackalloc(siz1 + 1024);
stk += 512;
top = (Stktop*)(stk+siz1-sizeof(*top));
@@ -658,3 +680,4 @@ sys·morestack(uint64 u)
*(int32*)234 = 123; // never return
}
+