Commit 5a4a08fa authored by Devon H. O'Dell's avatar Devon H. O'Dell Committed by Russ Cox

Fix stack on FreeBSD / add stack check across the board

FreeBSD was passing stk as the new thread's stack base, while
stk is the top of the stack in go. The added check should cause
a trap if this ever comes up in any new ports, or regresses
in current ones.

R=rsc
CC=golang-dev
https://golang.org/cl/167055
parent cdce7325
......@@ -323,6 +323,17 @@ TEXT runcgo(SB),7,$16
MOVL 4(SP), SP
RET
// check that SP is in range [g->stackbase, g->stackguard)
TEXT stackcheck(SB), 7, $0
MOVL g, AX
CMPL g_stackbase(AX), SP
JHI 2(PC)
INT $3
CMPL SP, g_stackguard(AX)
JHI 2(PC)
INT $3
RET
GLOBL m0(SB), $1024
GLOBL g0(SB), $1024
......
......@@ -301,3 +301,13 @@ TEXT runcgo(SB),7,$32
MOVQ 8(SP), SP
RET
// check that SP is in range [g->stackbase, g->stackguard)
TEXT stackcheck(SB), 7, $0
CMPQ g_stackbase(g), SP
JHI 2(PC)
INT $3
CMPQ SP, g_stackguard(g)
JHI 2(PC)
INT $3
RET
......@@ -153,6 +153,7 @@ TEXT bsdthread_start(SB),7,$0
MOVL AX, g
MOVL DX, m
MOVL BX, m_procid(DX) // m->procid = thread port (for debuggers)
CALL stackcheck(SB) // smashes AX
CALL CX // fn()
CALL exit1(SB)
RET
......
......@@ -9,13 +9,13 @@
#include "386/asm.h"
TEXT sys_umtx_op(SB),7,$-4
MOVL $454, AX
INT $0x80
MOVL $454, AX
INT $0x80
RET
TEXT thr_new(SB),7,$-4
MOVL $455, AX
INT $0x80
MOVL $455, AX
INT $0x80
RET
TEXT thr_start(SB),7,$0
......@@ -33,10 +33,11 @@ TEXT thr_start(SB),7,$0
POPL AX
POPL AX
POPAL
MOVL BX, g
MOVL AX, m
CALL mstart(SB)
MOVL 0, AX // crash (not reached)
MOVL BX, g
MOVL AX, m
CALL stackcheck(SB) // smashes AX
CALL mstart(SB)
MOVL 0, AX // crash (not reached)
// Exit the entire program (like C exit)
TEXT exit(SB),7,$-4
......
......@@ -28,6 +28,7 @@ TEXT thr_new(SB),7,$0
TEXT thr_start(SB),7,$0
MOVQ DI, m
MOVQ m_g0(m), g
CALL stackcheck(SB)
CALL mstart(SB)
MOVQ 0, AX // crash (not reached)
......
......@@ -139,8 +139,8 @@ newosproc(M *m, G *g, void *stk, void (*fn)(void))
param.start_func = thr_start;
param.arg = m;
param.stack_base = stk;
param.stack_size = g->stackbase - g->stackguard + 256;
param.stack_base = (int8*)g->stackbase;
param.stack_size = (byte*)stk - (byte*)g->stackbase;
param.child_tid = (intptr*)&m->procid;
param.parent_tid = nil;
param.tls_base = (int8*)&m->tls[0];
......
......@@ -152,6 +152,7 @@ TEXT clone(SB),7,$0
MOVL DX, g
MOVL BX, m
CALL stackcheck(SB) // smashes AX
MOVL 0(DX), DX // paranoia; check they are not nil
MOVL 0(BX), BX
......
......@@ -149,6 +149,7 @@ TEXT clone(SB),7,$0
MOVQ SI, SP
MOVQ R8, m
MOVQ R9, g
CALL stackcheck(SB)
// Initialize m->procid to Linux tid
MOVL $186, AX // gettid
......
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