View | Details | Raw Unified | Return to bug 195802
Collapse All | Expand All

(-)kern_sig.c (-21 / +33 lines)
Lines 1003-1010 Link Here
1003
	int error;
1003
	int error;
1004
1004
1005
	p = td->td_proc;
1005
	p = td->td_proc;
1006
	if (!(flags & SIGPROCMASK_PROC_LOCKED))
1006
	if ((flags & SIGPROCMASK_PROC_LOCKED) != 0)
1007
		PROC_LOCK_ASSERT(p, MA_OWNED);
1008
	else
1007
		PROC_LOCK(p);
1009
		PROC_LOCK(p);
1010
	mtx_assert(&p->p_sigacts->ps_mtx, ((flags & SIGPROCMASK_PS_LOCKED) != 0) ? MA_OWNED : MA_NOTOWNED);
1008
	if (oset != NULL)
1011
	if (oset != NULL)
1009
		*oset = td->td_sigmask;
1012
		*oset = td->td_sigmask;
1010
1013
Lines 1891-1896 Link Here
1891
	}
1894
	}
1892
}
1895
}
1893
1896
1897
1898
/*
1899
 * Recalculate the signal mask and reset the signal disposition after
1900
 * usermode frame for delivery is formed.  Should be called after
1901
 * mach-specific routine, because sysent->sv_sendsig() needs correct
1902
 * ps_siginfo and signal mask.
1903
 */
