libc_r/uthread/uthread_join.c and uthread_create.c

Marc Olzheim marcolz at stack.nl
Mon Jan 12 05:51:38 PST 2004


On Wed, Dec 31, 2003 at 03:30:15PM +0100, Marc Olzheim wrote:
> So I noticed. But it seems to me as if the undefers could be removed
> from within the if-else-blocks and collapsed into a single undefer just
> beneath the if-else-blocks, right before the
> _thread_leave_cancellation_point();

Hmm, this is just what OpenBSD did...

Any way: new problem / idea:

uthread_create.c: _pthread_create() doesn't clean ebp, so producing a
backtrace, either with gdb, or with gcc's __builtin_frame_address(),
results in garbage, cq. segmentation faults, when for instance the
spawning thread has already been deleted.

The following patch fixes that for i386. I don't have any other systems
available, so I don't know what to do on other systems, but this works
for us.

Zlo
-------------- next part --------------
--- /usr/src/lib/libc_r/uthread/pthread_private.h	Tue Oct 22 16:44:02 2002
+++ /usr/src/lib/libc_r/uthread/pthread_private.h	Mon Jan 12 14:34:32 2004
@@ -84,7 +84,8 @@
 	fdata = (char *) (ucp)->uc_mcontext.mc_fpregs;	\
 	__asm__("frstor %0": :"m"(*fdata));		\
 } while (0)
-#define SET_RETURN_ADDR_JB(jb, ra)	(jb)[0]._jb[0] = (int)(ra)
+#define	SET_RETURN_ADDR_JB(jb, ra)	(jb)[0]._jb[0] = (int)(ra)
+#define	SET_FRAME_PTR_JB(jb, fp)	(jb)[0]._jb[3] = (int)(fp)
 #elif	defined(__alpha__)
 #include <machine/reg.h>
 #define	GET_STACK_JB(jb)	((unsigned long)((jb)[0]._jb[R_SP + 4]))
--- /usr/src/lib/libc_r/uthread/uthread_create.c	Wed Jan  8 06:04:26 2003
+++ /usr/src/lib/libc_r/uthread/uthread_create.c	Mon Jan 12 14:23:56 2004
@@ -195,6 +195,7 @@
 			 * _thread_start().
 			 */
 			SET_RETURN_ADDR_JB(new_thread->ctx.jb, _thread_start);
+			SET_FRAME_PTR_JB(new_thread->ctx.jb, NULL);
 
 			/* The stack starts high and builds down: */
 			SET_STACK_JB(new_thread->ctx.jb,


More information about the freebsd-hackers mailing list