The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/signalvar.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1991, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 4. Neither the name of the University nor the names of its contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  *      @(#)signalvar.h 8.6 (Berkeley) 2/19/95
   30  * $FreeBSD: releng/11.0/sys/sys/signalvar.h 302328 2016-07-03 18:19:48Z kib $
   31  */
   32 
   33 #ifndef _SYS_SIGNALVAR_H_
   34 #define _SYS_SIGNALVAR_H_
   35 
   36 #include <sys/queue.h>
   37 #include <sys/_lock.h>
   38 #include <sys/_mutex.h>
   39 #include <sys/signal.h>
   40 
   41 /*
   42  * Kernel signal definitions and data structures.
   43  */
   44 
   45 /*
   46  * Logical process signal actions and state, needed only within the process
   47  * The mapping between sigacts and proc structures is 1:1 except for rfork()
   48  * processes masquerading as threads which use one structure for the whole
   49  * group.  All members are locked by the included mutex.  The reference count
   50  * and mutex must be last for the bcopy in sigacts_copy() to work.
   51  */
   52 struct sigacts {
   53         sig_t   ps_sigact[_SIG_MAXSIG]; /* Disposition of signals. */
   54         sigset_t ps_catchmask[_SIG_MAXSIG];     /* Signals to be blocked. */
   55         sigset_t ps_sigonstack;         /* Signals to take on sigstack. */
   56         sigset_t ps_sigintr;            /* Signals that interrupt syscalls. */
   57         sigset_t ps_sigreset;           /* Signals that reset when caught. */
   58         sigset_t ps_signodefer;         /* Signals not masked while handled. */
   59         sigset_t ps_siginfo;            /* Signals that want SA_SIGINFO args. */
   60         sigset_t ps_sigignore;          /* Signals being ignored. */
   61         sigset_t ps_sigcatch;           /* Signals being caught by user. */
   62         sigset_t ps_freebsd4;           /* Signals using freebsd4 ucontext. */
   63         sigset_t ps_osigset;            /* Signals using <= 3.x osigset_t. */
   64         sigset_t ps_usertramp;          /* SunOS compat; libc sigtramp. XXX */
   65         int     ps_flag;
   66         u_int   ps_refcnt;
   67         struct mtx ps_mtx;
   68 };
   69 
   70 #define PS_NOCLDWAIT    0x0001  /* No zombies if child dies */
   71 #define PS_NOCLDSTOP    0x0002  /* No SIGCHLD when children stop. */
   72 #define PS_CLDSIGIGN    0x0004  /* The SIGCHLD handler is SIG_IGN. */
   73 
   74 #ifdef _KERNEL
   75 
   76 #ifdef COMPAT_43
   77 typedef struct {
   78         struct osigcontext si_sc;
   79         int             si_signo;
   80         int             si_code;
   81         union sigval    si_value;
   82 } osiginfo_t;
   83 
   84 struct osigaction {
   85         union {
   86                 void    (*__sa_handler)(int);
   87                 void    (*__sa_sigaction)(int, osiginfo_t *, void *);
   88         } __sigaction_u;                /* signal handler */
   89         osigset_t       sa_mask;        /* signal mask to apply */
   90         int             sa_flags;       /* see signal options below */
   91 };
   92 
   93 typedef void __osiginfohandler_t(int, osiginfo_t *, void *);
   94 #endif /* COMPAT_43 */
   95 
   96 /* additional signal action values, used only temporarily/internally */
   97 #define SIG_CATCH       ((__sighandler_t *)2)
   98 /* #define SIG_HOLD        ((__sighandler_t *)3) See signal.h */
   99 
  100 /*
  101  * get signal action for process and signal; currently only for current process
  102  */
  103 #define SIGACTION(p, sig)       (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
  104 
  105 #endif /* _KERNEL */
  106 
  107 /*
  108  * sigset_t manipulation macros.
  109  */
  110 #define SIGADDSET(set, signo)                                           \
  111         ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo))
  112 
  113 #define SIGDELSET(set, signo)                                           \
  114         ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo))
  115 
  116 #define SIGEMPTYSET(set)                                                \
  117         do {                                                            \
  118                 int __i;                                                \
  119                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
  120                         (set).__bits[__i] = 0;                          \
  121         } while (0)
  122 
  123 #define SIGFILLSET(set)                                                 \
  124         do {                                                            \
  125                 int __i;                                                \
  126                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
  127                         (set).__bits[__i] = ~0U;                        \
  128         } while (0)
  129 
  130 #define SIGISMEMBER(set, signo)                                         \
  131         ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
  132 
  133 #define SIGISEMPTY(set)         (__sigisempty(&(set)))
  134 #define SIGNOTEMPTY(set)        (!__sigisempty(&(set)))
  135 
  136 #define SIGSETEQ(set1, set2)    (__sigseteq(&(set1), &(set2)))
  137 #define SIGSETNEQ(set1, set2)   (!__sigseteq(&(set1), &(set2)))
  138 
  139 #define SIGSETOR(set1, set2)                                            \
  140         do {                                                            \
  141                 int __i;                                                \
  142                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
  143                         (set1).__bits[__i] |= (set2).__bits[__i];       \
  144         } while (0)
  145 
  146 #define SIGSETAND(set1, set2)                                           \
  147         do {                                                            \
  148                 int __i;                                                \
  149                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
  150                         (set1).__bits[__i] &= (set2).__bits[__i];       \
  151         } while (0)
  152 
  153 #define SIGSETNAND(set1, set2)                                          \
  154         do {                                                            \
  155                 int __i;                                                \
  156                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
  157                         (set1).__bits[__i] &= ~(set2).__bits[__i];      \
  158         } while (0)
  159 
  160 #define SIGSETLO(set1, set2)    ((set1).__bits[0] = (set2).__bits[0])
  161 #define SIGSETOLD(set, oset)    ((set).__bits[0] = (oset))
  162 
  163 #define SIG_CANTMASK(set)                                               \
  164         SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
  165 
  166 #define SIG_STOPSIGMASK(set)                                            \
  167         SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP),               \
  168         SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
  169 
  170 #define SIG_CONTSIGMASK(set)                                            \
  171         SIGDELSET(set, SIGCONT)
  172 
  173 #define sigcantmask     (sigmask(SIGKILL) | sigmask(SIGSTOP))
  174 
  175 #define SIG2OSIG(sig, osig)     (osig = (sig).__bits[0])
  176 #define OSIG2SIG(osig, sig)     SIGEMPTYSET(sig); (sig).__bits[0] = osig
  177 
  178 static __inline int
  179 __sigisempty(sigset_t *set)
  180 {
  181         int i;
  182 
  183         for (i = 0; i < _SIG_WORDS; i++) {
  184                 if (set->__bits[i])
  185                         return (0);
  186         }
  187         return (1);
  188 }
  189 
  190 static __inline int
  191 __sigseteq(sigset_t *set1, sigset_t *set2)
  192 {
  193         int i;
  194 
  195         for (i = 0; i < _SIG_WORDS; i++) {
  196                 if (set1->__bits[i] != set2->__bits[i])
  197                         return (0);
  198         }
  199         return (1);
  200 }
  201 
  202 #ifdef COMPAT_FREEBSD6
  203 struct osigevent {
  204         int     sigev_notify;           /* Notification type */
  205         union {
  206                 int     __sigev_signo;  /* Signal number */
  207                 int     __sigev_notify_kqueue;
  208         } __sigev_u;
  209         union sigval sigev_value;       /* Signal value */
  210 };
  211 #endif
  212 
  213 typedef struct ksiginfo {
  214         TAILQ_ENTRY(ksiginfo)   ksi_link;
  215         siginfo_t               ksi_info;
  216         int                     ksi_flags;
  217         struct sigqueue         *ksi_sigq;
  218 } ksiginfo_t;
  219 
  220 #define ksi_signo       ksi_info.si_signo
  221 #define ksi_errno       ksi_info.si_errno
  222 #define ksi_code        ksi_info.si_code
  223 #define ksi_pid         ksi_info.si_pid
  224 #define ksi_uid         ksi_info.si_uid
  225 #define ksi_status      ksi_info.si_status
  226 #define ksi_addr        ksi_info.si_addr
  227 #define ksi_value       ksi_info.si_value
  228 #define ksi_band        ksi_info.si_band
  229 #define ksi_trapno      ksi_info.si_trapno
  230 #define ksi_overrun     ksi_info.si_overrun
  231 #define ksi_timerid     ksi_info.si_timerid
  232 #define ksi_mqd         ksi_info.si_mqd
  233 
  234 /* bits for ksi_flags */
  235 #define KSI_TRAP        0x01    /* Generated by trap. */
  236 #define KSI_EXT         0x02    /* Externally managed ksi. */
  237 #define KSI_INS         0x04    /* Directly insert ksi, not the copy */
  238 #define KSI_SIGQ        0x08    /* Generated by sigqueue, might ret EGAIN. */
  239 #define KSI_HEAD        0x10    /* Insert into head, not tail. */
  240 #define KSI_COPYMASK    (KSI_TRAP|KSI_SIGQ)
  241 
  242 #define KSI_ONQ(ksi)    ((ksi)->ksi_sigq != NULL)
  243 
  244 typedef struct sigqueue {
  245         sigset_t        sq_signals;     /* All pending signals. */
  246         sigset_t        sq_kill;        /* Legacy depth 1 queue. */
  247         TAILQ_HEAD(, ksiginfo)  sq_list;/* Queued signal info. */
  248         struct proc     *sq_proc;
  249         int             sq_flags;
  250 } sigqueue_t;
  251 
  252 /* Flags for ksi_flags */
  253 #define SQ_INIT 0x01
  254 
  255 #ifdef _KERNEL
  256 
  257 /* Return nonzero if process p has an unmasked pending signal. */
  258 #define SIGPENDING(td)                                                  \
  259         ((!SIGISEMPTY((td)->td_siglist) &&                              \
  260             !sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask)) ||     \
  261          (!SIGISEMPTY((td)->td_proc->p_siglist) &&                      \
  262             !sigsetmasked(&(td)->td_proc->p_siglist, &(td)->td_sigmask)))
  263 /*
  264  * Return the value of the pseudo-expression ((*set & ~*mask) != 0).  This
  265  * is an optimized version of SIGISEMPTY() on a temporary variable
  266  * containing SIGSETNAND(*set, *mask).
  267  */
  268 static __inline int
  269 sigsetmasked(sigset_t *set, sigset_t *mask)
  270 {
  271         int i;
  272 
  273         for (i = 0; i < _SIG_WORDS; i++) {
  274                 if (set->__bits[i] & ~mask->__bits[i])
  275                         return (0);
  276         }
  277         return (1);
  278 }
  279 
  280 #define ksiginfo_init(ksi)                      \
  281 do {                                            \
  282         bzero(ksi, sizeof(ksiginfo_t));         \
  283 } while(0)
  284 
  285 #define ksiginfo_init_trap(ksi)                 \
  286 do {                                            \
  287         ksiginfo_t *kp = ksi;                   \
  288         bzero(kp, sizeof(ksiginfo_t));          \
  289         kp->ksi_flags |= KSI_TRAP;              \
  290 } while(0)
  291 
  292 static __inline void
  293 ksiginfo_copy(ksiginfo_t *src, ksiginfo_t *dst)
  294 {
  295         (dst)->ksi_info = src->ksi_info;
  296         (dst)->ksi_flags = (src->ksi_flags & KSI_COPYMASK);
  297 }
  298 
  299 static __inline void
  300 ksiginfo_set_sigev(ksiginfo_t *dst, struct sigevent *sigev)
  301 {
  302         dst->ksi_signo = sigev->sigev_signo;
  303         dst->ksi_value = sigev->sigev_value;
  304 }
  305 
  306 struct pgrp;
  307 struct proc;
  308 struct sigio;
  309 struct thread;
  310 
  311 /*
  312  * Lock the pointers for a sigio object in the underlying objects of
  313  * a file descriptor.
  314  */
  315 #define SIGIO_LOCK()    mtx_lock(&sigio_lock)
  316 #define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock)
  317 #define SIGIO_UNLOCK()  mtx_unlock(&sigio_lock)
  318 #define SIGIO_LOCKED()  mtx_owned(&sigio_lock)
  319 #define SIGIO_ASSERT(type)      mtx_assert(&sigio_lock, type)
  320 
  321 extern struct mtx       sigio_lock;
  322 
  323 /* Flags for kern_sigprocmask(). */
  324 #define SIGPROCMASK_OLD         0x0001
  325 #define SIGPROCMASK_PROC_LOCKED 0x0002
  326 #define SIGPROCMASK_PS_LOCKED   0x0004
  327 
  328 /*
  329  * Modes for sigdeferstop().  Manages behaviour of
  330  * thread_suspend_check() in the region delimited by
  331  * sigdeferstop()/sigallowstop().  Must be restored to
  332  * SIGDEFERSTOP_OFF before returning to userspace.
  333  */
  334 #define SIGDEFERSTOP_NOP        0 /* continue doing whatever is done now */
  335 #define SIGDEFERSTOP_OFF        1 /* stop ignoring STOPs */
  336 #define SIGDEFERSTOP_SILENT     2 /* silently ignore STOPs */
  337 #define SIGDEFERSTOP_EINTR      3 /* ignore STOPs, return EINTR */
  338 #define SIGDEFERSTOP_ERESTART   4 /* ignore STOPs, return ERESTART */
  339 
  340 #define SIGDEFERSTOP_VAL_NCHG   (-1) /* placeholder indicating no state change */
  341 int     sigdeferstop_impl(int mode);
  342 void    sigallowstop_impl(int prev);
  343 
  344 static inline int
  345 sigdeferstop(int mode)
  346 {
  347 
  348         if (mode == SIGDEFERSTOP_NOP)
  349                 return (SIGDEFERSTOP_VAL_NCHG);
  350         return (sigdeferstop_impl(mode));
  351 }
  352 
  353 static inline void
  354 sigallowstop(int prev)
  355 {
  356 
  357         if (prev == SIGDEFERSTOP_VAL_NCHG)
  358                 return;
  359         sigallowstop_impl(prev);
  360 }
  361 
  362 int     cursig(struct thread *td);
  363 void    execsigs(struct proc *p);
  364 void    gsignal(int pgid, int sig, ksiginfo_t *ksi);
  365 void    killproc(struct proc *p, char *why);
  366 ksiginfo_t * ksiginfo_alloc(int wait);
  367 void    ksiginfo_free(ksiginfo_t *ksi);
  368 int     pksignal(struct proc *p, int sig, ksiginfo_t *ksi);
  369 void    pgsigio(struct sigio **sigiop, int sig, int checkctty);
  370 void    pgsignal(struct pgrp *pgrp, int sig, int checkctty, ksiginfo_t *ksi);
  371 int     postsig(int sig);
  372 void    kern_psignal(struct proc *p, int sig);
  373 int     ptracestop(struct thread *td, int sig);
  374 void    sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *retmask);
  375 struct sigacts *sigacts_alloc(void);
  376 void    sigacts_copy(struct sigacts *dest, struct sigacts *src);
  377 void    sigacts_free(struct sigacts *ps);
  378 struct sigacts *sigacts_hold(struct sigacts *ps);
  379 int     sigacts_shared(struct sigacts *ps);
  380 void    sigexit(struct thread *td, int sig) __dead2;
  381 int     sigev_findtd(struct proc *p, struct sigevent *sigev, struct thread **);
  382 int     sig_ffs(sigset_t *set);
  383 void    siginit(struct proc *p);
  384 void    signotify(struct thread *td);
  385 void    sigqueue_delete(struct sigqueue *queue, int sig);
  386 void    sigqueue_delete_proc(struct proc *p, int sig);
  387 void    sigqueue_flush(struct sigqueue *queue);
  388 void    sigqueue_init(struct sigqueue *queue, struct proc *p);
  389 void    sigqueue_take(ksiginfo_t *ksi);
  390 void    tdksignal(struct thread *td, int sig, ksiginfo_t *ksi);
  391 int     tdsendsignal(struct proc *p, struct thread *td, int sig,
  392            ksiginfo_t *ksi);
  393 void    tdsigcleanup(struct thread *td);
  394 void    tdsignal(struct thread *td, int sig);
  395 void    trapsignal(struct thread *td, ksiginfo_t *ksi);
  396 
  397 #endif /* _KERNEL */
  398 
  399 #endif /* !_SYS_SIGNALVAR_H_ */

Cache object: 527dc309bac2a39aaf44b1806e7f4b03


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.