Skip to content

Commit 7e9a097

Browse files
committed
- Adjust pthread_stackseg_np to return the page aligned addressable stack
range. okay kettenis@, guenther@, deraadt@
1 parent 16b581a commit 7e9a097

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/librthread/rthread_np.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: rthread_np.c,v 1.10 2013/11/29 16:27:40 guenther Exp $ */
1+
/* $OpenBSD: rthread_np.c,v 1.11 2014/05/02 21:58:51 kurt Exp $ */
22
/*
33
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
44
* Copyright (c) 2005 Otto Moerbeek <otto@openbsd.org>
@@ -24,6 +24,7 @@
2424
#include <sys/queue.h>
2525
#include <sys/sysctl.h>
2626

27+
#include <inttypes.h>
2728
#include <errno.h>
2829
#include <pthread.h>
2930
#include <pthread_np.h>
@@ -63,7 +64,11 @@ int
6364
pthread_stackseg_np(pthread_t thread, stack_t *sinfo)
6465
{
6566
if (thread->stack) {
66-
sinfo->ss_sp = thread->stack->sp;
67+
#ifdef MACHINE_STACK_GROWS_UP
68+
sinfo->ss_sp = thread->stack->base;
69+
#else
70+
sinfo->ss_sp = thread->stack->base + thread->stack->len;
71+
#endif
6772
sinfo->ss_size = thread->stack->len;
6873
if (thread->stack->guardsize != 1)
6974
sinfo->ss_size -= thread->stack->guardsize;
@@ -93,10 +98,12 @@ pthread_stackseg_np(pthread_t thread, stack_t *sinfo)
9398
* Provides a rough estimation of stack bounds. Caller
9499
* likely wants to know for the purpose of inspecting call
95100
* frames, but VM_PSSTRINGS points to process arguments...
96-
*
97-
* XXXX This interface ignores MACHINE_STACK_GROWS_UP.
98101
*/
102+
#ifdef MACHINE_STACK_GROWS_UP
99103
sinfo->ss_sp = _ps.val;
104+
#else
105+
sinfo->ss_sp = (void *)ROUND_TO_PAGE((uintptr_t)_ps.val);
106+
#endif
100107
sinfo->ss_size = (size_t)rl.rlim_cur;
101108
sinfo->ss_flags = 0;
102109
return (0);

0 commit comments

Comments
 (0)