summaryrefslogtreecommitdiffstats
path: root/misc/cgo/test/issue9400
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:23:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:23:18 +0000
commit43a123c1ae6613b3efeed291fa552ecd909d3acf (patch)
treefd92518b7024bc74031f78a1cf9e454b65e73665 /misc/cgo/test/issue9400
parentInitial commit. (diff)
downloadgolang-1.20-upstream.tar.xz
golang-1.20-upstream.zip
Adding upstream version 1.20.14.upstream/1.20.14upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--misc/cgo/test/issue9400/asm_386.s27
-rw-r--r--misc/cgo/test/issue9400/asm_amd64x.s27
-rw-r--r--misc/cgo/test/issue9400/asm_arm.s39
-rw-r--r--misc/cgo/test/issue9400/asm_arm64.s39
-rw-r--r--misc/cgo/test/issue9400/asm_loong64.s28
-rw-r--r--misc/cgo/test/issue9400/asm_mips64x.s33
-rw-r--r--misc/cgo/test/issue9400/asm_mipsx.s31
-rw-r--r--misc/cgo/test/issue9400/asm_ppc64x.s32
-rw-r--r--misc/cgo/test/issue9400/asm_riscv64.s31
-rw-r--r--misc/cgo/test/issue9400/asm_s390x.s26
-rw-r--r--misc/cgo/test/issue9400/gccgo.go26
-rw-r--r--misc/cgo/test/issue9400/stubs.go11
-rw-r--r--misc/cgo/test/issue9400_linux.go67
13 files changed, 417 insertions, 0 deletions
diff --git a/misc/cgo/test/issue9400/asm_386.s b/misc/cgo/test/issue9400/asm_386.s
new file mode 100644
index 0000000..96b8b60
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_386.s
@@ -0,0 +1,27 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT,$0-0
+ MOVL $·Baton(SB), BX
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADDL $(1024 * 8), SP
+
+ // Ask signaller to setgid
+ MOVL $1, (BX)
+
+ // Wait for setgid completion
+loop:
+ PAUSE
+ MOVL (BX), AX
+ CMPL AX, $0
+ JNE loop
+
+ // Restore stack
+ SUBL $(1024 * 8), SP
+ RET
diff --git a/misc/cgo/test/issue9400/asm_amd64x.s b/misc/cgo/test/issue9400/asm_amd64x.s
new file mode 100644
index 0000000..99509bc
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_amd64x.s
@@ -0,0 +1,27 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build amd64 amd64p32
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADDQ $(1024 * 8), SP
+
+ // Ask signaller to setgid
+ MOVL $1, ·Baton(SB)
+
+ // Wait for setgid completion
+loop:
+ PAUSE
+ MOVL ·Baton(SB), AX
+ CMPL AX, $0
+ JNE loop
+
+ // Restore stack
+ SUBQ $(1024 * 8), SP
+ RET
diff --git a/misc/cgo/test/issue9400/asm_arm.s b/misc/cgo/test/issue9400/asm_arm.s
new file mode 100644
index 0000000..cc92856
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_arm.s
@@ -0,0 +1,39 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gc
+
+#include "textflag.h"
+
+TEXT cas<>(SB),NOSPLIT,$0
+ MOVW $0xffff0fc0, R15 // R15 is PC
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Save link register
+ MOVW R14, R4
+
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADD $(1024 * 8), R13
+
+ // Ask signaller to setgid
+ MOVW $·Baton(SB), R2
+storeloop:
+ MOVW 0(R2), R0
+ MOVW $1, R1
+ BL cas<>(SB)
+ BCC storeloop
+
+ // Wait for setgid completion
+loop:
+ MOVW $0, R0
+ MOVW $0, R1
+ BL cas<>(SB)
+ BCC loop
+
+ // Restore stack
+ SUB $(1024 * 8), R13
+
+ MOVW R4, R14
+ RET
diff --git a/misc/cgo/test/issue9400/asm_arm64.s b/misc/cgo/test/issue9400/asm_arm64.s
new file mode 100644
index 0000000..2565793
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_arm64.s
@@ -0,0 +1,39 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Save link register
+ MOVD R30, R9
+
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADD $(1024 * 8), RSP
+
+ // Ask signaller to setgid
+ MOVD $·Baton(SB), R0
+ MOVD $1, R1
+storeloop:
+ LDAXRW (R0), R2
+ STLXRW R1, (R0), R3
+ CBNZ R3, storeloop
+
+ // Wait for setgid completion
+ MOVW $0, R1
+ MOVW $0, R2
+loop:
+ LDAXRW (R0), R3
+ CMPW R1, R3
+ BNE loop
+ STLXRW R2, (R0), R3
+ CBNZ R3, loop
+
+ // Restore stack
+ SUB $(1024 * 8), RSP
+
+ MOVD R9, R30
+ RET
diff --git a/misc/cgo/test/issue9400/asm_loong64.s b/misc/cgo/test/issue9400/asm_loong64.s
new file mode 100644
index 0000000..c242fc6
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_loong64.s
@@ -0,0 +1,28 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADDV $(1024*8), R3
+
+ // Ask signaller to setgid
+ MOVW $1, R12
+ DBAR
+ MOVW R12, ·Baton(SB)
+ DBAR
+
+ // Wait for setgid completion
+loop:
+ DBAR
+ MOVW ·Baton(SB), R12
+ OR R13, R13, R13 // hint that we're in a spin loop
+ BNE R12, loop
+ DBAR
+
+ // Restore stack
+ ADDV $(-1024*8), R3
+ RET
diff --git a/misc/cgo/test/issue9400/asm_mips64x.s b/misc/cgo/test/issue9400/asm_mips64x.s
new file mode 100644
index 0000000..693231d
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_mips64x.s
@@ -0,0 +1,33 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build mips64 mips64le
+// +build gc
+
+#include "textflag.h"
+
+#define SYNC WORD $0xf
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADDV $(1024*8), R29
+
+ // Ask signaller to setgid
+ MOVW $1, R1
+ SYNC
+ MOVW R1, ·Baton(SB)
+ SYNC
+
+ // Wait for setgid completion
+loop:
+ SYNC
+ MOVW ·Baton(SB), R1
+ OR R2, R2, R2 // hint that we're in a spin loop
+ BNE R1, loop
+ SYNC
+
+ // Restore stack
+ ADDV $(-1024*8), R29
+ RET
diff --git a/misc/cgo/test/issue9400/asm_mipsx.s b/misc/cgo/test/issue9400/asm_mipsx.s
new file mode 100644
index 0000000..63261bb
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_mipsx.s
@@ -0,0 +1,31 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build mips mipsle
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADDU $(1024*8), R29
+
+ // Ask signaller to setgid
+ MOVW $1, R1
+ SYNC
+ MOVW R1, ·Baton(SB)
+ SYNC
+
+ // Wait for setgid completion
+loop:
+ SYNC
+ MOVW ·Baton(SB), R1
+ OR R2, R2, R2 // hint that we're in a spin loop
+ BNE R1, loop
+ SYNC
+
+ // Restore stack
+ ADDU $(-1024*8), R29
+ RET
diff --git a/misc/cgo/test/issue9400/asm_ppc64x.s b/misc/cgo/test/issue9400/asm_ppc64x.s
new file mode 100644
index 0000000..b5613fb
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_ppc64x.s
@@ -0,0 +1,32 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ppc64 ppc64le
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADD $(1024 * 8), R1
+
+ // Ask signaller to setgid
+ MOVW $1, R3
+ SYNC
+ MOVW R3, ·Baton(SB)
+
+ // Wait for setgid completion
+loop:
+ SYNC
+ MOVW ·Baton(SB), R3
+ CMP R3, $0
+ // Hint that we're in a spin loop
+ OR R1, R1, R1
+ BNE loop
+ ISYNC
+
+ // Restore stack
+ SUB $(1024 * 8), R1
+ RET
diff --git a/misc/cgo/test/issue9400/asm_riscv64.s b/misc/cgo/test/issue9400/asm_riscv64.s
new file mode 100644
index 0000000..244dada
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_riscv64.s
@@ -0,0 +1,31 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build riscv64
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADD $(1024*8), X2
+
+ // Ask signaller to setgid
+ MOV $1, X5
+ FENCE
+ MOVW X5, ·Baton(SB)
+ FENCE
+
+ // Wait for setgid completion
+loop:
+ FENCE
+ MOVW ·Baton(SB), X5
+ OR X6, X6, X6 // hint that we're in a spin loop
+ BNE ZERO, X5, loop
+ FENCE
+
+ // Restore stack
+ ADD $(-1024*8), X2
+ RET
diff --git a/misc/cgo/test/issue9400/asm_s390x.s b/misc/cgo/test/issue9400/asm_s390x.s
new file mode 100644
index 0000000..4856492
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_s390x.s
@@ -0,0 +1,26 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gc
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT,$0-0
+ // Rewind stack pointer so anything that happens on the stack
+ // will clobber the test pattern created by the caller
+ ADD $(1024 * 8), R15
+
+ // Ask signaller to setgid
+ MOVD $·Baton(SB), R5
+ MOVW $1, 0(R5)
+
+ // Wait for setgid completion
+loop:
+ SYNC
+ MOVW ·Baton(SB), R3
+ CMPBNE R3, $0, loop
+
+ // Restore stack
+ SUB $(1024 * 8), R15
+ RET
diff --git a/misc/cgo/test/issue9400/gccgo.go b/misc/cgo/test/issue9400/gccgo.go
new file mode 100644
index 0000000..a9b62b0
--- /dev/null
+++ b/misc/cgo/test/issue9400/gccgo.go
@@ -0,0 +1,26 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gccgo
+
+package issue9400
+
+import (
+ "runtime"
+ "sync/atomic"
+)
+
+// The test for the gc compiler resets the stack pointer so that the
+// stack gets modified. We don't have a way to do that for gccgo
+// without writing more assembly code, which we haven't bothered to
+// do. So this is not much of a test.
+
+var Baton int32
+
+func RewindAndSetgid() {
+ atomic.StoreInt32(&Baton, 1)
+ for atomic.LoadInt32(&Baton) != 0 {
+ runtime.Gosched()
+ }
+}
diff --git a/misc/cgo/test/issue9400/stubs.go b/misc/cgo/test/issue9400/stubs.go
new file mode 100644
index 0000000..e431c5a
--- /dev/null
+++ b/misc/cgo/test/issue9400/stubs.go
@@ -0,0 +1,11 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gc
+
+package issue9400
+
+var Baton int32
+
+func RewindAndSetgid()
diff --git a/misc/cgo/test/issue9400_linux.go b/misc/cgo/test/issue9400_linux.go
new file mode 100644
index 0000000..38fa9dd
--- /dev/null
+++ b/misc/cgo/test/issue9400_linux.go
@@ -0,0 +1,67 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test that SIGSETXID runs on signal stack, since it's likely to
+// overflow if it runs on the Go stack.
+
+package cgotest
+
+/*
+#include <sys/types.h>
+#include <unistd.h>
+*/
+import "C"
+
+import (
+ "runtime"
+ "runtime/debug"
+ "sync/atomic"
+ "testing"
+
+ "misc/cgo/test/issue9400"
+)
+
+func test9400(t *testing.T) {
+ // We synchronize through a shared variable, so we need two procs
+ defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2))
+
+ // Start signaller
+ atomic.StoreInt32(&issue9400.Baton, 0)
+ go func() {
+ // Wait for RewindAndSetgid
+ for atomic.LoadInt32(&issue9400.Baton) == 0 {
+ runtime.Gosched()
+ }
+ // Broadcast SIGSETXID
+ runtime.LockOSThread()
+ C.setgid(0)
+ // Indicate that signalling is done
+ atomic.StoreInt32(&issue9400.Baton, 0)
+ }()
+
+ // Grow the stack and put down a test pattern
+ const pattern = 0x123456789abcdef
+ var big [1024]uint64 // len must match assembly
+ for i := range big {
+ big[i] = pattern
+ }
+
+ // Disable GC for the duration of the test.
+ // This avoids a potential GC deadlock when spinning in uninterruptable ASM below #49695.
+ defer debug.SetGCPercent(debug.SetGCPercent(-1))
+ // SetGCPercent waits until the mark phase is over, but the runtime
+ // also preempts at the start of the sweep phase, so make sure that's
+ // done too. See #49695.
+ runtime.GC()
+
+ // Temporarily rewind the stack and trigger SIGSETXID
+ issue9400.RewindAndSetgid()
+
+ // Check test pattern
+ for i := range big {
+ if big[i] != pattern {
+ t.Fatalf("entry %d of test pattern is wrong; %#x != %#x", i, big[i], uint64(pattern))
+ }
+ }
+}