summaryrefslogtreecommitdiff
path: root/regress/sys/uvm/stack_noexec/tramptest.c
blob: a3582ff28857ba805dac30d5d5c80274d2c83e4f (plain)
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
/* $NetBSD: tramptest.c,v 1.1 2003/12/10 13:24:59 drochner Exp $ */

#include <stdlib.h>
#include <signal.h>

/*
 * This test checks that the stack has no execute permission.
 * It depends on the fact that gcc puts trampoline code for
 * nested functions on the stack, at least on some architectures.
 * (On the other architectures, the test will fail, as on platforms
 * where execution permissions cannot be controlled.)
 * Actually, it would be better if gcc wouldn't use stack trampolines,
 * at all, but for now it allows for an easy portable check whether the
 * stack is executable.
 */

void
__enable_execute_stack()
{
	/* replace gcc's internal function by a noop */
}

void
buserr(int s)
{

	exit(0);
}

void (*f)(void);

void do_f()
{

	(*f)();
}

int
main()
{

	void mist()
	{

		return;
	}

	signal(SIGBUS, buserr);

	f = mist;
	do_f();

	exit(1);
}