1/*
2
3 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
4 * Created by:  rusty.lynch REMOVE-THIS AT intel DOT com
5 * This file is licensed under the GPL license.  For the full content
6 * of this license, see the COPYING file at the top level of this
7 * source tree.
8
9  Test case for assertion #13 of the sigaction system call that verifies
10  signal-catching functions are executed on the current stack if the
11  SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the
12  sigaction function call.
13
14  NOTE: This test case does not attempt to verify the proper operation
15        of sigaltstack.
16*/
17
18#define _XOPEN_SOURCE 600
19
20#include <signal.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include "posixtest.h"
24
25stack_t current;
26
27void handler(int signo)
28{
29	stack_t oss;
30
31	printf("Caught SIGSEGV\n");
32
33	if (sigaltstack((stack_t *)0, &oss) == -1) {
34		perror("Unexpected error while attempting to setup test "
35		       "pre-conditions");
36		exit(-1);
37	}
38
39	if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) {
40		printf("Test FAILED\n");
41		exit(-1);
42	}
43}
44
45int main()
46{
47	struct sigaction act;
48
49	act.sa_handler = handler;
50	act.sa_flags = 0;
51	sigemptyset(&act.sa_mask);
52	if (sigaction(SIGSEGV,  &act, 0) == -1) {
53		perror("Unexpected error while attempting to setup test "
54		       "pre-conditions");
55		return PTS_UNRESOLVED;
56	}
57
58	if (sigaltstack((stack_t *)0, &current) == -1) {
59		perror("Unexpected error while attempting to setup test "
60		       "pre-conditions");
61		return PTS_UNRESOLVED;
62	}
63
64	if (raise(SIGSEGV) == -1) {
65		perror("Unexpected error while attempting to setup test "
66		       "pre-conditions");
67		return PTS_UNRESOLVED;
68	}
69
70	printf("Test PASSED\n");
71	return PTS_PASS;
72}
73
74