• 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 #define _XOPEN_SOURCE 600
21 
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include "posixtest.h"
27 
28 #define SIGTOTEST SIGUSR1
29 
30 stack_t altstack1;
31 
handler()32 void handler()
33 {
34 	printf("Just a dummy handler\n");
35 }
36 
main(void)37 int main(void)
38 {
39 
40 	struct sigaction act;
41 	act.sa_flags = SA_ONSTACK;
42 	act.sa_handler = handler;
43 	sigemptyset(&act.sa_mask);
44 
45 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
46 		perror
47 		    ("Unexpected error while attempting to setup test pre-conditions");
48 		return PTS_UNRESOLVED;
49 	}
50 
51 	if ((altstack1.ss_sp = malloc(SIGSTKSZ)) == NULL) {
52 		perror
53 		    ("Unexpected error while attempting to setup test pre-conditions");
54 		return PTS_UNRESOLVED;
55 	}
56 
57 	altstack1.ss_flags = 0;
58 	/* use value low enough for all kernel versions
59 	 * avoid using MINSIGSTKSZ defined by glibc as it could be different
60 	 * from the one in kernel ABI
61 	 */
62 	altstack1.ss_size = 2048 - 1;
63 
64 	if (sigaltstack(&altstack1, NULL) != -1) {
65 		printf("Test FAILED: Expected return value of -1.\n");
66 		return PTS_FAIL;
67 	}
68 
69 	if (errno != ENOMEM) {
70 		printf("Test FAILED: Errno [ENOMEM] was expected.\n");
71 		return PTS_FAIL;
72 	}
73 
74 	printf("Test PASSED\n");
75 	return PTS_PASS;
76 }
77