xref: /titanic_41/usr/src/uts/common/syscall/sigprocmask.c (revision bbb1277b6ec1b0daad4e3ed1a2b891d3e2ece2eb)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 
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>
39 
40 int64_t
41 lwp_sigmask(int how, uint_t bits0, uint_t bits1)
42 {
43 	kthread_t *t = curthread;
44 	proc_t *p = ttoproc(t);
45 	rval_t rv;
46 
47 	/*
48 	 * We don't need to acquire p->p_lock here;
49 	 * we are manipulating thread-private data.
50 	 */
51 
52 	schedctl_finish_sigblock(t);
53 
54 	bits0 &= (FILLSET0 & ~CANTMASK0);
55 	bits1 &= (FILLSET1 & ~CANTMASK1);
56 
57 	rv.r_val1 = t->t_hold.__sigbits[0];
58 	rv.r_val2 = t->t_hold.__sigbits[1];
59 
60 	switch (how) {
61 	case SIG_BLOCK:
62 		t->t_hold.__sigbits[0] |= bits0;
63 		t->t_hold.__sigbits[1] |= bits1;
64 		break;
65 	case SIG_UNBLOCK:
66 		t->t_hold.__sigbits[0] &= ~bits0;
67 		t->t_hold.__sigbits[1] &= ~bits1;
68 		if (sigcheck(p, t))
69 			t->t_sig_check = 1;
70 		break;
71 	case SIG_SETMASK:
72 		t->t_hold.__sigbits[0] = bits0;
73 		t->t_hold.__sigbits[1] = bits1;
74 		if (sigcheck(p, t))
75 			t->t_sig_check = 1;
76 		break;
77 	}
78 
79 	return (rv.r_vals);
80 }
81 
82 /*
83  * This system call is no longer called from libc.
84  * It exists solely for the benefit of statically-linked
85  * binaries from the past.  It should be eliminated.
86  */
87 int
88 sigprocmask(int how, sigset_t *setp, sigset_t *osetp)
89 {
90 	sigset_t set;
91 	k_sigset_t kset;
92 	rval_t rv;
93 
94 	/*
95 	 * User's oset and set might be the same address, so copyin first and
96 	 * save before copying out.
97 	 */
98 	if (setp) {
99 		switch (how) {
100 		case SIG_BLOCK:
101 		case SIG_UNBLOCK:
102 		case SIG_SETMASK:
103 			break;
104 		default:
105 			return (set_errno(EINVAL));
106 		}
107 		if (copyin((caddr_t)setp, (caddr_t)&set, sizeof (sigset_t)))
108 			return (set_errno(EFAULT));
109 		sigutok(&set, &kset);
110 	} else {
111 		/* none of SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK equals 0 */
112 		how = 0;
113 		sigemptyset(&kset);
114 	}
115 
116 	rv.r_vals = lwp_sigmask(how, kset.__sigbits[0], kset.__sigbits[1]);
117 
118 	if (osetp) {
119 		kset.__sigbits[0] = rv.r_val1;
120 		kset.__sigbits[1] = rv.r_val2;
121 		sigktou(&kset, &set);
122 		if (copyout((caddr_t)&set, (caddr_t)osetp, sizeof (sigset_t)))
123 			return (set_errno(EFAULT));
124 	}
125 
126 	return (0);
127 }
128