blob: 8abb624909aa29e9ea97037f4500934a76ba3f04 (
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
55
56
57
58
59
60
61
|
/* $NetBSD: tramptest.c,v 1.2 2004/02/19 16:49:43 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, siginfo_t *si, void *ctx)
{
if (s != SIGSEGV || si->si_code != SEGV_ACCERR)
exit(2);
exit(0);
}
void (*f)(void);
void do_f()
{
(*f)();
}
int
main()
{
struct sigaction sa;
void mist()
{
return;
}
sa.sa_sigaction = buserr;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &sa, 0);
f = mist;
do_f();
exit(1);
}
|