Commit 8380de41 authored by Bryan C. Mills's avatar Bryan C. Mills Committed by Bryan Mills

runtime: align stack pointer in sigfwd

sigfwd calls an arbitrary C signal handler function.  The System V ABI
for x86_64 (and the most recent revision of the ABI for i386) requires
the stack to be 16-byte aligned.

Fixes: #17641

Change-Id: I77f53d4a8c29c1b0fe8cfbcc8d5381c4e6f75a6b
Reviewed-on: https://go-review.googlesource.com/32107
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent b2c54afe
......@@ -7,8 +7,10 @@
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
......@@ -46,11 +48,22 @@ static void ioHandler(int signo, siginfo_t* info, void* ctxt) {
static jmp_buf jmp;
static char* nullPointer;
// An arbitrary function which requires proper stack alignment; see
// http://golang.org/issue/17641.
static void callWithVarargs(void* dummy, ...) {
va_list args;
va_start(args, dummy);
va_end(args);
}
// Signal handler for SIGSEGV on a C thread.
static void segvHandler(int signo, siginfo_t* info, void* ctxt) {
sigset_t mask;
int i;
// Call an arbitrary function that requires the stack to be properly aligned.
callWithVarargs("dummy arg", 3.1415);
if (sigemptyset(&mask) < 0) {
die("sigemptyset");
}
......
......@@ -254,12 +254,12 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
MOVL info+8(FP), CX
MOVL ctx+12(FP), DX
MOVL SP, SI
SUBL $32, SP // align stack; handler might be C code
ANDL $~15, SP
SUBL $32, SP
ANDL $~15, SP // align stack: handler might be a C function
MOVL BX, 0(SP)
MOVL CX, 4(SP)
MOVL DX, 8(SP)
MOVL SI, 12(SP)
MOVL SI, 12(SP) // save SI: handler might be a Go function
CALL AX
MOVL 12(SP), AX
MOVL AX, SP
......
......@@ -219,15 +219,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$0-24
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ SP, BP
SUBQ $64, SP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$32
......
......@@ -188,11 +188,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
......@@ -208,14 +208,20 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-4
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
MOVL sig+4(FP), AX
MOVL AX, 0(SP)
MOVL info+8(FP), AX
MOVL AX, 4(SP)
MOVL ctx+12(FP), AX
MOVL AX, 8(SP)
MOVL fn+0(FP), AX
MOVL sig+4(FP), BX
MOVL info+8(FP), CX
MOVL ctx+12(FP), DX
MOVL SP, SI
SUBL $32, SP
ANDL $~15, SP // align stack: handler might be a C function
MOVL BX, 0(SP)
MOVL CX, 4(SP)
MOVL DX, 8(SP)
MOVL SI, 12(SP) // save SI: handler might be a Go function
CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
......@@ -184,11 +184,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
......@@ -212,14 +212,20 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
MOVL sig+4(FP), AX
MOVL AX, 0(SP)
MOVL info+8(FP), AX
MOVL AX, 4(SP)
MOVL ctx+12(FP), AX
MOVL AX, 8(SP)
MOVL fn+0(FP), AX
MOVL sig+4(FP), BX
MOVL info+8(FP), CX
MOVL ctx+12(FP), DX
MOVL SP, SI
SUBL $32, SP
ANDL $-15, SP // align stack: handler might be a C function
MOVL BX, 0(SP)
MOVL CX, 4(SP)
MOVL DX, 8(SP)
MOVL SI, 12(SP) // save SI: handler might be a Go function
CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
......@@ -219,11 +219,16 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0-36
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
......@@ -216,14 +216,20 @@ TEXT runtime·sigaction(SB),NOSPLIT,$24
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
MOVL sig+4(FP), AX
MOVL AX, 0(SP)
MOVL info+8(FP), AX
MOVL AX, 4(SP)
MOVL ctx+12(FP), AX
MOVL AX, 8(SP)
MOVL fn+0(FP), AX
MOVL sig+4(FP), BX
MOVL info+8(FP), CX
MOVL ctx+12(FP), DX
MOVL SP, SI
SUBL $32, SP
ANDL $-15, SP // align stack: handler might be a C function
MOVL BX, 0(SP)
MOVL CX, 4(SP)
MOVL DX, 8(SP)
MOVL SI, 12(SP) // save SI: handler might be a Go function
CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
......@@ -238,11 +238,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$32
......
......@@ -196,14 +196,20 @@ TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$-4
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
MOVL sig+4(FP), AX
MOVL AX, 0(SP)
MOVL info+8(FP), AX
MOVL AX, 4(SP)
MOVL ctx+12(FP), AX
MOVL AX, 8(SP)
MOVL fn+0(FP), AX
MOVL sig+4(FP), BX
MOVL info+8(FP), CX
MOVL ctx+12(FP), DX
MOVL SP, SI
SUBL $32, SP
ANDL $~15, SP // align stack: handler might be a C function
MOVL BX, 0(SP)
MOVL CX, 4(SP)
MOVL DX, 8(SP)
MOVL SI, 12(SP) // save SI: handler might be a Go function
CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
......@@ -229,11 +229,16 @@ TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
......@@ -290,11 +290,16 @@ exit:
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX
MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX
MOVQ BP, SP
POPQ BP
RET
// Called from runtime·usleep (Go). Can be called on Go stack, on OS stack,
......
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