]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use gp->sched.sp for stack overflow check
authorRuss Cox <rsc@golang.org>
Thu, 27 Jun 2013 20:51:06 +0000 (16:51 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 27 Jun 2013 20:51:06 +0000 (16:51 -0400)
On x86 it is a few words lower on the stack than m->morebuf.sp
so it is a more precise check. Enabling the check requires recording
a valid gp->sched in reflect.call too. This is a good thing in general,
since it will make stack traces during reflect.call work better, and it
may be useful for preemption too.

R=dvyukov
CC=golang-dev
https://golang.org/cl/10709043

src/pkg/runtime/asm_386.s
src/pkg/runtime/asm_amd64.s
src/pkg/runtime/asm_arm.s
src/pkg/runtime/stack.c

index cd1514e1e049db556f42eb2d00dadf03bd727bfe..630f006bcb9b482615a1aaede7bc4ae98ef1cfb1 100644 (file)
@@ -254,6 +254,11 @@ TEXT reflect·call(SB), 7, $0
        MOVL    g(CX), AX
        MOVL    AX, (m_morebuf+gobuf_g)(BX)
 
+       // Save our own state as the PC and SP to restore
+       // if this goroutine needs to be restarted.
+       MOVL    $reflect·call(SB), (g_sched+gobuf_pc)(AX)
+       MOVL    SP, (g_sched+gobuf_sp)(AX)
+
        // Set up morestack arguments to call f on a new stack.
        // We set f's frame size to 1, as a hint to newstack
        // that this is a call from reflect·call.
index 0b7c3ded06ccb1d020308345f7a685d14b60a4fa..d43eb0283574d6dcf7616fb9530a2aaae319353e 100644 (file)
@@ -231,6 +231,11 @@ TEXT reflect·call(SB), 7, $0
        MOVQ    AX, (m_morebuf+gobuf_sp)(BX)
        MOVQ    g(CX), AX
        MOVQ    AX, (m_morebuf+gobuf_g)(BX)
+       
+       // Save our own state as the PC and SP to restore
+       // if this goroutine needs to be restarted.
+       MOVQ    $reflect·call(SB), (g_sched+gobuf_pc)(AX)
+       MOVQ    SP, (g_sched+gobuf_sp)(AX)
 
        // Set up morestack arguments to call f on a new stack.
        // We set f's frame size to 1, as a hint to newstack
index fd88b46b90c04194351c497d49cd37b1e6232cc6..31bbca6afaa606b856cac0a64f254f7f970cfa96 100644 (file)
@@ -207,6 +207,13 @@ TEXT reflect·call(SB), 7, $-4
        MOVW    SP, (m_morebuf+gobuf_sp)(m)     // our caller's SP
        MOVW    g,  (m_morebuf+gobuf_g)(m)
 
+       // Save our own state as the PC and SP to restore
+       // if this goroutine needs to be restarted.
+       MOVW    $reflect·call(SB), R11
+       MOVW    R11, (g_sched+gobuf_pc)(g)
+       MOVW    LR, (g_sched+gobuf_lr)(g)
+       MOVW    SP, (g_sched+gobuf_sp)(g)
+
        // Set up morestack arguments to call f on a new stack.
        // We set f's frame size to 1, as a hint to newstack
        // that this is a call from reflect·call.
index 5480c4697059e5be53ddc6b7e1bcb3e13adf8168..16dfa041a0ebf20a6abc259722ee02aec9659806 100644 (file)
@@ -215,7 +215,7 @@ runtime·newstack(void)
        if(!reflectcall)
                runtime·rewindmorestack(&gp->sched);
 
-       sp = m->morebuf.sp;
+       sp = gp->sched.sp;
        if(thechar == '6' || thechar == '8') {
                // The call to morestack cost a word.
                sp -= sizeof(uintptr);