1/* $NetBSD: tramptest.c,v 1.1 2003/12/10 13:24:59 drochner Exp $ */ 2 3#include <stdlib.h> 4#include <signal.h> 5 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. 15 */ 16 17void 18__enable_execute_stack() 19{ 20 /* replace gcc's internal function by a noop */ 21} 22 23void 24buserr(int s, siginfo_t *si, void *ctx) 25{ 26 27 if (s != SIGSEGV || si->si_code != SEGV_ACCERR) 28 exit(2); 29 30 exit(0); 31} 32 33void (*f)(void); 34 35void do_f() 36{ 37 38 (*f)(); 39} 40 41int 42main() 43{ 44 struct sigaction sa; 45 46 void mist() 47 { 48 49 return; 50 } 51 52 sa.sa_sigaction = buserr; 53 sigemptyset(&sa.sa_mask); 54 sa.sa_flags = SA_SIGINFO; 55 sigaction(SIGSEGV, &sa, 0); 56 57 f = mist; 58 do_f(); 59 60 exit(1); 61} 62