2015-04-13 09:31:14 -06:00
|
|
|
// 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.
|
|
|
|
|
2015-12-26 10:51:59 -07:00
|
|
|
#include <signal.h>
|
2015-04-13 09:31:14 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2015-12-26 10:51:59 -07:00
|
|
|
#include <string.h>
|
2015-04-13 09:31:14 -06:00
|
|
|
|
2015-05-06 23:06:19 -06:00
|
|
|
#include "p.h"
|
|
|
|
#include "libgo.h"
|
2015-04-13 09:31:14 -06:00
|
|
|
|
2015-12-26 10:51:59 -07:00
|
|
|
static void (*oldHandler)(int, siginfo_t*, void*);
|
|
|
|
|
|
|
|
static void handler(int signo, siginfo_t* info, void* ctxt) {
|
|
|
|
if (oldHandler) {
|
|
|
|
oldHandler(signo, info, ctxt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 09:31:14 -06:00
|
|
|
int main(void) {
|
2015-12-26 10:51:59 -07:00
|
|
|
struct sigaction sa;
|
|
|
|
struct sigaction osa;
|
2015-04-13 12:54:36 -06:00
|
|
|
int32_t res;
|
2015-04-13 09:31:14 -06:00
|
|
|
|
2015-12-26 10:51:59 -07:00
|
|
|
// 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;
|
|
|
|
|
2015-04-13 17:31:39 -06:00
|
|
|
if (!DidInitRun()) {
|
|
|
|
fprintf(stderr, "ERROR: buildmode=c-archive init should run\n");
|
2015-04-13 09:31:14 -06:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2015-04-13 17:31:39 -06:00
|
|
|
if (DidMainRun()) {
|
|
|
|
fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
|
2015-04-13 09:31:14 -06:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2015-12-26 10:51:59 -07:00
|
|
|
// Make sure our signal handler is still the one in use.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-13 09:31:14 -06:00
|
|
|
res = FromPkg();
|
2015-04-13 12:54:36 -06:00
|
|
|
if (res != 1024) {
|
|
|
|
fprintf(stderr, "ERROR: FromPkg()=%d, want 1024\n", res);
|
2015-04-13 09:31:14 -06:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2015-04-17 14:42:16 -06:00
|
|
|
CheckArgs();
|
|
|
|
|
2015-04-20 07:33:25 -06:00
|
|
|
fprintf(stderr, "PASS\n");
|
2015-04-13 09:31:14 -06:00
|
|
|
return 0;
|
|
|
|
}
|