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 a signal explicitly declared to execute on 9 an alternate stack (using sigaltstack) shall be delivered on the alternate stack 10 specified by ss. 11 12 While it is easy to use a call like sigaltstack((stack_t *)0, &oss) to verify 13 that the signal stack that the handler is being executed on is the same alternate 14 signal stack ss that I defined for that signal, I do not want to rely of the 15 use of oss since we're testing sigaltstack(). 16 17 Instead, what I do is declare an integer i inside the handler and verify that 18 at least the address of i is located between ss.ss_sp and ss.ss_size. 19 20 */ 21 22 #define _XOPEN_SOURCE 600 23 24 #include <signal.h> 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include "posixtest.h" 28 29 #define SIGTOTEST SIGUSR1 30 31 stack_t alternate_s; 32 handler()33void handler() 34 { 35 int i = 0; 36 if ((void *)&i < (alternate_s.ss_sp) 37 || (long)&i >= 38 ((long)alternate_s.ss_sp + (long)alternate_s.ss_size)) { 39 40 printf 41 ("Test FAILED: address of local variable is not inside the memory allocated for the alternate signal stack\n"); 42 exit(PTS_FAIL); 43 } 44 } 45 main(void)46int main(void) 47 { 48 49 struct sigaction act; 50 act.sa_flags = SA_ONSTACK; 51 act.sa_handler = handler; 52 sigemptyset(&act.sa_mask); 53 54 if (sigaction(SIGUSR1, &act, 0) == -1) { 55 perror 56 ("Unexpected error while attempting to setup test pre-conditions"); 57 return PTS_UNRESOLVED; 58 } 59 60 if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) { 61 perror 62 ("Unexpected error while attempting to setup test pre-conditions"); 63 return PTS_UNRESOLVED; 64 } 65 66 alternate_s.ss_flags = 0; 67 alternate_s.ss_size = SIGSTKSZ; 68 69 if (sigaltstack(&alternate_s, NULL) == -1) { 70 perror 71 ("Unexpected error while attempting to setup test pre-conditions"); 72 return PTS_UNRESOLVED; 73 } 74 75 if (raise(SIGUSR1) == -1) { 76 perror 77 ("Unexpected error while attempting to setup test pre-conditions"); 78 return PTS_UNRESOLVED; 79 } 80 81 printf("Test PASSED\n"); 82 return PTS_PASS; 83 } 84