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 oss points to the alternate structure 9 that was in effect prior to the call to sigaltstack. 10 11 */ 12 13 #define _XOPEN_SOURCE 600 14 15 #include <signal.h> 16 #include <stdio.h> 17 #include <stdlib.h> 18 #include "posixtest.h" 19 20 #define SIGTOTEST SIGUSR1 21 handler()22void handler() 23 { 24 printf("Do nothing useful\n"); 25 } 26 main(void)27int main(void) 28 { 29 30 stack_t alternate_s, current_s; 31 struct sigaction act; 32 act.sa_flags = SA_ONSTACK; 33 act.sa_handler = handler; 34 sigemptyset(&act.sa_mask); 35 36 if (sigaction(SIGUSR1, &act, 0) == -1) { 37 perror 38 ("Unexpected error while attempting to setup test pre-conditions"); 39 return PTS_UNRESOLVED; 40 } 41 42 if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) { 43 perror 44 ("Unexpected error while attempting to setup test pre-conditions"); 45 return PTS_UNRESOLVED; 46 } 47 48 alternate_s.ss_flags = 0; 49 alternate_s.ss_size = SIGSTKSZ; 50 51 if (sigaltstack(&alternate_s, NULL) == -1) { 52 perror 53 ("Unexpected error while attempting to setup test pre-conditions"); 54 return PTS_UNRESOLVED; 55 } 56 57 if (sigaltstack(NULL, ¤t_s) == -1) { 58 perror 59 ("Unexpected error while attempting to setup test pre-conditions"); 60 return PTS_UNRESOLVED; 61 } 62 63 if (current_s.ss_sp != alternate_s.ss_sp) { 64 printf 65 ("Test FAILED: ss_sp of the alternate stack is not same as the defined one\n"); 66 exit(PTS_FAIL); 67 } 68 69 if (current_s.ss_size != alternate_s.ss_size) { 70 printf 71 ("Test FAILED: ss_size of the alternate stack is not same as the defined one\n"); 72 exit(PTS_FAIL); 73 } 74 75 printf("Test PASSED\n"); 76 return PTS_PASS; 77 } 78