• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 
3  * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
4  * Created by:  rusty.lynch REMOVE-THIS AT intel DOT com
5  * This file is licensed under the GPL license.  For the full content
6  * of this license, see the COPYING file at the top level of this
7  * source tree.
8 
9   Test case for assertion #12 of the sigaction system call that verifies
10   signal-catching functions are executed on the alternate stack if the
11   SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the
12   sigaction function call, and an alternate stack has been setup with
13   sigaltstack().
14 
15   NOTE: This test case does not attempt to verify the proper operation
16         of sigaltstack.
17 */
18 
19 
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include "posixtest.h"
24 
25 static stack_t alt_ss;
26 
handler(int signo PTS_ATTRIBUTE_UNUSED)27 static void handler(int signo PTS_ATTRIBUTE_UNUSED)
28 {
29 	stack_t ss;
30 
31 	printf("Caught SIGINT\n");
32 
33 	if (sigaltstack(NULL, &ss) == -1) {
34 		perror("Unexpected error while attempting to setup test "
35 		       "pre-conditions");
36 		exit(-1);
37 	}
38 
39 	if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) {
40 		printf("Test FAILED\n");
41 		exit(-1);
42 	}
43 }
44 
main(void)45 int main(void)
46 {
47 	struct sigaction act;
48 
49 	act.sa_handler = handler;
50 	act.sa_flags = SA_ONSTACK;
51 	sigemptyset(&act.sa_mask);
52 	if (sigaction(SIGINT, &act, 0) == -1) {
53 		perror("Unexpected error while attempting to setup test "
54 		       "pre-conditions");
55 		return PTS_UNRESOLVED;
56 	}
57 
58 	if ((alt_ss.ss_sp = malloc(SIGSTKSZ)) == NULL) {
59 		perror("Unexpected error while attempting to setup test "
60 		       "pre-conditions");
61 		return PTS_UNRESOLVED;
62 	}
63 	alt_ss.ss_size = SIGSTKSZ;
64 	alt_ss.ss_flags = 0;
65 
66 	if (sigaltstack(&alt_ss, NULL) == -1) {
67 		perror("Unexpected error while attempting to setup test "
68 		       "pre-conditions");
69 		return PTS_UNRESOLVED;
70 	}
71 
72 	if (raise(SIGINT) == -1) {
73 		perror("Unexpected error while attempting to setup test "
74 		       "pre-conditions");
75 		return PTS_UNRESOLVED;
76 	}
77 
78 	printf("Test PASSED\n");
79 	return PTS_PASS;
80 }
81