File: main.c

package info (click to toggle)
golang 2%3A1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 60,232 kB
  • ctags: 121,778
  • sloc: asm: 36,876; ansic: 7,370; sh: 1,459; perl: 1,120; xml: 623; python: 286; yacc: 155; makefile: 89; cpp: 22; awk: 7
file content (73 lines) | stat: -rw-r--r-- 1,669 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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>

#include "p.h"
#include "libgo.h"

static void (*oldHandler)(int, siginfo_t*, void*);

static void handler(int signo, siginfo_t* info, void* ctxt) {
	if (oldHandler) {
		oldHandler(signo, info, ctxt);
	}
}

int main(void) {
	struct sigaction sa;
	struct sigaction osa;
	int32_t res;

	// 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;

	if (!DidInitRun()) {
		fprintf(stderr, "ERROR: buildmode=c-archive init should run\n");
		return 2;
	}

	if (DidMainRun()) {
		fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
		return 2;
	}

	// 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;
	}

	res = FromPkg();
	if (res != 1024) {
		fprintf(stderr, "ERROR: FromPkg()=%d, want 1024\n", res);
		return 2;
	}

	CheckArgs();

	fprintf(stderr, "PASS\n");
	return 0;
}