Commit f0d73fbc authored by Russ Cox's avatar Russ Cox

runtime: use gp->sched.sp for stack overflow check

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
parent 4eb17ecd
...@@ -254,6 +254,11 @@ TEXT reflect·call(SB), 7, $0 ...@@ -254,6 +254,11 @@ TEXT reflect·call(SB), 7, $0
MOVL g(CX), AX MOVL g(CX), AX
MOVL AX, (m_morebuf+gobuf_g)(BX) 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. // Set up morestack arguments to call f on a new stack.
// We set f's frame size to 1, as a hint to newstack // We set f's frame size to 1, as a hint to newstack
// that this is a call from reflect·call. // that this is a call from reflect·call.
......
...@@ -232,6 +232,11 @@ TEXT reflect·call(SB), 7, $0 ...@@ -232,6 +232,11 @@ TEXT reflect·call(SB), 7, $0
MOVQ g(CX), AX MOVQ g(CX), AX
MOVQ AX, (m_morebuf+gobuf_g)(BX) 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. // Set up morestack arguments to call f on a new stack.
// We set f's frame size to 1, as a hint to newstack // We set f's frame size to 1, as a hint to newstack
// that this is a call from reflect·call. // that this is a call from reflect·call.
......
...@@ -207,6 +207,13 @@ TEXT reflect·call(SB), 7, $-4 ...@@ -207,6 +207,13 @@ TEXT reflect·call(SB), 7, $-4
MOVW SP, (m_morebuf+gobuf_sp)(m) // our caller's SP MOVW SP, (m_morebuf+gobuf_sp)(m) // our caller's SP
MOVW g, (m_morebuf+gobuf_g)(m) 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. // Set up morestack arguments to call f on a new stack.
// We set f's frame size to 1, as a hint to newstack // We set f's frame size to 1, as a hint to newstack
// that this is a call from reflect·call. // that this is a call from reflect·call.
......
...@@ -215,7 +215,7 @@ runtime·newstack(void) ...@@ -215,7 +215,7 @@ runtime·newstack(void)
if(!reflectcall) if(!reflectcall)
runtime·rewindmorestack(&gp->sched); runtime·rewindmorestack(&gp->sched);
sp = m->morebuf.sp; sp = gp->sched.sp;
if(thechar == '6' || thechar == '8') { if(thechar == '6' || thechar == '8') {
// The call to morestack cost a word. // The call to morestack cost a word.
sp -= sizeof(uintptr); sp -= sizeof(uintptr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment