Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / solaris / context_stack.c
blobff3ade609cf2cfa35fb6dce4c733df282eb2b62b
1 /* Test of correct simulation for active stack. */
3 #include <assert.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <ucontext.h>
8 static char altstack_map[8096];
9 static volatile stack_t *sp;
11 static void sighandler(int sig)
13 /* Check that the alternate stack is active. */
14 assert(sp->ss_sp == altstack_map);
15 assert(sp->ss_size == sizeof(altstack_map));
16 assert(sp->ss_flags == SS_ONSTACK);
19 int main(void)
21 stack_t mainstack;
22 stack_t altstack;
23 struct sigaction sa;
24 /* Obtain an address inside the stack using a dirty trick. */
25 void *local = &sa;
27 /* Get an address for stack definition. */
28 if (getustack((stack_t**)&sp)) {
29 perror("getustack");
30 return 1;
33 /* Check the current stack. */
34 assert(sp->ss_sp <= local);
35 assert(local < (void*)((char*)sp->ss_sp + sp->ss_size));
36 assert(sp->ss_flags == 0);
38 /* Backup the current stack. */
39 mainstack = *sp;
41 /* Setup a signal handler. */
42 sa.sa_handler = sighandler;
43 sa.sa_flags = SA_ONSTACK;
44 if (sigfillset(&sa.sa_mask)) {
45 perror("sigfillset");
46 return 1;
48 if (sigaction(SIGUSR1, &sa, NULL)) {
49 perror("sigaction");
50 return 1;
53 /* Setup an alternate stack. */
54 altstack.ss_sp = altstack_map;
55 altstack.ss_size = sizeof(altstack_map);
56 altstack.ss_flags = 0;
57 if (sigaltstack(&altstack, NULL)) {
58 perror("sigaltstack");
59 return 1;
62 /* Raise a signal. */
63 raise(SIGUSR1);
65 /* Check the current stack. */
66 assert(mainstack.ss_sp == sp->ss_sp);
67 assert(mainstack.ss_size == sp->ss_size);
68 assert(mainstack.ss_flags == sp->ss_flags);
70 return 0;