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 //go:build !windows && !android
7 // Test that the Go runtime still works if C code changes the signal stack.
18 // On AIX, SIGSTKSZ is too small to handle Go sighandler.
19 #define CSIGSTKSZ 0x4000
21 #define CSIGSTKSZ SIGSTKSZ
25 static char signalStack[CSIGSTKSZ];
27 static void changeSignalStack(void) {
29 memset(&ss, 0, sizeof ss);
30 ss.ss_sp = signalStack;
32 ss.ss_size = CSIGSTKSZ;
33 if (sigaltstack(&ss, &oss) < 0) {
34 perror("sigaltstack");
39 static void restoreSignalStack(void) {
40 #if (defined(__x86_64__) || defined(__i386__)) && defined(__APPLE__)
41 // The Darwin C library enforces a minimum that the kernel does not.
42 // This is OK since we allocated this much space in mpreinit,
43 // it was just removed from the buffer by stackalloc.
44 oss.ss_size = MINSIGSTKSZ;
46 if (sigaltstack(&oss, NULL) < 0) {
47 perror("sigaltstack restore");
52 static int zero(void) {
63 func testSigaltstack(t *testing.T) {
65 case runtime.GOOS == "solaris", runtime.GOOS == "illumos", runtime.GOOS == "ios" && runtime.GOARCH == "arm64":
66 t.Skipf("switching signal stack not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
70 defer C.restoreSignalStack()
73 t.Error("did not see expected panic")
76 v := 1 / int(C.zero())
77 t.Errorf("unexpected success of division by zero == %d", v)