1
0
mirror of https://github.com/golang/go synced 2024-11-20 00:04:43 -07:00

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
This commit is contained in:
Devon H. O'Dell 2009-12-08 18:19:30 -08:00 committed by Russ Cox
parent cdce7325c8
commit 5a4a08fab8
8 changed files with 36 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -35,6 +35,7 @@ TEXT thr_start(SB),7,$0
POPAL
MOVL BX, g
MOVL AX, m
CALL stackcheck(SB) // smashes AX
CALL mstart(SB)
MOVL 0, AX // crash (not reached)

View File

@ -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)

View File

@ -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];

View File

@ -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

View File

@ -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