From owner-freebsd-hackers Wed Oct 22 11:48:16 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id LAA18062 for hackers-outgoing; Wed, 22 Oct 1997 11:48:16 -0700 (PDT) (envelope-from owner-freebsd-hackers) Received: from jake.csh.rit.edu (jake.csh.rit.edu [129.21.60.8]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id LAA18010 for ; Wed, 22 Oct 1997 11:47:00 -0700 (PDT) (envelope-from tad@mcp.csh.rit.edu) Received: from localhost (tad@localhost) by jake.csh.rit.edu (8.8.5/8.8.5) with SMTP id OAA01419 for ; Wed, 22 Oct 1997 14:46:27 -0400 Message-Id: <199710221846.OAA01419@jake.csh.rit.edu> X-Authentication-Warning: jake.csh.rit.edu: tad owned process doing -bs X-Authentication-Warning: jake.csh.rit.edu: tad@localhost didn't use HELO protocol Reply-To: Tad Hunt To: freebsd-hackers@freebsd.org Subject: -lc_r and setjmp (BUG) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1374.877545901.1@mail.csh.rit.edu> Date: Wed, 22 Oct 1997 14:45:01 -0400 From: Tad Hunt Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk I was looking at the libc_r implementation of setjmp (lib/libc_r/uthread/uthread_setjmp.c) from (FreeBSD-2.2.5-101897) from lib/libc_r/uthread/uthread_setjmp.c: int setjmp(jmp_buf env) { return (_thread_sys_setjmp(env)); } where _thread_sys_setjmp is implemented in lib/libc/i386/gen/setjmp.S as something like the following: #ifdef _THREAD_SAFE ENTRY(_thread_sys_setjmp) #else ENTRY(setjmp) #endif [... essentially the same implementation for both cases, except for some signal stuff] In the case of threaded programs calling setjmp() (instead of calling _thread_sys_setjmp()) the wrong environment gets saved in the jmp_buf. When longjmp does it's work, it returns into setjmp() (instead of returning into the caller of setjmp(). Essentially the following is happening: jmp_buf foo; main() { bar(); longjmp(foo, 1); } bar() { setjmp(foo); } -Tad P.S. I don't know if this is the right place to report the bug, please redirect me if necessary.