Home | History | Annotate | Download | only in sigaltstack
      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 #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 
     32 void handler()
     33 {
     34 	printf("Just a dummy handler\n");
     35 }
     36 
     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 = SS_DISABLE + 1;
     58 	altstack1.ss_size = SIGSTKSZ;
     59 
     60 	if (sigaltstack(&altstack1, NULL) != -1) {
     61 		printf("Test FAILED: Expected return value of -1.\n");
     62 		return PTS_FAIL;
     63 	}
     64 
     65 	if (errno != EINVAL) {
     66 		printf("Test FAILED: Errno [EINVAL] was expected.\n");
     67 		return PTS_FAIL;
     68 	}
     69 
     70 	printf("Test PASSED\n");
     71 	return PTS_PASS;
     72 }
     73