]> Cypherpunks repositories - gostls13.git/commit
runtime: when using cgo on 386, call C sigaction function
authorIan Lance Taylor <iant@golang.org>
Sat, 6 Sep 2025 05:24:37 +0000 (22:24 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 10 Sep 2025 03:29:11 +0000 (20:29 -0700)
commitc5737dc21bbac9fbefc35ac9313e66291d66b382
tree978708188e3a609bbe63d9f900cadddf3e472fdd
parentb9a4a09b0fbb54b533f847c784c807db95f68d3b
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>
src/runtime/cgo/gcc_sigaction.c
src/runtime/cgo/sigaction.go
src/runtime/cgo_sigaction.go
src/runtime/crash_cgo_test.go
src/runtime/os_freebsd.go
src/runtime/os_linux.go
src/runtime/sigaction.go
src/runtime/sys_linux_386.s