1904
static void
1905
postsig_done(int sig, struct thread *td, struct sigacts *ps)
1906
{
1907
	sigset_t mask;
1908
1909
	mtx_assert(&ps->ps_mtx, MA_OWNED);
1910
	td->td_ru.ru_nsignals++;
1911
	mask = ps->ps_catchmask[_SIG_IDX(sig)];
1912
	if (!SIGISMEMBER(ps->ps_signodefer, sig))
1913
		SIGADDSET(mask, sig);
1914
	kern_sigprocmask(td, SIG_BLOCK, &mask, NULL,
1915
	    SIGPROCMASK_PROC_LOCKED | SIGPROCMASK_PS_LOCKED);
1916
	if (SIGISMEMBER(ps->ps_sigreset, sig))
1917
		sigdflt(ps, sig);
1918
}
1919
1920
1894
/*
1921
/*
1895
 * Send a signal caused by a trap to the current thread.  If it will be
1922
 * Send a signal caused by a trap to the current thread.  If it will be
1896
 * caught immediately, deliver it with correct code.  Otherwise, post it
1923
 * caught immediately, deliver it with correct code.  Otherwise, post it
Lines 1900-1906 Link Here
1900
trapsignal(struct thread *td, ksiginfo_t *ksi)
1927
trapsignal(struct thread *td, ksiginfo_t *ksi)
1901
{
1928
{
1902
	struct sigacts *ps;
1929
	struct sigacts *ps;
1903
	sigset_t mask;
1904
	struct proc *p;
1930
	struct proc *p;
1905
	int sig;
1931
	int sig;
1906
	int code;
1932
	int code;
Lines 1915-1921 Link Here
1915
	mtx_lock(&ps->ps_mtx);
1941
	mtx_lock(&ps->ps_mtx);
1916
	if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(ps->ps_sigcatch, sig) &&
1942
	if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(ps->ps_sigcatch, sig) &&
1917
	    !SIGISMEMBER(td->td_sigmask, sig)) {
1943
	    !SIGISMEMBER(td->td_sigmask, sig)) {
1918
		td->td_ru.ru_nsignals++;
1919
#ifdef KTRACE
1944
#ifdef KTRACE
1920
		if (KTRPOINT(curthread, KTR_PSIG))
1945
		if (KTRPOINT(curthread, KTR_PSIG))
1921
			ktrpsig(sig, ps->ps_sigact[_SIG_IDX(sig)],
1946
			ktrpsig(sig, ps->ps_sigact[_SIG_IDX(sig)],
Lines 1923-1935 Link Here
1923
#endif
1948
#endif
1924
		(*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)],
1949
		(*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)],
1925
				ksi, &td->td_sigmask);
1950
				ksi, &td->td_sigmask);
1926
		mask = ps->ps_catchmask[_SIG_IDX(sig)];
1951
		postsig_done(sig, td, ps);
1927
		if (!SIGISMEMBER(ps->ps_signodefer, sig))
1928
			SIGADDSET(mask, sig);
1929
		kern_sigprocmask(td, SIG_BLOCK, &mask, NULL,
1930
		    SIGPROCMASK_PROC_LOCKED | SIGPROCMASK_PS_LOCKED);
1931
		if (SIGISMEMBER(ps->ps_sigreset, sig))
1932
			sigdflt(ps, sig);
1933
		mtx_unlock(&ps->ps_mtx);
1952
		mtx_unlock(&ps->ps_mtx);
1934
	} else {
1953
	} else {
1935
		/*
1954
		/*
Lines 2503-2511 Link Here
2503
	int sig;
2522
	int sig;
2504
2523
2505
	PROC_LOCK_ASSERT(p, MA_OWNED);
2524
	PROC_LOCK_ASSERT(p, MA_OWNED);
2525
	ps = p->p_sigacts;
2526
	mtx_assert(&ps->ps_mtx, ((flags & SIGPROCMASK_PS_LOCKED) != 0) ? MA_OWNED : MA_NOTOWNED);
2506
	if (SIGISEMPTY(p->p_siglist))
2527
	if (SIGISEMPTY(p->p_siglist))
2507
		return;
2528
		return;
2508
	ps = p->p_sigacts;
2509
	SIGSETAND(block, p->p_siglist);
2529
	SIGSETAND(block, p->p_siglist);
2510
	while ((sig = sig_ffs(&block)) != 0) {
2530
	while ((sig = sig_ffs(&block)) != 0) {
2511
		SIGDELSET(block, sig);
2531
		SIGDELSET(block, sig);
Lines 2811-2817 Link Here
2811
	struct sigacts *ps;
2831
	struct sigacts *ps;
2812
	sig_t action;
2832
	sig_t action;
2813
	ksiginfo_t ksi;
2833
	ksiginfo_t ksi;
2814
	sigset_t returnmask, mask;
2834
	sigset_t returnmask;
2815
2835
2816
	KASSERT(sig != 0, ("postsig"));
2836
	KASSERT(sig != 0, ("postsig"));
2817
2837
Lines 2866-2885 Link Here
2866
		} else
2886
		} else
2867
			returnmask = td->td_sigmask;
2887
			returnmask = td->td_sigmask;
2868
2888
2869
		mask = ps->ps_catchmask[_SIG_IDX(sig)];
2870
		if (!SIGISMEMBER(ps->ps_signodefer, sig))
2871
			SIGADDSET(mask, sig);
2872
		kern_sigprocmask(td, SIG_BLOCK, &mask, NULL,
2873
		    SIGPROCMASK_PROC_LOCKED | SIGPROCMASK_PS_LOCKED);
2874
2875
		if (SIGISMEMBER(ps->ps_sigreset, sig))
2876
			sigdflt(ps, sig);
2877
		td->td_ru.ru_nsignals++;
2878
		if (p->p_sig == sig) {
2889
		if (p->p_sig == sig) {
2879
			p->p_code = 0;
2890
			p->p_code = 0;
2880
			p->p_sig = 0;
2891
			p->p_sig = 0;
2881
		}
2892
		}
2882
		(*p->p_sysent->sv_sendsig)(action, &ksi, &returnmask);
2893
		(*p->p_sysent->sv_sendsig)(action, &ksi, &returnmask);
2894
		postsig_done(sig, td, ps);
2883
	}
2895
	}
2884
	return (1);
2896
	return (1);
2885
}
2897
}

Return to bug 195802