3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * This file and its contents are supplied under the terms of the
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Common Development and Distribution License ("CDDL"), version 1.0.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * You may only use this file in accordance with the terms of version
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * 1.0 of the CDDL.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * A full copy of the text of the CDDL should have accompanied this
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * source. A copy of the CDDL is also available via the Internet at
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Copyright 2016 Joyent, Inc.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Support for the signalfd facility, a Linux-borne facility for
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * file descriptor-based synchronous signal consumption.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * As described on the signalfd(3C) man page, the general idea behind these
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * file descriptors is that they can be used to synchronously consume signals
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * via the read(2) syscall. While that capability already exists with the
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * sigwaitinfo(3C) function, signalfd holds an advantage since it is file
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * descriptor based: It is able use the event facilities (poll(2), /dev/poll,
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * event ports) to notify interested parties when consumable signals arrive.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * The signalfd lifecycle begins When a process opens /dev/signalfd. A minor
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * will be allocated for them along with an associated signalfd_state_t struct.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * It is there where the mask of desired signals resides.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Reading from the signalfd is straightforward and mimics the kernel behavior
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * for sigtimedwait(). Signals continue to live on either the proc's p_sig, or
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * thread's t_sig, member. During a read operation, those which match the mask
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * are consumed so they are no longer pending.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * The poll side is more complex. Every time a signal is delivered, all of the
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * signalfds on the process need to be examined in order to pollwake threads
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * waiting for signal arrival.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * When a thread polling on a signalfd requires a pollhead, several steps must
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * be taken to safely ensure the proper result. A sigfd_proc_state_t is
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * created for the calling process if it does not yet exist. It is there where
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * a list of sigfd_poll_waiter_t structures reside which associate pollheads to
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * signalfd_state_t entries. The sigfd_proc_state_t list is walked to find a
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * sigfd_poll_waiter_t matching the signalfd_state_t which corresponds to the
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * polled resource. If one is found, it is reused. Otherwise a new one is
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * created, incrementing the refcount on the signalfd_state_t, and it is added
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * to the sigfd_poll_waiter_t list.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * The complications imposed by fork(2) are why the pollhead is stored in the
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * associated sigfd_poll_waiter_t instead of directly in the signalfd_state_t.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * More than one process can hold a reference to the signalfd at a time but
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * arriving signals should wake only process-local pollers. Additionally,
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * signalfd_close is called only when the last referencing fd is closed, hiding
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * occurrences of preceeding threads which released their references. This
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * necessitates reference counting on the signalfd_state_t so it is able to
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * persist after close until all poll references have been cleansed. Doing so
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * ensures that blocked pollers which hold references to the signalfd_state_t
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * will be able to do clean-up after the descriptor itself has been closed.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * When a signal arrives in a process polling on signalfd, signalfd_pollwake_cb
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * is called via the pointer in sigfd_proc_state_t. It will walk over the
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * sigfd_poll_waiter_t entries present in the list, searching for any
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * associated with a signalfd_state_t with a matching signal mask. The
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * approach of keeping the poller list in p_sigfd was chosen because a process
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * is likely to use few signalfds relative to its total file descriptors. It
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * reduces the work required for each received signal.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * When matching sigfd_poll_waiter_t entries are encountered in the poller list
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * during signalfd_pollwake_cb, they are dispatched into signalfd_wakeq to
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * perform the pollwake. This is due to a lock ordering conflict between
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * signalfd_poll and signalfd_pollwake_cb. The former acquires
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * pollcache_t`pc_lock before proc_t`p_lock. The latter (via sigtoproc)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * reverses the order. Defering the pollwake into a taskq means it can be
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * performed without proc_t`p_lock held, avoiding the deadlock.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * The sigfd_list is self-cleaning; as signalfd_pollwake_cb is called, the list
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * will clear out on its own. Any remaining per-process state which remains
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * will be cleaned up by the exit helper (signalfd_exit_helper).
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * The structures associated with signalfd state are designed to operate
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * correctly across fork, but there is one caveat that applies. Using
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * fork-shared signalfd descriptors in conjuction with fork-shared caching poll
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * descriptors (such as /dev/poll or event ports) will result in missed poll
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * wake-ups. This is caused by the pollhead identity of signalfd descriptors
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * being dependent on the process they are polled from. Because it has a
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * thread-local cache, poll(2) is unaffected by this limitation.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Lock ordering:
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * 1. signalfd_lock
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * 2. signalfd_state_t`sfd_lock
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * 1. proc_t`p_lock (to walk p_sigfd)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * 2. signalfd_state_t`sfd_lock
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * 2a. signalfd_lock (after sfd_lock is dropped, when sfd_count falls to 0)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinektypedef struct signalfd_state signalfd_state_t;
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney list_node_t sfd_list; /* node in global list */
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney kmutex_t sfd_lock; /* protects fields below */
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney k_sigset_t sfd_set; /* signals for this fd */
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Protects global state in signalfd_devi, signalfd_minor, signalfd_softstate,
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * and signalfd_state (including sfd_list field of members)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinekstatic dev_info_t *signalfd_devi; /* device info */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinekstatic id_space_t *signalfd_minor; /* minor number arena */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinekstatic void *signalfd_softstate; /* softstate pointer */
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooneystatic list_t signalfd_state; /* global list of state */
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooneystatic taskq_t *signalfd_wakeq; /* pollwake event taskq */
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooneysignalfd_state_enter_locked(signalfd_state_t *state)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooneysignalfd_state_release(signalfd_state_t *state, boolean_t force_invalidate)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * The invalidation performed in signalfd_close is done
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * while signalfd_lock is held.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooneysignalfd_wake_list_add(sigfd_proc_state_t *pstate, signalfd_state_t *state)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney for (pw = list_head(lst); pw != NULL; pw = list_next(lst, pw)) {
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooneysignalfd_wake_list_rm(sigfd_proc_state_t *pstate, signalfd_state_t *state)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney for (pw = list_head(lst); pw != NULL; pw = list_next(lst, pw)) {
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney while ((pw = list_remove_head(lst)) != NULL) {
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Perform pollwake for a sigfd_poll_waiter_t entry.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Thanks to the strict and conflicting lock orders required for signalfd_poll
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * (pc_lock before p_lock) and signalfd_pollwake_cb (p_lock before pc_lock),
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * this is relegated to a taskq to avoid deadlock.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Called every time a signal is delivered to the process so that we can
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * see if any signal stream needs a pollwakeup. We maintain a list of
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * signal state elements so that we don't have to look at every file descriptor
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * on the process. If necessary, a further optimization would be to maintain a
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * signal set mask that is a union of all of the sets in the list so that
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * we don't even traverse the list if the signal is not in one of the elements.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * However, since the list is likely to be very short, this is not currently
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * being done. A more complex data structure might also be used, but it is
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * unclear what that would be since each signal set needs to be checked for a
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sigfd_proc_state_t *pstate = (sigfd_proc_state_t *)p->p_sigfd;
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney } else if (sigismember(&state->sfd_set, sig)) {
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Pull the sigfd_poll_waiter_t out of the list and dispatch it
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * to perform a pollwake. This cannot be done synchronously
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * since signalfd_poll and signalfd_pollwake_cb have
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * conflicting lock orders which can deadlock.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney taskq_dispatch_ent(signalfd_wakeq, signalfd_wake_task, pw, 0,
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (ddi_soft_state_zalloc(signalfd_softstate, minor) != DDI_SUCCESS) {
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney state = kmem_zalloc(sizeof (*state), KM_SLEEP);
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney list_insert_head(&signalfd_state, (void *)state);
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sstate = ddi_get_soft_state(signalfd_softstate, minor);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Consume one signal from our set in a manner similar to sigtimedwait().
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * The block parameter is used to control whether we wait for a signal or
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * return immediately if no signal is pending. We use the thread's t_sigwait
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * member in the same way that it is used by sigtimedwait.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Return 0 if we successfully consumed a signal or an errno if not.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinekconsume_signal(k_sigset_t set, uio_t *uio, boolean_t block)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek timespec_t *rqtp = NULL; /* null means blocking */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek rqtp = &now; /* non-blocking check for pending signals */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * set the thread's signal mask to unmask those signals in the
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * specified set.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Based on rqtp, wait indefinitely until we take a signal in our set
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * or return immediately if there are no signals pending from our set.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek while ((ret = cv_waituntil_sig(&t->t_delay_cv, &p->p_lock, rqtp,
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek /* Restore thread's signal mask to its previous value. */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek t->t_sig_check = 1; /* so post_syscall sees new t_hold mask */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek /* no signals pending */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek /* Don't bother with signal if it is not in request set. */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek !sigismember(&t->t_sigwait, lwp->lwp_cursig)) {
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * lwp_cursig is zero if pokelwps() awakened cv_wait_sig().
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * This happens if some other thread in this process called
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * forkall() or exit().
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek DTRACE_PROC2(signal__clear, int, ret, ksiginfo_t *, infop);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek /* Convert k_siginfo into external, datamodel independent, struct. */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek ssp->ssi_addr = (uint64_t)(intptr_t)infop->si_addr;
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek ret = uiomove(ssp, sizeof (*ssp), UIO_READ, uio);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * This is similar to sigtimedwait. Based on the fd mode we may wait until a
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * signal within our specified set is posted. We consume as many available
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * signals within our set as we can.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_read(dev_t dev, uio_t *uio, cred_t *cr)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (uio->uio_resid < sizeof (signalfd_siginfo_t))
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sstate = ddi_get_soft_state(signalfd_softstate, minor);
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * After consuming one signal, do not block while
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * trying to consume more.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * Refresh the matching signal set in case it was
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * updated during the wait.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek } while (res == 0 && uio->uio_resid >= sizeof (signalfd_siginfo_t));
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * If ksigset_t's were a single word, we would do:
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * return (((p->p_sig | t->t_sig) & set) & fillset);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_sig_pending(proc_t *p, kthread_t *t, k_sigset_t set)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek return (((p->p_sig.__sigbits[0] | t->t_sig.__sigbits[0]) &
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek ((p->p_sig.__sigbits[1] | t->t_sig.__sigbits[1]) &
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek (((p->p_sig.__sigbits[2] | t->t_sig.__sigbits[2]) &
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_poll(dev_t dev, short events, int anyyet, short *reventsp,
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sstate = ddi_get_soft_state(signalfd_softstate, minor);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (signalfd_sig_pending(p, t, state->sfd_set) != 0)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (!(*reventsp = revents & events) && !anyyet) {
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek * Enable pollwakeup handling.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney if ((pstate = (sigfd_proc_state_t *)p->p_sigfd) == NULL) {
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney pstate = kmem_zalloc(sizeof (*pstate), KM_SLEEP);
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney pstate->sigfd_pollwake_cb = signalfd_pollwake_cb;
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney /* Check again, after blocking for the alloc. */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek /* someone beat us to it */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_ioctl(dev_t dev, int cmd, intptr_t arg, int md, cred_t *cr, int *rv)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sstate = ddi_get_soft_state(signalfd_softstate, minor);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (ddi_copyin((caddr_t)arg, (caddr_t)&mask, sizeof (sigset_t),
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_close(dev_t dev, int flag, int otyp, cred_t *cred_p)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sstate = ddi_get_soft_state(signalfd_softstate, minor);
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney /* Make sure state is removed from this proc's pollwake list. */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek ddi_soft_state_free(signalfd_softstate, minor);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (cmd != DDI_ATTACH || signalfd_devi != NULL)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek signalfd_minor = id_space_create("signalfd_minor", 1, L_MAXMIN32 + 1);
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek cmn_err(CE_WARN, "signalfd couldn't create id space");
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney sizeof (signalfd_state_t *), 0) != 0) {
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek cmn_err(CE_WARN, "signalfd failed to create soft state");
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek if (ddi_create_minor_node(devi, "signalfd", S_IFCHR,
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek SIGNALFDMNRN_SIGNALFD, DDI_PSEUDO, NULL) == DDI_FAILURE) {
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek cmn_err(CE_NOTE, "/dev/signalfd couldn't create minor node");
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney list_create(&signalfd_state, sizeof (signalfd_state_t),
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney signalfd_wakeq = taskq_create("signalfd_wake", 1, minclsyspri,
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * There are dangling poll waiters holding signalfd_state_t
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * entries on the global list. Detach is not possible until
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * they purge themselves.
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * With no remaining entries in the signalfd_state list, the wake taskq
abf99a006172ea5aab2246bda23f9d6d935bf1adPatrick Mooney * should be empty with no possibility for new entries.
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelineksignalfd_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek *result = (void *)0;
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek 0, /* streamtab */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek 0, /* refcnt */
3d729aecc03ea6ebb9bd5d56b8dccd24f57daa41Jerry Jelinek &mod_driverops, /* module type (this is a pseudo driver) */