From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 12 05:51:37 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E0D9216A4CE for ; Mon, 12 Jan 2004 05:51:37 -0800 (PST) Received: from mailhost.stack.nl (vaak.stack.nl [131.155.140.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 031FC43D46 for ; Mon, 12 Jan 2004 05:51:25 -0800 (PST) (envelope-from marcolz@stack.nl) Received: from toad.stack.nl (zen.stack.nl [2001:610:1108:5010::130]) by mailhost.stack.nl (Postfix) with ESMTP id 4002A65B#A8ED01F00E; Mon, 12 Jan 2004 14:51:23 +0100 (CET) Received: by toad.stack.nl (Postfix, from userid 333) id 65A7F8E; Mon, 12 Jan 2004 14:51:23 +0100 (CET) Date: Mon, 12 Jan 2004 14:51:23 +0100 From: Marc Olzheim To: Daniel Eischen Message-ID: <20040112135123.GA41657@stack.nl> References: <20031231140533.GA56158@stack.nl> <20031231143015.GA59104@stack.nl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline In-Reply-To: <20031231143015.GA59104@stack.nl> X-Operating-System: FreeBSD toad.stack.nl 4.9-RC FreeBSD 4.9-RC X-URL: http://www.stack.nl/~marcolz/ User-Agent: Mutt/1.5.5.1i cc: Marc Olzheim cc: hackers@freebsd.org Subject: Re: libc_r/uthread/uthread_join.c and uthread_create.c X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jan 2004 13:51:38 -0000 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="uthread_ebp.patch" --- /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 #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, --Kj7319i9nmIyA2yE--