• 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 set to something
9  other than SS_DISABLE, and the ss argument is something other than a null pointer,
10  then sigaltstack() shall return -1 and set errno to [EINVAL].
11 
12  Steps:
13  - Set up a dummy handler for signal SIGTOTEST and set the sa_flags member to SA_ONSTACK.
14  - Allocate memory for the alternate signal stack (altstack1)
15  - Set the ss_flags member of the alternate stack to something other than SS_DISABLE
16  - call sigaltstack() to define the alternate signal stack
17  - Verify that sigaltstack() returns -1 and sets errno to [EINVAL].
18 */
19 
20 
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include "posixtest.h"
26 
27 #define SIGTOTEST SIGUSR1
28 
29 stack_t altstack1;
30 
handler()31 void handler()
32 {
33 	printf("Just a dummy handler\n");
34 }
35 
main(void)36 int main(void)
37 {
38 
39 	struct sigaction act;
40 	act.sa_flags = SA_ONSTACK;
41 	act.sa_handler = handler;
42 	sigemptyset(&act.sa_mask);
43 
44 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
45 		perror
46 		    ("Unexpected error while attempting to setup test pre-conditions");
47 		return PTS_UNRESOLVED;
48 	}
49 
50 	if ((altstack1.ss_sp = malloc(SIGSTKSZ)) == NULL) {
51 		perror
52 		    ("Unexpected error while attempting to setup test pre-conditions");
53 		return PTS_UNRESOLVED;
54 	}
55 
56 	altstack1.ss_flags = SS_DISABLE + 1;
57 	altstack1.ss_size = SIGSTKSZ;
58 
59 	if (sigaltstack(&altstack1, NULL) != -1) {
60 		printf("Test FAILED: Expected return value of -1.\n");
61 		return PTS_FAIL;
62 	}
63 
64 	if (errno != EINVAL) {
65 		printf("Test FAILED: Errno [EINVAL] was expected.\n");
66 		return PTS_FAIL;
67 	}
68 
69 	printf("Test PASSED\n");
70 	return PTS_PASS;
71 }
72