Merge commit '0b905b49d460a57773d88d714cd880ffe0182b7c'
[unleashed.git] / kernel / syscall / sigaltstack.c
blob4c310390b3ed454b7819c1a260107a1cd7157c8b
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/proc.h>
38 #include <sys/fault.h>
39 #include <sys/signal.h>
40 #include <sys/siginfo.h>
41 #include <sys/debug.h>
43 int
44 sigaltstack(struct sigaltstack *ssp, struct sigaltstack *oss)
46 klwp_t *lwp = ttolwp(curthread);
47 struct sigaltstack ss;
50 * User's oss and ss might be the same address, so copyin first and
51 * save before copying out.
53 if (ssp) {
54 if (lwp->lwp_sigaltstack.ss_flags & SS_ONSTACK)
55 return (set_errno(EPERM));
56 if (copyin(ssp, &ss, sizeof (ss)))
57 return (set_errno(EFAULT));
58 if (ss.ss_flags & ~SS_DISABLE)
59 return (set_errno(EINVAL));
60 if (!(ss.ss_flags & SS_DISABLE) && ss.ss_size < MINSIGSTKSZ)
61 return (set_errno(ENOMEM));
64 if (oss) {
65 if (copyout(&lwp->lwp_sigaltstack,
66 oss, sizeof (struct sigaltstack)))
67 return (set_errno(EFAULT));
70 if (ssp)
71 lwp->lwp_sigaltstack = ss;
73 return (0);
76 #ifdef _LP64
77 int
78 sigaltstack32(struct sigaltstack32 *ssp, struct sigaltstack32 *oss)
80 klwp_t *lwp = ttolwp(curthread);
81 struct sigaltstack *ss;
82 struct sigaltstack32 ss32, oss32;
85 * User's oss and ss might be the same address, so copyin first and
86 * save before copying out.
88 if (ssp) {
89 if (lwp->lwp_sigaltstack.ss_flags & SS_ONSTACK)
90 return (set_errno(EPERM));
91 if (copyin(ssp, &ss32, sizeof (ss32)))
92 return (set_errno(EFAULT));
93 if (ss32.ss_flags & ~SS_DISABLE)
94 return (set_errno(EINVAL));
95 if (!(ss32.ss_flags & SS_DISABLE) && ss32.ss_size < MINSIGSTKSZ)
96 return (set_errno(ENOMEM));
99 if (oss) {
101 * copy to ILP32 struct before copyout.
103 ss = &lwp->lwp_sigaltstack;
104 oss32.ss_sp = (caddr32_t)(uintptr_t)ss->ss_sp;
105 oss32.ss_size = (size32_t)ss->ss_size;
106 oss32.ss_flags = ss->ss_flags;
108 if (copyout(&oss32, oss, sizeof (oss32)))
109 return (set_errno(EFAULT));
112 if (ssp) {
113 ss = &lwp->lwp_sigaltstack;
114 ss->ss_sp = (void *)(uintptr_t)ss32.ss_sp;
115 ss->ss_size = (size_t)ss32.ss_size;
116 ss->ss_flags = ss32.ss_flags;
119 return (0);
121 #endif /* _LP64 */