• 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_size is equal to
9  something smaller that MINSIGSTKSZ, then sigaltstack() shall return -1
10  and set errno to [ENOMEM].
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), but make it one byte shorter
15    than MINSIGSTKSZ
16  - call sigaltstack() to define the alternate signal stack
17  - Verify that sigaltstack() returns -1 and sets errno to [ENOMEM].
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 = 0;
57 	/* use value low enough for all kernel versions
58 	 * avoid using MINSIGSTKSZ defined by glibc as it could be different
59 	 * from the one in kernel ABI
60 	 */
61 	altstack1.ss_size = 2048 - 1;
62 
63 	if (sigaltstack(&altstack1, NULL) != -1) {
64 		printf("Test FAILED: Expected return value of -1.\n");
65 		return PTS_FAIL;
66 	}
67 
68 	if (errno != ENOMEM) {
69 		printf("Test FAILED: Errno [ENOMEM] was expected.\n");
70 		return PTS_FAIL;
71 	}
72 
73 	printf("Test PASSED\n");
74 	return PTS_PASS;
75 }
76