• 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 oss points to the alternate structure
9  that was in effect prior to the call to sigaltstack.
10 
11 */
12 
13 
14 #include <signal.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "posixtest.h"
18 
19 #define SIGTOTEST SIGUSR1
20 
handler()21 void handler()
22 {
23 	printf("Do nothing useful\n");
24 }
25 
main(void)26 int main(void)
27 {
28 
29 	stack_t alternate_s, current_s;
30 	struct sigaction act;
31 	act.sa_flags = SA_ONSTACK;
32 	act.sa_handler = handler;
33 	sigemptyset(&act.sa_mask);
34 
35 	if (sigaction(SIGUSR1, &act, 0) == -1) {
36 		perror
37 		    ("Unexpected error while attempting to setup test pre-conditions");
38 		return PTS_UNRESOLVED;
39 	}
40 
41 	if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
42 		perror
43 		    ("Unexpected error while attempting to setup test pre-conditions");
44 		return PTS_UNRESOLVED;
45 	}
46 
47 	alternate_s.ss_flags = 0;
48 	alternate_s.ss_size = SIGSTKSZ;
49 
50 	if (sigaltstack(&alternate_s, NULL) == -1) {
51 		perror
52 		    ("Unexpected error while attempting to setup test pre-conditions");
53 		return PTS_UNRESOLVED;
54 	}
55 
56 	if (sigaltstack(NULL, &current_s) == -1) {
57 		perror
58 		    ("Unexpected error while attempting to setup test pre-conditions");
59 		return PTS_UNRESOLVED;
60 	}
61 
62 	if (current_s.ss_sp != alternate_s.ss_sp) {
63 		printf
64 		    ("Test FAILED: ss_sp of the alternate stack is not same as the defined one\n");
65 		exit(PTS_FAIL);
66 	}
67 
68 	if (current_s.ss_size != alternate_s.ss_size) {
69 		printf
70 		    ("Test FAILED: ss_size of the alternate stack is not same as the defined one\n");
71 		exit(PTS_FAIL);
72 	}
73 
74 	printf("Test PASSED\n");
75 	return PTS_PASS;
76 }
77