1 /* Test of correct simulation for active stack. */
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
);
24 /* Obtain an address inside the stack using a dirty trick. */
27 /* Get an address for stack definition. */
28 if (getustack((stack_t
**)&sp
)) {
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. */
41 /* Setup a signal handler. */
42 sa
.sa_handler
= sighandler
;
43 sa
.sa_flags
= SA_ONSTACK
;
44 if (sigfillset(&sa
.sa_mask
)) {
48 if (sigaction(SIGUSR1
, &sa
, NULL
)) {
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");
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
);