mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
misc/cgo/testcarchive: split main.c into unix and non-unix
This is in support of https://golang.org/cl/18057 which adds support for c-archive to the Windows platform. The signal handling tests do not compile on Windows. This splits them out into a separate main_unix.c file, and conditionally includes them for non-Windows platforms. Change-Id: Ic79ce83da7656d6703505e514554748a482b81a1 Reviewed-on: https://go-review.googlesource.com/21086 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
135109d241
commit
93c5fbf390
4 changed files with 97 additions and 47 deletions
53
misc/cgo/testcarchive/main_unix.c
Normal file
53
misc/cgo/testcarchive/main_unix.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2015 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 <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
struct sigaction sa;
|
||||
struct sigaction osa;
|
||||
|
||||
static void (*oldHandler)(int, siginfo_t*, void*);
|
||||
|
||||
static void handler(int signo, siginfo_t* info, void* ctxt) {
|
||||
if (oldHandler) {
|
||||
oldHandler(signo, info, ctxt);
|
||||
}
|
||||
}
|
||||
|
||||
int install_handler() {
|
||||
// Install our own signal handler.
|
||||
memset(&sa, 0, sizeof sa);
|
||||
sa.sa_sigaction = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
|
||||
memset(&osa, 0, sizeof osa);
|
||||
sigemptyset(&osa.sa_mask);
|
||||
if (sigaction(SIGSEGV, &sa, &osa) < 0) {
|
||||
perror("sigaction");
|
||||
return 2;
|
||||
}
|
||||
if (osa.sa_handler == SIG_DFL || (osa.sa_flags&SA_ONSTACK) == 0) {
|
||||
fprintf(stderr, "Go runtime did not install signal handler\n");
|
||||
return 2;
|
||||
}
|
||||
oldHandler = osa.sa_sigaction;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_handler() {
|
||||
if (sigaction(SIGSEGV, NULL, &sa) < 0) {
|
||||
perror("sigaction check");
|
||||
return 2;
|
||||
}
|
||||
if (sa.sa_sigaction != handler) {
|
||||
fprintf(stderr, "ERROR: wrong signal handler: %p != %p\n", sa.sa_sigaction, handler);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue