diff options
| author | Ian Lance Taylor <iant@golang.org> | 2025-09-05 22:24:37 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-09-09 20:29:11 -0700 |
| commit | c5737dc21bbac9fbefc35ac9313e66291d66b382 (patch) | |
| tree | 978708188e3a609bbe63d9f900cadddf3e472fdd /src/runtime/sys_linux_386.s | |
| parent | b9a4a09b0fbb54b533f847c784c807db95f68d3b (diff) | |
| download | go-c5737dc21bbac9fbefc35ac9313e66291d66b382.tar.xz | |
runtime: when using cgo on 386, call C sigaction function
On 386 the C sigaction function assumes that the caller does not set
the SA_RESTORER flag. It does not copy the C sa_restorer field to
the kernel sa_restorer field. The effect is that the kernel sees
the SA_RESTORER flag but a NULL sa_restorer field, and the program
crashes when returning from a signal handler.
On the other hand, the C sigaction function will return the SA_RESTORER
flag and the sa_restorer field stored in the kernel.
This means that if the Go runtime installs a signal handler,
with SA_RESTORER as is required when calling the kernel,
and the Go program calls C code that calls the C sigaction function
to query the current signal handler, that C code will get a result
that it can't pass back to sigaction.
This CL fixes the problem by using the C sigaction function
for 386 programs that use cgo. This reuses the functionality
used on amd64 and other GOARCHs to support the race detector.
See #75253, or runtime/testdata/testprogcgo/eintr.go, for sample
code that used to fail on 386. No new test case is required,
we just remove the skip we used to have for eintr.go.
Fixes #75253
Change-Id: I803059b1fb9e09e9fbb43f68eccb6a59a92c2991
Reviewed-on: https://go-review.googlesource.com/c/go/+/701375
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/sys_linux_386.s')
| -rw-r--r-- | src/runtime/sys_linux_386.s | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s index d53be243fe..8e832687e0 100644 --- a/src/runtime/sys_linux_386.s +++ b/src/runtime/sys_linux_386.s @@ -410,6 +410,25 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0 MOVL AX, ret+16(FP) RET +// Call the function stored in _cgo_sigaction using the GCC calling convention. +TEXT runtime·callCgoSigaction(SB),NOSPLIT,$0-16 + MOVL _cgo_sigaction(SB), AX + MOVL sig+0(FP), BX + MOVL new+4(FP), CX + MOVL old+8(FP), DX + MOVL SP, SI // align stack to call C function + SUBL $32, SP + ANDL $~15, SP + MOVL BX, 0(SP) + MOVL CX, 4(SP) + MOVL DX, 8(SP) + MOVL SI, 12(SP) + CALL AX + MOVL 12(SP), BX + MOVL BX, SP + MOVL AX, ret+12(FP) + RET + TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 MOVL fn+0(FP), AX MOVL sig+4(FP), BX |
