Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / sys / uvm / stack_noexec / tramptest.c
blob486139d6826ca7db1d6b6f045c05f9a4464ae587
1 /* $NetBSD: tramptest.c,v 1.1 2003/12/10 13:24:59 drochner Exp $ */
3 #include <stdlib.h>
4 #include <signal.h>
6 /*
7 * This test checks that the stack has no execute permission.
8 * It depends on the fact that gcc puts trampoline code for
9 * nested functions on the stack, at least on some architectures.
10 * (On the other architectures, the test will fail, as on platforms
11 * where execution permissions cannot be controlled.)
12 * Actually, it would be better if gcc wouldn't use stack trampolines,
13 * at all, but for now it allows for an easy portable check whether the
14 * stack is executable.
17 void
18 __enable_execute_stack()
20 /* replace gcc's internal function by a noop */
23 void
24 buserr(int s, siginfo_t *si, void *ctx)
27 if (s != SIGSEGV || si->si_code != SEGV_ACCERR)
28 exit(2);
30 exit(0);
33 void (*f)(void);
35 void do_f()
38 (*f)();
41 int
42 main()
44 struct sigaction sa;
46 void mist()
49 return;
52 sa.sa_sigaction = buserr;
53 sigemptyset(&sa.sa_mask);
54 sa.sa_flags = SA_SIGINFO;
55 sigaction(SIGSEGV, &sa, 0);
57 f = mist;
58 do_f();
60 exit(1);