Merge commit '7e3488dc6cdcb0c04e1ce167a1a3bfef83b5f2e0'
[unleashed.git] / kernel / syscall / sigprocmask.c
blobc98580655b36b107899e4717c90443c4e0a12f38
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 #include <sys/param.h>
30 #include <sys/types.h>
31 #include <sys/sysmacros.h>
32 #include <sys/systm.h>
33 #include <sys/errno.h>
34 #include <sys/proc.h>
35 #include <sys/fault.h>
36 #include <sys/signal.h>
37 #include <sys/schedctl.h>
38 #include <sys/debug.h>
40 /* ARGSUSED4 */
41 int64_t
42 lwp_sigmask(int how, uint_t bits0, uint_t bits1, uint_t bits2, uint_t bits3)
44 kthread_t *t = curthread;
45 proc_t *p = ttoproc(t);
46 rval_t rv;
49 * We don't need to acquire p->p_lock here;
50 * we are manipulating thread-private data.
53 schedctl_finish_sigblock(t);
55 bits0 &= (FILLSET0 & ~CANTMASK0);
56 bits1 &= (FILLSET1 & ~CANTMASK1);
57 bits2 &= (FILLSET2 & ~CANTMASK2);
60 * As a sop to the s10 brand, we continue to return
61 * the first two words of the signal mask, regardless
62 * of the value of 'how', even though libc doesn't use them.
64 rv.r_val1 = t->t_hold.__sigbits[0];
65 rv.r_val2 = t->t_hold.__sigbits[1];
67 switch (how) {
68 case SIG_BLOCK:
69 t->t_hold.__sigbits[0] |= bits0;
70 t->t_hold.__sigbits[1] |= bits1;
71 t->t_hold.__sigbits[2] |= bits2;
72 break;
73 case SIG_UNBLOCK:
74 t->t_hold.__sigbits[0] &= ~bits0;
75 t->t_hold.__sigbits[1] &= ~bits1;
76 t->t_hold.__sigbits[2] &= ~bits2;
77 if (sigcheck(p, t))
78 t->t_sig_check = 1;
79 break;
80 case SIG_SETMASK:
81 t->t_hold.__sigbits[0] = bits0;
82 t->t_hold.__sigbits[1] = bits1;
83 t->t_hold.__sigbits[2] = bits2;
84 if (sigcheck(p, t))
85 t->t_sig_check = 1;
86 break;
89 return (rv.r_vals);
92 int
93 sigprocmask(int how, sigset_t *setp, sigset_t *osetp)
95 sigset_t set;
96 sigset_t oset;
97 k_sigset_t kset;
100 * User's osetp and setp might be the same address,
101 * so copyin first and save before copying out.
103 if (setp) {
104 switch (how) {
105 case SIG_BLOCK:
106 case SIG_UNBLOCK:
107 case SIG_SETMASK:
108 break;
109 default:
110 return (set_errno(EINVAL));
112 if (copyin((caddr_t)setp, (caddr_t)&set, sizeof (sigset_t)))
113 return (set_errno(EFAULT));
114 sigutok(&set, &kset);
117 if (osetp) {
118 sigktou(&curthread->t_hold, &oset);
119 if (copyout((caddr_t)&oset, (caddr_t)osetp, sizeof (sigset_t)))
120 return (set_errno(EFAULT));
123 if (setp) {
124 (void) lwp_sigmask(how,
125 kset.__sigbits[0],
126 kset.__sigbits[1],
127 kset.__sigbits[2],
131 return (0);