Subject: Re: CVS commit: src/lib (libpthread)
To: Geoff Wing <mason@primenet.com.au>
From: Chuck Silvers <chuq@chuq.com>
List: source-changes
Date: 07/19/2004 09:02:19
--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

hi,

On Mon, Jul 19, 2004 at 06:17:27AM +0000, Geoff Wing wrote:
> Geoff Wing <mason@primenet.com.au> typed:
> : Chuck Silvers <chs@netbsd.org> typed:
> :: cvs rdiff -r1.12 -r1.13 src/lib/libpthread/pthread_stack.c
> 
> It's this change that's causing a problem.  In pthread__stackid_setup():
> 
>         /* Set up an initial ucontext pointer to a "safe" area */
> -       t->pt_uc =(ucontext_t *)(void *)((char *)t->pt_stack.ss_sp + 
> -           t->pt_stack.ss_size - (pagesize/2));
> -#ifdef _UC_UCONTEXT_ALIGN
> -       t->pt_uc = (ucontext_t *)((uintptr_t)t->pt_uc & _UC_UCONTEXT_ALIGN);
> -#endif
> +       t->pt_uc = (ucontext_t *)
> +               STACK_ALIGN(STACK_GROW(t->pt_stack.ss_sp, pagesize / 2),
> +                           ~_UC_UCONTEXT_ALIGN);

yea, that doesn't do the same thing.  I'm not sure why it would matter, though.
does the attached patch fix the problem?

curiously, the regress/lib/libpthread tests don't fail for me.
I didn't try all of them, but several of the more stressful ones passed.
I'm building firefox from current pkgsrc now, I'll do some experiments
tonight.

-Chuck

--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.pthread.1"

Index: src/lib/libpthread/pthread_stack.c
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_stack.c,v
retrieving revision 1.13
diff -u -p -r1.13 pthread_stack.c
--- src/lib/libpthread/pthread_stack.c	18 Jul 2004 21:24:52 -0000	1.13
+++ src/lib/libpthread/pthread_stack.c	19 Jul 2004 13:19:53 -0000
@@ -160,6 +160,7 @@ pthread__stackid_setup(void *base, size_
 	pthread_t t;
 	void *redaddr;
 	size_t pagesize;
+	caddr_t sp;
 	int ret;
 
 	t = base;
@@ -171,18 +172,18 @@ pthread__stackid_setup(void *base, size_
 	 */
 
 	redaddr = STACK_SHRINK(STACK_MAX(base, size), pagesize);
+	t->pt_stack.ss_size = PT_STACKSIZE - 2 * pagesize;
 #ifdef __MACHINE_STACK_GROWS_UP
 	t->pt_stack.ss_sp = (char *)base + pagesize;
+	sp = t->pt_stack.ss_sp;
 #else
 	t->pt_stack.ss_sp = (char *)base + 2 * pagesize;
+	sp = (caddr_t)t->pt_stack.ss_sp + t->pt_stack.ss_size;
 #endif
-	t->pt_stack.ss_size = PT_STACKSIZE - 2 * pagesize;
-
 
 	/* Set up an initial ucontext pointer to a "safe" area */
 	t->pt_uc = (ucontext_t *)
-		STACK_ALIGN(STACK_GROW(t->pt_stack.ss_sp, pagesize / 2),
-			    ~_UC_UCONTEXT_ALIGN);
+		STACK_ALIGN(STACK_GROW(sp, pagesize / 2), ~_UC_UCONTEXT_ALIGN);
 
 	/* Protect the next-to-bottom stack page as a red zone. */
 	ret = mprotect(redaddr, pagesize, PROT_NONE);

--C7zPtVaVf+AK4Oqc--