1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
--- 21 unchanged lines hidden (view full) ---
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/kern_sig.c 130192 2004-06-07 13:35:02Z davidxu $");
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/signalvar.h>
46#include <sys/vnode.h>
--- 183 unchanged lines hidden (view full) ---
230}
231
232int
233sigonstack(size_t sp)
234{
235 struct thread *td = curthread;
236
237 return ((td->td_pflags & TDP_ALTSTACK) ?
238#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
239 ((td->td_sigstk.ss_size == 0) ?
240 (td->td_sigstk.ss_flags & SS_ONSTACK) :
241 ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size))
242#else
243 ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size)
244#endif
245 : 0);
246}
--- 95 unchanged lines hidden (view full) ---
342 if (act->sa_flags & SA_RESETHAND)
343 SIGADDSET(ps->ps_sigreset, sig);
344 else
345 SIGDELSET(ps->ps_sigreset, sig);
346 if (act->sa_flags & SA_NODEFER)
347 SIGADDSET(ps->ps_signodefer, sig);
348 else
349 SIGDELSET(ps->ps_signodefer, sig);
350#ifdef COMPAT_SUNOS
351 if (act->sa_flags & SA_USERTRAMP)
352 SIGADDSET(ps->ps_usertramp, sig);
353 else
354 SIGDELSET(ps->ps_usertramp, sig);
355#endif
356 if (sig == SIGCHLD) {
357 if (act->sa_flags & SA_NOCLDSTOP)
358 ps->ps_flag |= PS_NOCLDSTOP;
359 else
360 ps->ps_flag &= ~PS_NOCLDSTOP;
361 if (act->sa_flags & SA_NOCLDWAIT) {
362 /*
363 * Paranoia: since SA_NOCLDWAIT is implemented
--- 631 unchanged lines hidden (view full) ---
995 siglist = p->p_siglist;
996 SIGSETOR(siglist, td->td_siglist);
997 PROC_UNLOCK(p);
998 SIG2OSIG(siglist, td->td_retval[0]);
999 return (0);
1000}
1001#endif /* COMPAT_43 */
1002
1003#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1004/*
1005 * Generalized interface signal handler, 4.3-compatible.
1006 */
1007#ifndef _SYS_SYSPROTO_H_
1008struct osigvec_args {
1009 int signum;
1010 struct sigvec *nsv;
1011 struct sigvec *osv;
--- 20 unchanged lines hidden (view full) ---
1032 if (nsap) {
1033 error = copyin(uap->nsv, &vec, sizeof(vec));
1034 if (error)
1035 return (error);
1036 nsap->sa_handler = vec.sv_handler;
1037 OSIG2SIG(vec.sv_mask, nsap->sa_mask);
1038 nsap->sa_flags = vec.sv_flags;
1039 nsap->sa_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
1040#ifdef COMPAT_SUNOS
1041 nsap->sa_flags |= SA_USERTRAMP;
1042#endif
1043 }
1044 error = kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET);
1045 if (osap && !error) {
1046 vec.sv_handler = osap->sa_handler;
1047 SIG2OSIG(osap->sa_mask, vec.sv_mask);
1048 vec.sv_flags = osap->sa_flags;
1049 vec.sv_flags &= ~SA_NOCLDWAIT;
1050 vec.sv_flags ^= SA_RESTART;
1051#ifdef COMPAT_SUNOS
1052 vec.sv_flags &= ~SA_NOCLDSTOP;
1053#endif
1054 error = copyout(&vec, uap->osv, sizeof(vec));
1055 }
1056 return (error);
1057}
1058
1059#ifndef _SYS_SYSPROTO_H_
1060struct osigblock_args {
1061 int mask;
--- 39 unchanged lines hidden (view full) ---
1101 SIG_CANTMASK(set);
1102 PROC_LOCK(p);
1103 SIG2OSIG(td->td_sigmask, td->td_retval[0]);
1104 SIGSETLO(td->td_sigmask, set);
1105 signotify(td);
1106 PROC_UNLOCK(p);
1107 return (0);
1108}
1109#endif /* COMPAT_43 || COMPAT_SUNOS */
1110
1111/*
1112 * Suspend process until signal, providing mask to be set
1113 * in the meantime.
1114 ***** XXXKSE this doesn't make sense under KSE.
1115 ***** Do we suspend the thread or all threads in the process?
1116 ***** How do we suspend threads running NOW on another processor?
1117 */
--- 77 unchanged lines hidden (view full) ---
1195 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH, "opause", 0) == 0)
1196 /* void */;
1197 PROC_UNLOCK(p);
1198 /* always return EINTR rather than ERESTART... */
1199 return (EINTR);
1200}
1201#endif /* COMPAT_43 */
1202
1203#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1204#ifndef _SYS_SYSPROTO_H_
1205struct osigstack_args {
1206 struct sigstack *nss;
1207 struct sigstack *oss;
1208};
1209#endif
1210/*
1211 * MPSAFE
--- 20 unchanged lines hidden (view full) ---
1232 td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK;
1233 td->td_pflags |= TDP_ALTSTACK;
1234 }
1235 if (uap->oss != NULL)
1236 error = copyout(&oss, uap->oss, sizeof(oss));
1237
1238 return (error);
1239}
1240#endif /* COMPAT_43 || COMPAT_SUNOS */
1241
1242#ifndef _SYS_SYSPROTO_H_
1243struct sigaltstack_args {
1244 stack_t *ss;
1245 stack_t *oss;
1246};
1247#endif
1248/*
--- 162 unchanged lines hidden (view full) ---
1411 case 0: /* signal own process group */
1412 return (killpg1(td, uap->signum, 0, 0));
1413 default: /* negative explicit process group */
1414 return (killpg1(td, uap->signum, -uap->pid, 0));
1415 }
1416 /* NOTREACHED */
1417}
1418
1419#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1420#ifndef _SYS_SYSPROTO_H_
1421struct okillpg_args {
1422 int pgid;
1423 int signum;
1424};
1425#endif
1426/*
1427 * MPSAFE
--- 4 unchanged lines hidden (view full) ---
1432 struct thread *td;
1433 register struct okillpg_args *uap;
1434{
1435
1436 if ((u_int)uap->signum > _SIG_MAXSIG)
1437 return (EINVAL);
1438 return (killpg1(td, uap->signum, uap->pgid, 0));
1439}
1440#endif /* COMPAT_43 || COMPAT_SUNOS */
1441
1442/*
1443 * Send a signal to a process group.
1444 */
1445void
1446gsignal(pgid, sig)
1447 int pgid, sig;
1448{
--- 1330 unchanged lines hidden ---
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
--- 21 unchanged lines hidden (view full) ---
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/kern_sig.c 130192 2004-06-07 13:35:02Z davidxu $");
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/signalvar.h>
46#include <sys/vnode.h>
--- 183 unchanged lines hidden (view full) ---
230}
231
232int
233sigonstack(size_t sp)
234{
235 struct thread *td = curthread;
236
237 return ((td->td_pflags & TDP_ALTSTACK) ?
238#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
239 ((td->td_sigstk.ss_size == 0) ?
240 (td->td_sigstk.ss_flags & SS_ONSTACK) :
241 ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size))
242#else
243 ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size)
244#endif
245 : 0);
246}
--- 95 unchanged lines hidden (view full) ---
342 if (act->sa_flags & SA_RESETHAND)
343 SIGADDSET(ps->ps_sigreset, sig);
344 else
345 SIGDELSET(ps->ps_sigreset, sig);
346 if (act->sa_flags & SA_NODEFER)
347 SIGADDSET(ps->ps_signodefer, sig);
348 else
349 SIGDELSET(ps->ps_signodefer, sig);
350#ifdef COMPAT_SUNOS
351 if (act->sa_flags & SA_USERTRAMP)
352 SIGADDSET(ps->ps_usertramp, sig);
353 else
354 SIGDELSET(ps->ps_usertramp, sig);
355#endif
356 if (sig == SIGCHLD) {
357 if (act->sa_flags & SA_NOCLDSTOP)
358 ps->ps_flag |= PS_NOCLDSTOP;
359 else
360 ps->ps_flag &= ~PS_NOCLDSTOP;
361 if (act->sa_flags & SA_NOCLDWAIT) {
362 /*
363 * Paranoia: since SA_NOCLDWAIT is implemented
--- 631 unchanged lines hidden (view full) ---
995 siglist = p->p_siglist;
996 SIGSETOR(siglist, td->td_siglist);
997 PROC_UNLOCK(p);
998 SIG2OSIG(siglist, td->td_retval[0]);
999 return (0);
1000}
1001#endif /* COMPAT_43 */
1002
1003#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1004/*
1005 * Generalized interface signal handler, 4.3-compatible.
1006 */
1007#ifndef _SYS_SYSPROTO_H_
1008struct osigvec_args {
1009 int signum;
1010 struct sigvec *nsv;
1011 struct sigvec *osv;
--- 20 unchanged lines hidden (view full) ---
1032 if (nsap) {
1033 error = copyin(uap->nsv, &vec, sizeof(vec));
1034 if (error)
1035 return (error);
1036 nsap->sa_handler = vec.sv_handler;
1037 OSIG2SIG(vec.sv_mask, nsap->sa_mask);
1038 nsap->sa_flags = vec.sv_flags;
1039 nsap->sa_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
1040#ifdef COMPAT_SUNOS
1041 nsap->sa_flags |= SA_USERTRAMP;
1042#endif
1043 }
1044 error = kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET);
1045 if (osap && !error) {
1046 vec.sv_handler = osap->sa_handler;
1047 SIG2OSIG(osap->sa_mask, vec.sv_mask);
1048 vec.sv_flags = osap->sa_flags;
1049 vec.sv_flags &= ~SA_NOCLDWAIT;
1050 vec.sv_flags ^= SA_RESTART;
1051#ifdef COMPAT_SUNOS
1052 vec.sv_flags &= ~SA_NOCLDSTOP;
1053#endif
1054 error = copyout(&vec, uap->osv, sizeof(vec));
1055 }
1056 return (error);
1057}
1058
1059#ifndef _SYS_SYSPROTO_H_
1060struct osigblock_args {
1061 int mask;
--- 39 unchanged lines hidden (view full) ---
1101 SIG_CANTMASK(set);
1102 PROC_LOCK(p);
1103 SIG2OSIG(td->td_sigmask, td->td_retval[0]);
1104 SIGSETLO(td->td_sigmask, set);
1105 signotify(td);
1106 PROC_UNLOCK(p);
1107 return (0);
1108}
1109#endif /* COMPAT_43 || COMPAT_SUNOS */
1110
1111/*
1112 * Suspend process until signal, providing mask to be set
1113 * in the meantime.
1114 ***** XXXKSE this doesn't make sense under KSE.
1115 ***** Do we suspend the thread or all threads in the process?
1116 ***** How do we suspend threads running NOW on another processor?
1117 */
--- 77 unchanged lines hidden (view full) ---
1195 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH, "opause", 0) == 0)
1196 /* void */;
1197 PROC_UNLOCK(p);
1198 /* always return EINTR rather than ERESTART... */
1199 return (EINTR);
1200}
1201#endif /* COMPAT_43 */
1202
1203#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1204#ifndef _SYS_SYSPROTO_H_
1205struct osigstack_args {
1206 struct sigstack *nss;
1207 struct sigstack *oss;
1208};
1209#endif
1210/*
1211 * MPSAFE
--- 20 unchanged lines hidden (view full) ---
1232 td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK;
1233 td->td_pflags |= TDP_ALTSTACK;
1234 }
1235 if (uap->oss != NULL)
1236 error = copyout(&oss, uap->oss, sizeof(oss));
1237
1238 return (error);
1239}
1240#endif /* COMPAT_43 || COMPAT_SUNOS */
1241
1242#ifndef _SYS_SYSPROTO_H_
1243struct sigaltstack_args {
1244 stack_t *ss;
1245 stack_t *oss;
1246};
1247#endif
1248/*
--- 162 unchanged lines hidden (view full) ---
1411 case 0: /* signal own process group */
1412 return (killpg1(td, uap->signum, 0, 0));
1413 default: /* negative explicit process group */
1414 return (killpg1(td, uap->signum, -uap->pid, 0));
1415 }
1416 /* NOTREACHED */
1417}
1418
1419#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1420#ifndef _SYS_SYSPROTO_H_
1421struct okillpg_args {
1422 int pgid;
1423 int signum;
1424};
1425#endif
1426/*
1427 * MPSAFE
--- 4 unchanged lines hidden (view full) ---
1432 struct thread *td;
1433 register struct okillpg_args *uap;
1434{
1435
1436 if ((u_int)uap->signum > _SIG_MAXSIG)
1437 return (EINVAL);
1438 return (killpg1(td, uap->signum, uap->pgid, 0));
1439}
1440#endif /* COMPAT_43 || COMPAT_SUNOS */
1441
1442/*
1443 * Send a signal to a process group.
1444 */
1445void
1446gsignal(pgid, sig)
1447 int pgid, sig;
1448{
--- 1330 unchanged lines hidden ---