summaryrefslogtreecommitdiffstats
path: root/lib/libc_r/uthread/uthread_create.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2003-12-03 06:54:40 +0000
committerpeter <peter@FreeBSD.org>2003-12-03 06:54:40 +0000
commit976bb368f632aecb3df41d286354c57f38921b00 (patch)
treedd4cb5a18a26bf30a1c6df35e18a237dba59bd22 /lib/libc_r/uthread/uthread_create.c
parent53610e3cd2be6e7615ccc52ddb9f997276a0b1da (diff)
downloadFreeBSD-src-976bb368f632aecb3df41d286354c57f38921b00.zip
FreeBSD-src-976bb368f632aecb3df41d286354c57f38921b00.tar.gz
For the amd64 we need to do some extra stack alignment fixups. Otherwise
we can end up with some threads with a non-16-byte-aligned stack. This causes some interesting side effects, including general protection faults leading to a SIGBUS when doing floating point or varargs. This should be just a verbose NOP for the other platforms. Approved by: re (scottl)
Diffstat (limited to 'lib/libc_r/uthread/uthread_create.c')
-rw-r--r--lib/libc_r/uthread/uthread_create.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/libc_r/uthread/uthread_create.c b/lib/libc_r/uthread/uthread_create.c
index 2ea87b2..356bc07 100644
--- a/lib/libc_r/uthread/uthread_create.c
+++ b/lib/libc_r/uthread/uthread_create.c
@@ -73,6 +73,9 @@ _pthread_create(pthread_t *thread, const pthread_attr_t *attr,
pthread_t new_thread;
pthread_attr_t pattr;
void *stack;
+#if !defined(__ia64__)
+ u_long stackp;
+#endif
if (thread == NULL)
return(EINVAL);
@@ -145,10 +148,12 @@ _pthread_create(pthread_t *thread, const pthread_attr_t *attr,
SET_RETURN_ADDR_JB(new_thread->ctx.jb, _thread_start);
#if !defined(__ia64__)
+ stackp = (long)new_thread->stack + pattr->stacksize_attr - sizeof(double);
+#if defined(__amd64__)
+ stackp &= ~0xFUL;
+#endif
/* The stack starts high and builds down: */
- SET_STACK_JB(new_thread->ctx.jb,
- (long)new_thread->stack + pattr->stacksize_attr
- - sizeof(double));
+ SET_STACK_JB(new_thread->ctx.jb, stackp);
#else
SET_STACK_JB(new_thread->ctx.jb,
(long)new_thread->stack, pattr->stacksize_attr);
OpenPOWER on IntegriCloud