xref: /titanic_41/usr/src/lib/libc/port/sys/sigstack.c (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include "synonyms.h"
34 #include <sys/types.h>
35 #include <sys/ucontext.h>
36 #include <signal.h>
37 #include <errno.h>
38 
39 int
40 sigstack(struct sigstack *nss, struct sigstack *oss)
41 {
42 	struct sigaltstack nalt;
43 	struct sigaltstack oalt;
44 	struct sigaltstack *naltp;
45 
46 	if (nss) {
47 		/* Assumes stack growth is down */
48 		nalt.ss_sp = (char *)nss->ss_sp - SIGSTKSZ;
49 		nalt.ss_size = SIGSTKSZ;
50 		nalt.ss_flags = 0;
51 		naltp = &nalt;
52 	} else
53 		naltp = (struct sigaltstack *)0;
54 
55 	if (sigaltstack(naltp, &oalt) < 0)
56 		return (-1);
57 
58 	if (oss) {
59 		/* Assumes stack growth is down */
60 		oss->ss_sp = (char *)oalt.ss_sp + oalt.ss_size;
61 		oss->ss_onstack = ((oalt.ss_flags & SS_ONSTACK) != 0);
62 	}
63 	return (0);
64 }
65