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 @@ ...@@ -7,8 +7,10 @@
#include <setjmp.h> #include <setjmp.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -46,11 +48,22 @@ static void ioHandler(int signo, siginfo_t* info, void* ctxt) { ...@@ -46,11 +48,22 @@ static void ioHandler(int signo, siginfo_t* info, void* ctxt) {
static jmp_buf jmp; static jmp_buf jmp;
static char* nullPointer; 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. // Signal handler for SIGSEGV on a C thread.
static void segvHandler(int signo, siginfo_t* info, void* ctxt) { static void segvHandler(int signo, siginfo_t* info, void* ctxt) {
sigset_t mask; sigset_t mask;
int i; int i;
// Call an arbitrary function that requires the stack to be properly aligned.
callWithVarargs("dummy arg", 3.1415);
if (sigemptyset(&mask) < 0) { if (sigemptyset(&mask) < 0) {
die("sigemptyset"); die("sigemptyset");
} }
......
...@@ -254,12 +254,12 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16 ...@@ -254,12 +254,12 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
MOVL info+8(FP), CX MOVL info+8(FP), CX
MOVL ctx+12(FP), DX MOVL ctx+12(FP), DX
MOVL SP, SI MOVL SP, SI
SUBL $32, SP // align stack; handler might be C code SUBL $32, SP
ANDL $~15, SP ANDL $~15, SP // align stack: handler might be a C function
MOVL BX, 0(SP) MOVL BX, 0(SP)
MOVL CX, 4(SP) MOVL CX, 4(SP)
MOVL DX, 8(SP) MOVL DX, 8(SP)
MOVL SI, 12(SP) MOVL SI, 12(SP) // save SI: handler might be a Go function
CALL AX CALL AX
MOVL 12(SP), AX MOVL 12(SP), AX
MOVL AX, SP MOVL AX, SP
......
...@@ -223,11 +223,12 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 ...@@ -223,11 +223,12 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
PUSHQ BP
MOVQ SP, BP MOVQ SP, BP
SUBQ $64, SP
ANDQ $~15, SP // alignment for x86_64 ABI ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$32 TEXT runtime·sigtramp(SB),NOSPLIT,$32
......
...@@ -188,11 +188,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8 ...@@ -188,11 +188,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24 TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
...@@ -208,14 +208,20 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-4 ...@@ -208,14 +208,20 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-4
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 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 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 CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12 TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
...@@ -184,11 +184,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8 ...@@ -184,11 +184,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24 TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
...@@ -212,14 +212,20 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0 ...@@ -212,14 +212,20 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 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 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 CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12 TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
...@@ -219,11 +219,16 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0-36 ...@@ -219,11 +219,16 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0-36
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24 TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
...@@ -216,14 +216,20 @@ TEXT runtime·sigaction(SB),NOSPLIT,$24 ...@@ -216,14 +216,20 @@ TEXT runtime·sigaction(SB),NOSPLIT,$24
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 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 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 CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12 TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
...@@ -238,11 +238,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8 ...@@ -238,11 +238,16 @@ TEXT runtime·sigaction(SB),NOSPLIT,$-8
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$32 TEXT runtime·sigtramp(SB),NOSPLIT,$32
......
...@@ -196,14 +196,20 @@ TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$-4 ...@@ -196,14 +196,20 @@ TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$-4
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 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 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 CALL AX
MOVL 12(SP), AX
MOVL AX, SP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$12 TEXT runtime·sigtramp(SB),NOSPLIT,$12
......
...@@ -229,11 +229,16 @@ TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0 ...@@ -229,11 +229,16 @@ TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24 TEXT runtime·sigtramp(SB),NOSPLIT,$24
......
...@@ -290,11 +290,16 @@ exit: ...@@ -290,11 +290,16 @@ exit:
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI MOVL sig+8(FP), DI
MOVQ info+16(FP), SI MOVQ info+16(FP), SI
MOVQ ctx+24(FP), DX MOVQ ctx+24(FP), DX
MOVQ fn+0(FP), AX PUSHQ BP
MOVQ SP, BP
ANDQ $~15, SP // alignment for x86_64 ABI
CALL AX CALL AX
MOVQ BP, SP
POPQ BP
RET RET
// Called from runtime·usleep (Go). Can be called on Go stack, on OS stack, // 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