• 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 that the ss_flags member of the obtained alternate signal stack is SS_DISABLE.
19 */
20 
21 
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include "posixtest.h"
26 
27 #define SIGTOTEST SIGUSR1
28 
29 static stack_t alternate_s;
30 
handler()31 void handler()
32 {
33 	stack_t handler_s;
34 
35 	if (sigaltstack(NULL, &handler_s) == -1) {
36 		perror
37 		    ("Unexpected error while attempting to setup test pre-conditions");
38 		exit(PTS_UNRESOLVED);
39 	}
40 
41 	if (handler_s.ss_flags != SS_DISABLE) {
42 		printf
43 		    ("Test FAILED: The alternate stack's ss_flags member does not contain SS_DISABLE even though the alternate signal stack is disabled.\n");
44 		exit(PTS_FAIL);
45 	}
46 }
47 
main(void)48 int main(void)
49 {
50 
51 	struct sigaction act;
52 	act.sa_flags = SA_ONSTACK;
53 	act.sa_handler = handler;
54 	sigemptyset(&act.sa_mask);
55 
56 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
57 		perror
58 		    ("Unexpected error while attempting to setup test pre-conditions");
59 		return PTS_UNRESOLVED;
60 	}
61 
62 	if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
63 		perror
64 		    ("Unexpected error while attempting to setup test pre-conditions");
65 		return PTS_UNRESOLVED;
66 	}
67 
68 	alternate_s.ss_flags = SS_DISABLE;
69 	alternate_s.ss_size = SIGSTKSZ;
70 
71 	if (sigaltstack(&alternate_s, NULL) == -1) {
72 		perror
73 		    ("Unexpected error while attempting to setup test pre-conditions");
74 		return PTS_UNRESOLVED;
75 	}
76 
77 	if (raise(SIGTOTEST) == -1) {
78 		perror
79 		    ("Unexpected error while attempting to setup test pre-conditions");
80 		return PTS_UNRESOLVED;
81 	}
82 
83 	printf("Test PASSED\n");
84 	return PTS_PASS;
85 }
86