• 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 (altstack1)
15  - call sigaltstack() to define the alternate signal stack
16  - raise SIGTOTEST
17  - Inside the handler, try to change the alternate signal stack to altstack2, and verify
18    that the attempt fails.
19 */
20 
21 #define _XOPEN_SOURCE 600
22 
23 #include <signal.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "posixtest.h"
27 
28 #define SIGTOTEST SIGUSR1
29 
30 static stack_t altstack1;
31 
handler()32 void handler()
33 {
34 	stack_t altstack2;
35 
36 	if ((altstack2.ss_sp = malloc(SIGSTKSZ)) == NULL) {
37 		perror
38 		    ("Unexpected error while attempting to setup test pre-conditions");
39 		exit(PTS_UNRESOLVED);
40 	}
41 
42 	altstack2.ss_flags = 0;
43 	altstack2.ss_size = SIGSTKSZ;
44 
45 	if (sigaltstack(&altstack2, NULL) != -1) {
46 		printf
47 		    ("Test FAILED: Attempt to set change alternate stack while inside handler succeeded.\n");
48 		exit(PTS_FAIL);
49 	}
50 }
51 
main(void)52 int main(void)
53 {
54 
55 	struct sigaction act;
56 	act.sa_flags = SA_ONSTACK;
57 	act.sa_handler = handler;
58 	sigemptyset(&act.sa_mask);
59 
60 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
61 		perror
62 		    ("Unexpected error while attempting to setup test pre-conditions");
63 		return PTS_UNRESOLVED;
64 	}
65 
66 	if ((altstack1.ss_sp = malloc(SIGSTKSZ)) == NULL) {
67 		perror
68 		    ("Unexpected error while attempting to setup test pre-conditions");
69 		return PTS_UNRESOLVED;
70 	}
71 
72 	altstack1.ss_flags = 0;
73 	altstack1.ss_size = SIGSTKSZ;
74 
75 	if (sigaltstack(&altstack1, NULL) == -1) {
76 		perror
77 		    ("Unexpected error while attempting to setup test pre-conditions");
78 		return PTS_UNRESOLVED;
79 	}
80 
81 	if (raise(SIGTOTEST) == -1) {
82 		perror
83 		    ("Unexpected error while attempting to setup test pre-conditions");
84 		return PTS_UNRESOLVED;
85 	}
86 
87 	printf("Test PASSED\n");
88 	return PTS_PASS;
89 }
90