]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, runtime/cgo: use libc for sigaction syscalls when cgo is enabled on loong64
authorlimeidan <limeidan@loongson.cn>
Wed, 5 Mar 2025 07:07:07 +0000 (15:07 +0800)
committerabner chenc <chenguoqi@loongson.cn>
Tue, 18 Mar 2025 01:30:39 +0000 (18:30 -0700)
This ensures that runtime's signal handlers pass through the TSAN and
MSAN libc interceptors and subsequent calls to the intercepted
sigaction function from C will correctly see them.

Change-Id: I243a70d9dcb6d95a65c8494d5f9f9f09a316c693
Reviewed-on: https://go-review.googlesource.com/c/go/+/654995
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/cgo/gcc_sigaction.c
src/runtime/cgo/sigaction.go
src/runtime/cgo_sigaction.go
src/runtime/sigaction.go
src/runtime/sys_linux_loong64.s

index 374909bf9768e171e6e12bc181db95400ea017ba..7cbef7db11518515e51a4e870e2b94060ae282a1 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build linux && (amd64 || arm64 || ppc64le)
+//go:build linux && (amd64 || arm64 || loong64 || ppc64le)
 
 #include <errno.h>
 #include <stddef.h>
 #include "libcgo.h"
 
 // go_sigaction_t is a C version of the sigactiont struct from
-// defs_linux_amd64.go.  This definition — and its conversion to and from struct
-// sigaction — are specific to linux/amd64.
+// defs_${goos}_${goarch}.go.  This definition — and its conversion
+// to and from struct sigaction — are specific to ${goos}/${goarch}.
 typedef struct {
        uintptr_t handler;
        uint64_t flags;
+#ifdef __loongarch__
+       uint64_t mask;
+       uintptr_t restorer;
+#else
        uintptr_t restorer;
        uint64_t mask;
+#endif
 } go_sigaction_t;
 
 // SA_RESTORER is part of the kernel interface.
index dc714f7ef4a3b08b06231a534591fa6b3c92a46e..dc3f5fd2552eefc29db50ffefc47f755fad15780 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build (linux && amd64) || (freebsd && amd64) || (linux && arm64) || (linux && ppc64le)
+//go:build (linux && (amd64 || arm64 || loong64 || ppc64le)) || (freebsd && amd64)
 
 package cgo
 
index 9500c522059580be42f8d7e6c97e3b95eb8576f3..5c644587f0da829c93f7d2e24ec88498dd798e1d 100644 (file)
@@ -4,7 +4,7 @@
 
 // Support for sanitizers. See runtime/cgo/sigaction.go.
 
-//go:build (linux && amd64) || (freebsd && amd64) || (linux && arm64) || (linux && ppc64le)
+//go:build (linux && (amd64 || arm64 || loong64 || ppc64le)) || (freebsd && amd64)
 
 package runtime
 
index 05f44f65dbcd5614499fd1a0e2393ffdb0bc213b..2027ae80bf2b88ffb69a9f00d6d6642b31ceb46d 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build (linux && !amd64 && !arm64 && !ppc64le) || (freebsd && !amd64)
+//go:build (linux && !amd64 && !arm64 && !loong64 && !ppc64le) || (freebsd && !amd64)
 
 package runtime
 
index 1121b3c991699d4921bb2bc7927e93afba81b5ac..84630c16d83448dba205d47d072b20139f74b430 100644 (file)
@@ -378,6 +378,16 @@ TEXT runtime·rt_sigaction<ABIInternal>(SB),NOSPLIT,$0
        SYSCALL
        RET
 
+// Call the function stored in _cgo_sigaction using the GCC calling convention.
+TEXT runtime·callCgoSigaction<ABIInternal>(SB),NOSPLIT,$0
+       // R4: sig, R5: new, R6: old
+       MOVV    _cgo_sigaction(SB), R7
+       SUBV    $16, R3 // reserve 16 bytes for sp-8 where fp may be saved.
+       JAL     (R7)
+       ADDV    $16, R3
+       MOVW    R4, R4
+       RET
+
 // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
 TEXT runtime·sigfwd<ABIInternal>(SB),NOSPLIT,$0
        // before: