17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57be238fcSRoger A. Faulkner * Common Development and Distribution License (the "License").
67be238fcSRoger A. Faulkner * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gate /*
23*bdf0047cSRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277be238fcSRoger A. Faulkner /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/errno.h>
347c478bd9Sstevel@tonic-gate #include <sys/proc.h>
357c478bd9Sstevel@tonic-gate #include <sys/fault.h>
367c478bd9Sstevel@tonic-gate #include <sys/signal.h>
377c478bd9Sstevel@tonic-gate #include <sys/schedctl.h>
387c478bd9Sstevel@tonic-gate #include <sys/debug.h>
397c478bd9Sstevel@tonic-gate
40*bdf0047cSRoger A. Faulkner /* ARGSUSED4 */
417c478bd9Sstevel@tonic-gate int64_t
lwp_sigmask(int how,uint_t bits0,uint_t bits1,uint_t bits2,uint_t bits3)42*bdf0047cSRoger A. Faulkner lwp_sigmask(int how, uint_t bits0, uint_t bits1, uint_t bits2, uint_t bits3)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate kthread_t *t = curthread;
457c478bd9Sstevel@tonic-gate proc_t *p = ttoproc(t);
467c478bd9Sstevel@tonic-gate rval_t rv;
477c478bd9Sstevel@tonic-gate
487be238fcSRoger A. Faulkner /*
497be238fcSRoger A. Faulkner * We don't need to acquire p->p_lock here;
507be238fcSRoger A. Faulkner * we are manipulating thread-private data.
517be238fcSRoger A. Faulkner */
527be238fcSRoger A. Faulkner
537c478bd9Sstevel@tonic-gate schedctl_finish_sigblock(t);
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate bits0 &= (FILLSET0 & ~CANTMASK0);
567c478bd9Sstevel@tonic-gate bits1 &= (FILLSET1 & ~CANTMASK1);
57*bdf0047cSRoger A. Faulkner bits2 &= (FILLSET2 & ~CANTMASK2);
587c478bd9Sstevel@tonic-gate
59*bdf0047cSRoger A. Faulkner /*
60*bdf0047cSRoger A. Faulkner * As a sop to the s10 brand, we continue to return
61*bdf0047cSRoger A. Faulkner * the first two words of the signal mask, regardless
62*bdf0047cSRoger A. Faulkner * of the value of 'how', even though libc doesn't use them.
63*bdf0047cSRoger A. Faulkner */
647c478bd9Sstevel@tonic-gate rv.r_val1 = t->t_hold.__sigbits[0];
657c478bd9Sstevel@tonic-gate rv.r_val2 = t->t_hold.__sigbits[1];
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate switch (how) {
687c478bd9Sstevel@tonic-gate case SIG_BLOCK:
697c478bd9Sstevel@tonic-gate t->t_hold.__sigbits[0] |= bits0;
707c478bd9Sstevel@tonic-gate t->t_hold.__sigbits[1] |= bits1;
71*bdf0047cSRoger A. Faulkner t->t_hold.__sigbits[2] |= bits2;
727c478bd9Sstevel@tonic-gate break;
737c478bd9Sstevel@tonic-gate case SIG_UNBLOCK:
747c478bd9Sstevel@tonic-gate t->t_hold.__sigbits[0] &= ~bits0;
757c478bd9Sstevel@tonic-gate t->t_hold.__sigbits[1] &= ~bits1;
76*bdf0047cSRoger A. Faulkner t->t_hold.__sigbits[2] &= ~bits2;
777c478bd9Sstevel@tonic-gate if (sigcheck(p, t))
787c478bd9Sstevel@tonic-gate t->t_sig_check = 1;
797c478bd9Sstevel@tonic-gate break;
807c478bd9Sstevel@tonic-gate case SIG_SETMASK:
817c478bd9Sstevel@tonic-gate t->t_hold.__sigbits[0] = bits0;
827c478bd9Sstevel@tonic-gate t->t_hold.__sigbits[1] = bits1;
83*bdf0047cSRoger A. Faulkner t->t_hold.__sigbits[2] = bits2;
847c478bd9Sstevel@tonic-gate if (sigcheck(p, t))
857c478bd9Sstevel@tonic-gate t->t_sig_check = 1;
867c478bd9Sstevel@tonic-gate break;
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate return (rv.r_vals);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate int
sigprocmask(int how,sigset_t * setp,sigset_t * osetp)937c478bd9Sstevel@tonic-gate sigprocmask(int how, sigset_t *setp, sigset_t *osetp)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate sigset_t set;
96*bdf0047cSRoger A. Faulkner sigset_t oset;
977c478bd9Sstevel@tonic-gate k_sigset_t kset;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate /*
100*bdf0047cSRoger A. Faulkner * User's osetp and setp might be the same address,
101*bdf0047cSRoger A. Faulkner * so copyin first and save before copying out.
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate if (setp) {
1047c478bd9Sstevel@tonic-gate switch (how) {
1057c478bd9Sstevel@tonic-gate case SIG_BLOCK:
1067c478bd9Sstevel@tonic-gate case SIG_UNBLOCK:
1077c478bd9Sstevel@tonic-gate case SIG_SETMASK:
1087c478bd9Sstevel@tonic-gate break;
1097c478bd9Sstevel@tonic-gate default:
1107c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate if (copyin((caddr_t)setp, (caddr_t)&set, sizeof (sigset_t)))
1137c478bd9Sstevel@tonic-gate return (set_errno(EFAULT));
1147c478bd9Sstevel@tonic-gate sigutok(&set, &kset);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate if (osetp) {
118*bdf0047cSRoger A. Faulkner sigktou(&curthread->t_hold, &oset);
119*bdf0047cSRoger A. Faulkner if (copyout((caddr_t)&oset, (caddr_t)osetp, sizeof (sigset_t)))
1207c478bd9Sstevel@tonic-gate return (set_errno(EFAULT));
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
123*bdf0047cSRoger A. Faulkner if (setp) {
124*bdf0047cSRoger A. Faulkner (void) lwp_sigmask(how,
125*bdf0047cSRoger A. Faulkner kset.__sigbits[0],
126*bdf0047cSRoger A. Faulkner kset.__sigbits[1],
127*bdf0047cSRoger A. Faulkner kset.__sigbits[2],
128*bdf0047cSRoger A. Faulkner 0);
129*bdf0047cSRoger A. Faulkner }
130*bdf0047cSRoger A. Faulkner
1317c478bd9Sstevel@tonic-gate return (0);
1327c478bd9Sstevel@tonic-gate }
133