aboutsummaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2018-11-27 19:50:58 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2018-11-27 19:50:58 +0000
commitaffd918514794a231cd571d0d15c9cfaf4a2a6f4 (patch)
tree9a14dd73b0147397866e7a8faec28c2347149988 /sys/kern
parentb307954481a13a501bf9f315d160ff768174feff (diff)
downloadsrc-affd918514794a231cd571d0d15c9cfaf4a2a6f4.tar.gz
src-affd918514794a231cd571d0d15c9cfaf4a2a6f4.zip
Improve sigonstack().
Avoid relying on unsigned overflow for the test. Simplify expressions to avoid duplicate check for the range. Style. Add herald comment. Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D18361
Notes
Notes: svn path=/head/; revision=341094
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_sig.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 0817bb618c1c..2ed7d36f2c33 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -615,20 +615,25 @@ signotify(struct thread *td)
}
}
+/*
+ * Returns 1 (true) if altstack is configured for the thread, and the
+ * passed stack bottom address falls into the altstack range. Handles
+ * the 43 compat special case where the alt stack size is zero.
+ */
int
sigonstack(size_t sp)
{
- struct thread *td = curthread;
+ struct thread *td;
- return ((td->td_pflags & TDP_ALTSTACK) ?
+ td = curthread;
+ if ((td->td_pflags & TDP_ALTSTACK) == 0)
+ return (0);
#if defined(COMPAT_43)
- ((td->td_sigstk.ss_size == 0) ?
- (td->td_sigstk.ss_flags & SS_ONSTACK) :
- ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size))
-#else
- ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size)
+ if (td->td_sigstk.ss_size == 0)
+ return ((td->td_sigstk.ss_flags & SS_ONSTACK) != 0);
#endif
- : 0);
+ return (sp >= (size_t)td->td_sigstk.ss_sp &&
+ sp < td->td_sigstk.ss_size + (size_t)td->td_sigstk.ss_sp);
}
static __inline int