From 7e9a0975a41eeeba58810cd67dabb4af33d47c0c Mon Sep 17 00:00:00 2001 From: kurt Date: Fri, 2 May 2014 21:58:51 +0000 Subject: [PATCH] - Adjust pthread_stackseg_np to return the page aligned addressable stack range. okay kettenis@, guenther@, deraadt@ --- lib/librthread/rthread_np.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/librthread/rthread_np.c b/lib/librthread/rthread_np.c index 0cbb24e74e7..f7b213cfd24 100644 --- a/lib/librthread/rthread_np.c +++ b/lib/librthread/rthread_np.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_np.c,v 1.10 2013/11/29 16:27:40 guenther Exp $ */ +/* $OpenBSD: rthread_np.c,v 1.11 2014/05/02 21:58:51 kurt Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst * Copyright (c) 2005 Otto Moerbeek @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -63,7 +64,11 @@ int pthread_stackseg_np(pthread_t thread, stack_t *sinfo) { if (thread->stack) { - sinfo->ss_sp = thread->stack->sp; +#ifdef MACHINE_STACK_GROWS_UP + sinfo->ss_sp = thread->stack->base; +#else + sinfo->ss_sp = thread->stack->base + thread->stack->len; +#endif sinfo->ss_size = thread->stack->len; if (thread->stack->guardsize != 1) sinfo->ss_size -= thread->stack->guardsize; @@ -93,10 +98,12 @@ pthread_stackseg_np(pthread_t thread, stack_t *sinfo) * Provides a rough estimation of stack bounds. Caller * likely wants to know for the purpose of inspecting call * frames, but VM_PSSTRINGS points to process arguments... - * - * XXXX This interface ignores MACHINE_STACK_GROWS_UP. */ +#ifdef MACHINE_STACK_GROWS_UP sinfo->ss_sp = _ps.val; +#else + sinfo->ss_sp = (void *)ROUND_TO_PAGE((uintptr_t)_ps.val); +#endif sinfo->ss_size = (size_t)rl.rlim_cur; sinfo->ss_flags = 0; return (0); -- 2.20.1