From owner-freebsd-hackers Tue Jun 26 14: 9:46 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from pcnet1.pcnet.com (pcnet1.pcnet.com [204.213.232.3]) by hub.freebsd.org (Postfix) with ESMTP id 6FED537B401 for ; Tue, 26 Jun 2001 14:09:37 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: (from eischen@localhost) by pcnet1.pcnet.com (8.8.7/PCNet) id RAA12944; Tue, 26 Jun 2001 17:08:56 -0400 (EDT) Date: Tue, 26 Jun 2001 17:08:54 -0400 (EDT) From: Daniel Eischen To: Louis-Philippe Gagnon Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: pthread/longjmp/signal problem In-Reply-To: <0db001c0fa62$2b567800$2964a8c0@macadamian.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, 21 Jun 2001, Louis-Philippe Gagnon wrote: > No reactions the first time, let's try again. > > I've encountered a problem in the interaction betwen signals, longjmp and > pthreads; I'm hoping someone can help me make sense of it. > > I've been trying to implement a IsBadReadPtr-style function in FreeBSD by > using signal handlers and longjmp/setjmp. It seemed to work as expected, > until I started using the -pthread option to gcc (thus linking against > libc_r). Now the function only works on the first call; subsequent calls > hang on the segmentation fault. > > Here's an example of the kind of code that causes problems : Try this patch (to -stable). Only the patch to uthread_sig.c is needed for -current. -- Dan Eischen Index: libc/i386/gen/setjmp.S =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libc/i386/gen/setjmp.S,v retrieving revision 1.17.2.1 diff -u -r1.17.2.1 setjmp.S --- libc/i386/gen/setjmp.S 2000/05/16 20:43:21 1.17.2.1 +++ libc/i386/gen/setjmp.S 2001/06/26 21:07:23 @@ -61,11 +61,7 @@ pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else call PIC_PLT(CNAME(sigprocmask)) -#endif addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -91,11 +87,7 @@ leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else call PIC_PLT(CNAME(sigprocmask)) -#endif addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx Index: libc/i386/gen/sigsetjmp.S =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libc/i386/gen/sigsetjmp.S,v retrieving revision 1.19.2.1 diff -u -r1.19.2.1 sigsetjmp.S --- libc/i386/gen/sigsetjmp.S 2000/05/16 20:43:21 1.19.2.1 +++ libc/i386/gen/sigsetjmp.S 2001/06/26 21:04:34 @@ -70,11 +70,7 @@ pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else call PIC_PLT(CNAME(sigprocmask)) -#endif addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -102,11 +98,7 @@ leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else call PIC_PLT(CNAME(sigprocmask)) -#endif addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx Index: libc_r/uthread/uthread_sig.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libc_r/uthread/uthread_sig.c,v retrieving revision 1.25.2.7 diff -u -r1.25.2.7 uthread_sig.c --- libc_r/uthread/uthread_sig.c 2001/06/23 00:47:05 1.25.2.7 +++ libc_r/uthread/uthread_sig.c 2001/06/26 20:56:52 @@ -931,6 +931,12 @@ thread->curframe = NULL; PTHREAD_ASSERT(psf != NULL, "Invalid signal frame in signal handler"); + /* + * We came here from the kernel scheduler; clear the in scheduler + * flag. + */ + _thread_kern_in_sched = 0; + /* Check the threads previous state: */ if (psf->saved_state.psd_state != PS_RUNNING) { /* To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message