Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / regress / sys / uvm / stack_exec / tramptest.c
blobd1b95582ac3cd61fe27307d3dfffb17b05d132ca
1 /* $NetBSD$ */
3 #include <stdlib.h>
4 #include <pthread.h>
5 #include <signal.h>
7 /*
8 * This test checks whether processes/threads get execute permission
9 * on the stack if needed, in particular for multiple threads.
10 * It depends on the fact that gcc puts trampoline code for
11 * nested functions on the stack and requests execution permission
12 * for that address internally, at least on some architectures.
13 * (On the other architectures, the test is just insignificant.)
14 * Actually, it would be better if gcc wouldn't use stack trampolines,
15 * at all, but for now it allows for an easy portable check whether the
16 * kernel handles permissions correctly.
19 void
20 buserr(int s)
23 exit(1);
26 int
27 main()
29 pthread_t t1, t2;
31 void *mist(void *p)
34 return (0);
37 signal(SIGBUS, buserr);
39 pthread_create(&t1, 0, mist, 0);
40 pthread_create(&t2, 0, mist, 0);
41 pthread_join(t1, 0);
42 pthread_join(t2, 0);
43 exit(0);