Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Oct 1997 14:45:01 -0400
From:      Tad Hunt <tad@mcp.csh.rit.edu>
To:        freebsd-hackers@freebsd.org
Subject:   -lc_r and setjmp (BUG)
Message-ID:  <199710221846.OAA01419@jake.csh.rit.edu>

next in thread | raw e-mail | index | archive | help
    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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199710221846.OAA01419>