From add89dd1bae04b641944d082467375f1dc787cd2 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 12 Oct 2009 10:26:38 -0700 Subject: stack overflow debugging and fix. * in 6l, -K already meant check for stack underflow. add -KK to mean double-check stack overflows even in nosplit functions. * comment out print locks; they deadlock too easily but are still useful to put back for special occasions. * let runcgo assembly switch to scheduler stack without involving scheduler directly. because runcgo gets called from matchmg, it is too hard to keep it from being called on other stacks. R=r DELTA=94 (65 added, 18 deleted, 11 changed) OCL=35591 CL=35604 --- src/pkg/runtime/amd64/asm.s | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/pkg/runtime/amd64') diff --git a/src/pkg/runtime/amd64/asm.s b/src/pkg/runtime/amd64/asm.s index 6cb6d5c77a..87bc222e14 100644 --- a/src/pkg/runtime/amd64/asm.s +++ b/src/pkg/runtime/amd64/asm.s @@ -272,20 +272,32 @@ TEXT jmpdefer(SB), 7, $0 JMP AX // but first run the deferred function // runcgo(void(*fn)(void*), void *arg) -// Call fn(arg), but align the stack -// appropriately for the gcc ABI -// and also save g and m across the call, +// Call fn(arg) on the scheduler stack, +// aligned appropriately for the gcc ABI. +// Save g and m across the call, // since the foreign code might reuse them. TEXT runcgo(SB),7,$32 + // Save old registers. MOVQ fn+0(FP),AX MOVQ arg+8(FP),DI // DI = first argument in AMD64 ABI MOVQ SP, CX + + // Figure out if we need to switch to m->g0 stack. + MOVQ m_g0(m), R8 + CMPQ R8, g + JEQ 2(PC) + MOVQ (m_sched+gobuf_sp)(m), SP + + // Now on a scheduling stack (a pthread-created stack). + SUBQ $32, SP ANDQ $~15, SP // alignment for gcc ABI MOVQ g, 24(SP) // save old g, m, SP MOVQ m, 16(SP) MOVQ CX, 8(SP) CALL AX - MOVQ 16(SP), m // restore + + // Restore registers, stack pointer. + MOVQ 16(SP), m MOVQ 24(SP), g MOVQ 8(SP), SP RET -- cgit v1.3-5-g9baa