summaryrefslogtreecommitdiff
path: root/lib/librthread
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2006-01-05 08:15:17 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2006-01-05 08:15:17 +0000
commitdd74e0c8bf477bf947c6d9949987b5516659fbac (patch)
treeb362671a7acefc0ef6300b22fadda581c26cba89 /lib/librthread
parentc561b5e78ceab3f681a200f320da9a93164411ca (diff)
Remove redundant mprotect() calls (we're unmapping the region anyway)
and check user stack for proper alignment. ok tedu@ marc@
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/rthread_attr.c14
-rw-r--r--lib/librthread/rthread_stack.c6
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c
index 4806aef0eb2..6bc334ba92b 100644
--- a/lib/librthread/rthread_attr.c
+++ b/lib/librthread/rthread_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_attr.c,v 1.7 2006/01/05 04:06:48 marc Exp $ */
+/* $OpenBSD: rthread_attr.c,v 1.8 2006/01/05 08:15:16 otto Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -25,6 +25,7 @@
#include <machine/spinlock.h>
+#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
@@ -135,7 +136,10 @@ pthread_attr_getstack(const pthread_attr_t *attrp, void **stackaddr,
int
pthread_attr_setstack(pthread_attr_t *attrp, void *stackaddr, size_t stacksize)
{
- (*attrp)->stack_addr = stackaddr;
+ int n;
+
+ if ((n = pthread_attr_setstackaddr(attrp, stackaddr)))
+ return (n);
(*attrp)->stack_size = stacksize;
(*attrp)->stack_size -= (*attrp)->guard_size;
@@ -173,6 +177,12 @@ pthread_attr_getstackaddr(const pthread_attr_t *attrp, void **stackaddr)
int
pthread_attr_setstackaddr(pthread_attr_t *attrp, void *stackaddr)
{
+ size_t pgsz = sysconf(_SC_PAGESIZE);
+
+ if (pgsz == (size_t)-1)
+ return EINVAL;
+ if ((uintptr_t)stackaddr & (pgsz - 1))
+ return EINVAL;
(*attrp)->stack_addr = stackaddr;
return (0);
diff --git a/lib/librthread/rthread_stack.c b/lib/librthread/rthread_stack.c
index 05a1f6158ea..d76a824b816 100644
--- a/lib/librthread/rthread_stack.c
+++ b/lib/librthread/rthread_stack.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_stack.c,v 1.1 2006/01/01 19:32:30 marc Exp $ */
+/* $OpenBSD: rthread_stack.c,v 1.2 2006/01/05 08:15:16 otto Exp $ */
/* $snafu: rthread_stack.c,v 1.12 2005/01/11 02:45:28 marc Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
@@ -66,8 +66,6 @@ _rthread_alloc_stack(pthread_t thread)
/* wrap up the info in a struct stack and return it */
stack = malloc(sizeof(*stack));
if (!stack) {
- mprotect(guard, thread->attr.guard_size,
- PROT_EXEC | PROT_READ | PROT_WRITE);
munmap(base, size);
return (NULL);
}
@@ -84,8 +82,6 @@ _rthread_alloc_stack(pthread_t thread)
void
_rthread_free_stack(struct stack *stack)
{
- mprotect(stack->guard, stack->guardsize,
- PROT_EXEC | PROT_READ | PROT_WRITE);
munmap(stack->base, stack->len);
free(stack);
}