• 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 a signal explicitly declared to execute on
9  an alternate stack (using sigaltstack) shall be delivered on the alternate stack
10  specified by ss.
11 
12  While it is easy to use a call like sigaltstack((stack_t *)0, &oss) to verify
13  that the signal stack that the handler is being executed on is the same alternate
14  signal stack ss that I defined for that signal, I do not want to rely of the
15  use of oss since we're testing sigaltstack().
16 
17  Instead, what I do is declare an integer i inside the handler and verify that
18  at least the address of i is located between ss.ss_sp and ss.ss_size.
19 
20 */
21 
22 
23 #include <signal.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "posixtest.h"
27 
28 #define SIGTOTEST SIGUSR1
29 
30 stack_t alternate_s;
31 
handler()32 void handler()
33 {
34 	int i = 0;
35 	if ((void *)&i < (alternate_s.ss_sp)
36 	    || (long)&i >=
37 	    ((long)alternate_s.ss_sp + (long)alternate_s.ss_size)) {
38 
39 		printf
40 		    ("Test FAILED: address of local variable is not inside the memory allocated for the alternate signal stack\n");
41 		exit(PTS_FAIL);
42 	}
43 }
44 
main(void)45 int main(void)
46 {
47 
48 	struct sigaction act;
49 	act.sa_flags = SA_ONSTACK;
50 	act.sa_handler = handler;
51 	sigemptyset(&act.sa_mask);
52 
53 	if (sigaction(SIGUSR1, &act, 0) == -1) {
54 		perror
55 		    ("Unexpected error while attempting to setup test pre-conditions");
56 		return PTS_UNRESOLVED;
57 	}
58 
59 	if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
60 		perror
61 		    ("Unexpected error while attempting to setup test pre-conditions");
62 		return PTS_UNRESOLVED;
63 	}
64 
65 	alternate_s.ss_flags = 0;
66 	alternate_s.ss_size = SIGSTKSZ;
67 
68 	if (sigaltstack(&alternate_s, NULL) == -1) {
69 		perror
70 		    ("Unexpected error while attempting to setup test pre-conditions");
71 		return PTS_UNRESOLVED;
72 	}
73 
74 	if (raise(SIGUSR1) == -1) {
75 		perror
76 		    ("Unexpected error while attempting to setup test pre-conditions");
77 		return PTS_UNRESOLVED;
78 	}
79 
80 	printf("Test PASSED\n");
81 	return PTS_PASS;
82 }
83