1 /*
2 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
3 * Created by: salwan.searty REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license. For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8 This program tests the assertion that if ss_flags is set to SS_DISABLE, then
9 the alternate stack is disabled.
10
11 Steps:
12 - Set up a handler for signal SIGTOTEST and set the sa_flags member to SA_ONSTACK.
13 - Using the first call to sigaltstack(), get the process's current stack info (original_s.)
14 - Allocate memory for the alternate signal stack (alternate_s.)
15 - call sigaltstack() to define the alternate signal stack, and set ss_flags to SS_DISABLE
16 - raise SIGTOTEST
17 - Inside the handler, use sigaltstack() to obtain the current stack that the handler is
18 executing on (handler_s) and verify that:
19 1. The ss_sp member of the handler_s is equal to that of original_s.
20 2. The ss_size member of the hanlder_s is equal to that of original_s.
21 */
22
23
24 #include <signal.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "posixtest.h"
28
29 #define SIGTOTEST SIGUSR1
30
31 static stack_t alternate_s, original_s;
32
handler()33 void handler()
34 {
35
36 stack_t handler_s;
37
38 if (sigaltstack(NULL, &handler_s) == -1) {
39 perror
40 ("Unexpected error while attempting to setup test pre-conditions");
41 exit(PTS_UNRESOLVED);
42 }
43
44 if (handler_s.ss_sp != original_s.ss_sp) {
45 printf
46 ("Test FAILED: ss_sp of the handler's stack changed even though SS_DISABLE was set\n");
47 exit(PTS_FAIL);
48 }
49
50 if (handler_s.ss_size != original_s.ss_size) {
51 printf
52 ("Test FAILED: ss_size of the handler's stack changed even though SS_DISABLE was set\n");
53 exit(PTS_FAIL);
54 }
55
56 }
57
main(void)58 int main(void)
59 {
60
61 struct sigaction act;
62 act.sa_flags = SA_ONSTACK;
63 act.sa_handler = handler;
64 sigemptyset(&act.sa_mask);
65
66 if (sigaction(SIGUSR1, &act, 0) == -1) {
67 perror
68 ("Unexpected error while attempting to setup test pre-conditions");
69 return PTS_UNRESOLVED;
70 }
71
72 if (sigaltstack(NULL, &original_s) == -1) {
73 perror
74 ("Unexpected error while attempting to setup test pre-conditions");
75 return PTS_UNRESOLVED;
76 }
77
78 if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
79 perror
80 ("Unexpected error while attempting to setup test pre-conditions");
81 return PTS_UNRESOLVED;
82 }
83
84 alternate_s.ss_flags = SS_DISABLE;
85 alternate_s.ss_size = SIGSTKSZ;
86
87 if (sigaltstack(&alternate_s, NULL) == -1) {
88 perror
89 ("Unexpected error while attempting to setup test pre-conditions");
90 return PTS_UNRESOLVED;
91 }
92
93 if (raise(SIGUSR1) == -1) {
94 perror
95 ("Unexpected error while attempting to setup test pre-conditions");
96 return PTS_UNRESOLVED;
97 }
98
99 printf("Test PASSED\n");
100 return PTS_PASS;
101 }
102