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 #define _XOPEN_SOURCE 600
24
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "posixtest.h"
29
30 #define SIGTOTEST SIGUSR1
31
32 static stack_t alternate_s, original_s;
33
handler()34 void handler()
35 {
36
37 stack_t handler_s;
38
39 if (sigaltstack(NULL, &handler_s) == -1) {
40 perror
41 ("Unexpected error while attempting to setup test pre-conditions");
42 exit(PTS_UNRESOLVED);
43 }
44
45 if (handler_s.ss_sp != original_s.ss_sp) {
46 printf
47 ("Test FAILED: ss_sp of the handler's stack changed even though SS_DISABLE was set\n");
48 exit(PTS_FAIL);
49 }
50
51 if (handler_s.ss_size != original_s.ss_size) {
52 printf
53 ("Test FAILED: ss_size of the handler's stack changed even though SS_DISABLE was set\n");
54 exit(PTS_FAIL);
55 }
56
57 }
58
main(void)59 int main(void)
60 {
61
62 struct sigaction act;
63 act.sa_flags = SA_ONSTACK;
64 act.sa_handler = handler;
65 sigemptyset(&act.sa_mask);
66
67 if (sigaction(SIGUSR1, &act, 0) == -1) {
68 perror
69 ("Unexpected error while attempting to setup test pre-conditions");
70 return PTS_UNRESOLVED;
71 }
72
73 if (sigaltstack(NULL, &original_s) == -1) {
74 perror
75 ("Unexpected error while attempting to setup test pre-conditions");
76 return PTS_UNRESOLVED;
77 }
78
79 if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
80 perror
81 ("Unexpected error while attempting to setup test pre-conditions");
82 return PTS_UNRESOLVED;
83 }
84
85 alternate_s.ss_flags = SS_DISABLE;
86 alternate_s.ss_size = SIGSTKSZ;
87
88 if (sigaltstack(&alternate_s, NULL) == -1) {
89 perror
90 ("Unexpected error while attempting to setup test pre-conditions");
91 return PTS_UNRESOLVED;
92 }
93
94 if (raise(SIGUSR1) == -1) {
95 perror
96 ("Unexpected error while attempting to setup test pre-conditions");
97 return PTS_UNRESOLVED;
98 }
99
100 printf("Test PASSED\n");
101 return PTS_PASS;
102 }
103