1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build !windows,!android
7 // Test that the Go runtime still works if C code changes the signal stack.
18 static char signalStack[SIGSTKSZ];
20 static void changeSignalStack(void) {
22 memset(&ss, 0, sizeof ss);
23 ss.ss_sp = signalStack;
25 ss.ss_size = SIGSTKSZ;
26 if (sigaltstack(&ss, &oss) < 0) {
27 perror("sigaltstack");
32 static void restoreSignalStack(void) {
33 #if (defined(__x86_64__) || defined(__i386__)) && defined(__APPLE__)
34 // The Darwin C library enforces a minimum that the kernel does not.
35 // This is OK since we allocated this much space in mpreinit,
36 // it was just removed from the buffer by stackalloc.
37 oss.ss_size = MINSIGSTKSZ;
39 if (sigaltstack(&oss, NULL) < 0) {
40 perror("sigaltstack restore");
45 static int zero(void) {
56 func testSigaltstack(t
*testing
.T
) {
58 case runtime
.GOOS
== "solaris", runtime
.GOOS
== "darwin" && (runtime
.GOARCH
== "arm" || runtime
.GOARCH
== "arm64"):
59 t
.Skipf("switching signal stack not implemented on %s/%s", runtime
.GOOS
, runtime
.GOARCH
)
60 case runtime
.GOOS
== "darwin" && runtime
.GOARCH
== "386":
61 t
.Skipf("sigaltstack fails on darwin/386")
65 defer C
.restoreSignalStack()
68 t
.Error("did not see expected panic")
71 v
:= 1 / int(C
.zero())
72 t
.Errorf("unexpected success of division by zero == %d", v
)