• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 the ss_flags member is not set to SS_DISABLE,
9  the stack shall be enabled, and the ss_sp and ss_size members specify the new address
10  and size of the stack.
11 
12  Steps:
13  - Set up a handler for signal SIGTOTEST and set the sa_flags member to SA_ONSTACK.
14  - Allocate memory for the alternate signal stack
15  - call sigaltstack() to define the alternate signal stack
16  - raise SIGTOTEST
17  - Inside the handler, use sigaltstack to examine/obtain the current alternate signal
18    stack and verify:
19    1. The ss_sp member of the obtained alternate signal stack is equal to the ss_sp
20       that we defined in the main() function.
21    2. The ss_size member of the obtained alternate signal stack is equal to the ss_size
22       that we defined in the main() function.
23 */
24 
25 #define _XOPEN_SOURCE 600
26 
27 #include <signal.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "posixtest.h"
31 
32 #define SIGTOTEST SIGUSR1
33 
34 static stack_t alternate_s;
35 
handler()36 void handler()
37 {
38 
39 	stack_t handler_s;
40 
41 	if (sigaltstack(NULL, &handler_s) == -1) {
42 		perror
43 		    ("Unexpected error while attempting to setup test pre-conditions");
44 		exit(PTS_UNRESOLVED);
45 	}
46 
47 	if (handler_s.ss_sp != alternate_s.ss_sp) {
48 		printf
49 		    ("Test FAILED: ss_sp of the stack is not same as the defined one\n");
50 		exit(PTS_FAIL);
51 	}
52 
53 	if (handler_s.ss_size != alternate_s.ss_size) {
54 		printf
55 		    ("Test FAILED: ss_size of the stack is not same as the defined one\n");
56 		exit(PTS_FAIL);
57 	}
58 
59 }
60 
main(void)61 int main(void)
62 {
63 
64 	struct sigaction act;
65 	act.sa_flags = SA_ONSTACK;
66 	act.sa_handler = handler;
67 	sigemptyset(&act.sa_mask);
68 
69 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
70 		perror
71 		    ("Unexpected error while attempting to setup test pre-conditions");
72 		return PTS_UNRESOLVED;
73 	}
74 
75 	if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
76 		perror
77 		    ("Unexpected error while attempting to setup test pre-conditions");
78 		return PTS_UNRESOLVED;
79 	}
80 
81 	alternate_s.ss_flags = 0;
82 	alternate_s.ss_size = SIGSTKSZ;
83 
84 	if (sigaltstack(&alternate_s, NULL) == -1) {
85 		perror
86 		    ("Unexpected error while attempting to setup test pre-conditions");
87 		return PTS_UNRESOLVED;
88 	}
89 
90 	if (raise(SIGTOTEST) == -1) {
91 		perror
92 		    ("Unexpected error while attempting to setup test pre-conditions");
93 		return PTS_UNRESOLVED;
94 	}
95 
96 	printf("Test PASSED\n");
97 	return PTS_PASS;
98 }
99