summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authorkurt <kurt@openbsd.org>2007-07-08 01:53:46 +0000
committerkurt <kurt@openbsd.org>2007-07-08 01:53:46 +0000
commit64d5a1e1514d99339e7b67a3264f26427796f153 (patch)
tree528abaf8c3b1e5677957c1af85cffb0832cd99a9 /lib/libpthread
parentAs pointed out by Mickey, "-I/usr/includes" is not required for (diff)
downloadwireguard-openbsd-64d5a1e1514d99339e7b67a3264f26427796f153.tar.xz
wireguard-openbsd-64d5a1e1514d99339e7b67a3264f26427796f153.zip
Report the correct stack size and top for the primordial thread in
pthread_stackseg_np(). With input and okay marc@
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/uthread/uthread_stackseg_np.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/libpthread/uthread/uthread_stackseg_np.c b/lib/libpthread/uthread/uthread_stackseg_np.c
index cd423aeaf9a..c2a981c3a57 100644
--- a/lib/libpthread/uthread/uthread_stackseg_np.c
+++ b/lib/libpthread/uthread/uthread_stackseg_np.c
@@ -1,9 +1,11 @@
-/* $OpenBSD: uthread_stackseg_np.c,v 1.5 2007/05/18 19:28:50 kurt Exp $ */
+/* $OpenBSD: uthread_stackseg_np.c,v 1.6 2007/07/08 01:53:46 kurt Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
#include <sys/param.h>
+#include <sys/time.h>
#include <sys/lock.h>
+#include <sys/resource.h>
#include <sys/queue.h>
#include <errno.h>
@@ -27,6 +29,7 @@ pthread_stackseg_np(pthread_t thread, stack_t *sinfo)
char *base;
size_t pgsz;
int ret;
+ struct rlimit rl;
if (thread->stack) {
base = thread->stack->base;
@@ -38,22 +41,22 @@ pthread_stackseg_np(pthread_t thread, stack_t *sinfo)
sinfo->ss_flags = 0;
ret = 0;
} else if (thread == _thread_initial) {
+ if (getrlimit(RLIMIT_STACK, &rl) != 0)
+ return (EAGAIN);
pgsz = (size_t)sysconf(_SC_PAGESIZE);
if (pgsz == (size_t)-1)
- ret = EAGAIN;
- else {
-#if defined(MACHINE_STACK_GROWS_UP)
- base = (caddr_t) USRSTACK;
-#else
- base = (caddr_t) ((USRSTACK - DFLSSIZ) & ~(pgsz - 1));
- base += DFLSSIZ;
-#endif
- sinfo->ss_sp = base;
- sinfo->ss_size = DFLSSIZ;
- sinfo->ss_flags = 0;
- ret = 0;
- }
-
+ return (EAGAIN);
+ /*
+ * round_page() stack rlim_cur and
+ * trunc_page() USRSTACK to be consistent with
+ * the way the kernel sets up the stack.
+ */
+ sinfo->ss_size = (size_t)rl.rlim_cur;
+ sinfo->ss_size += (pgsz - 1);
+ sinfo->ss_size &= ~(pgsz - 1);
+ sinfo->ss_sp = (caddr_t) (USRSTACK & ~(pgsz - 1));
+ sinfo->ss_flags = 0;
+ ret = 0;
} else
ret = EAGAIN;