blob: dd2ba43f5c41eb46604b7a6a7f3fcadd96b5373b [file] [log] [blame]
sewardj8eb8bab2015-07-21 14:44:28 +00001/* Test that the stack correctly dies after a setcontext(2) call. */
2
3#include <assert.h>
4#include <signal.h>
5#include <stdio.h>
6#include <ucontext.h>
7
8static volatile int *sp;
9
Elliott Hughesa0664b92017-04-18 17:46:52 -070010static void sighandler(int sig, siginfo_t *sip, void *arg)
sewardj8eb8bab2015-07-21 14:44:28 +000011{
Elliott Hughesa0664b92017-04-18 17:46:52 -070012 ucontext_t *ucp = (ucontext_t *) arg;
sewardj8eb8bab2015-07-21 14:44:28 +000013 sp = (int *) &ucp->uc_mcontext.gregs[0];
14}
15
16int main(void)
17{
18 struct sigaction sa;
19 /* Always-null value that is used to prevent any possible compiler
20 optimizations. */
21 volatile int zero = 0;
22
23 /* Setup a signal handler. */
Elliott Hughesa0664b92017-04-18 17:46:52 -070024 sa.sa_sigaction = sighandler;
sewardj8eb8bab2015-07-21 14:44:28 +000025 sa.sa_flags = SA_SIGINFO;
26 if (sigfillset(&sa.sa_mask)) {
27 perror("sigfillset");
28 return 1;
29 }
30 if (sigaction(SIGUSR1, &sa, NULL)) {
31 perror("sigaction");
32 return 1;
33 }
34
35 /* Raise a signal. */
36 raise(SIGUSR1);
37
38 /* Value pointed by sp should be at this point uninitialized. */
39 if (*sp && zero)
40 assert(0);
41
42 return 0;
43}
44