]> Cypherpunks repositories - gostls13.git/commitdiff
add stub routines stackalloc() and stackfree().
authorRuss Cox <rsc@golang.org>
Thu, 4 Dec 2008 16:30:54 +0000 (08:30 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 4 Dec 2008 16:30:54 +0000 (08:30 -0800)
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

src/runtime/Makefile
src/runtime/proc.c
src/runtime/rt0_amd64.s
src/runtime/runtime.h
src/runtime/stack.c [new file with mode: 0644]

index cd1cf28212ece15a04acbe7010cf36e27504bb80..da12c2ccb9c6fdcf8b85426a413a05b097d6c0e4 100644 (file)
@@ -25,6 +25,7 @@ LIBOFILES=\
        print.$O\
        rune.$O\
        proc.$O\
+       stack.$O\
        string.$O\
        symtab.$O\
        sys_file.$O\
index 4a61358dc4b20b0664a1e4197d79f097eaa4a444..fa30c1eabbe68148fc429d05d12194f941382c08 100644 (file)
@@ -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,15 +582,36 @@ 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)
 {
@@ -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
 }
+
index ad86c56a59b6ca9f4fe11ba648ea2008fc628411..73e9251210024a681173b54d2027ec7bb69be101 100644 (file)
@@ -42,7 +42,7 @@ TEXT  _rt0_amd64(SB),7,$-8
        CALL    sys·newproc(SB)
        POPQ    AX
        POPQ    AX
-       
+
        // start this M
        CALL    mstart(SB)
 
@@ -89,10 +89,10 @@ TEXT gosave(SB), 7, $0
  * support for morestack
  */
 
-// return point when leaving new stack.  save AX, jmp to oldstack to switch back
+// return point when leaving new stack.  save AX, jmp to lessstack to switch back
 TEXT retfromnewstack(SB), 7, $0
        MOVQ    AX, 16(R14)     // save AX in m->cret
-       MOVQ    $oldstack(SB), AX
+       MOVQ    $lessstack(SB), AX
        JMP     AX
 
 // gogo, returning 2nd arg instead of 1
index e37786e4fb6d1833616a93f1d033484f653d8438..a0cbac359d20e283b21cf2fc2e1fed14649f9657 100644 (file)
@@ -277,6 +277,8 @@ G*  malg(int32);
 void   minit(void);
 Func*  findfunc(uint64);
 int32  funcline(Func*, uint64);
+void*  stackalloc(uint32);
+void   stackfree(void*);
 
 /*
  * mutual exclusion locks.  in the uncontended case,
diff --git a/src/runtime/stack.c b/src/runtime/stack.c
new file mode 100644 (file)
index 0000000..a4eeedc
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2009 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "runtime.h"
+
+// Stubs for stack management.
+// In a separate file so they can be overridden during testing of gc.
+
+void*
+stackalloc(uint32 n)
+{
+       return mal(n);
+}
+
+void
+stackfree(void*)
+{
+}