[Gc] Re: Boehm GC on FreeBSD trouble, and maybe fix?

Ivan Maidanski ivmai at mail.ru
Thu Feb 3 14:03:42 PST 2011


Hi Dimitry,

1. I've already fixed the issue (but in a different way), see http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/bdwgc-7_2alpha5-20110107.tar.bz2
The mine variant is:
 
#   if defined(FREEBSD)
#     define SIG_OK TRUE
#     define CODE_OK (si -> si_code == BUS_PAGE_FAULT \
                      || si -> si_code == 2 /* experimentally determined */)

2. Probably, it's better to use SEGV_ACCERR instead of 2 but I couldn't find it at least in FreeBSD r6.2.

3. Have you tested your code with some older FreeBSD releases (it can't test it right now but it seems that the old code worked before FreeBSD r7).

Regards.

Sun, 30 Jan 2011 21:44:10 +0100 Dimitry Andric <dim at FreeBSD.org>:

> Hi Dmitry,
> 
> When I ran into some problems running "gmake check" with Boehm GC on
> FreeBSD, I searched around and ended up on this post of you:
> 
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/2010-August/004076.html
> 
> The end of that thread had Hans Boehm saying:
> 
> > I don't think the free-list is intended to be unprotected at this
> > stage.  GC_write_fault_handler() should just be invoked if something
> > is still protected, and that should unprotect it.
> ...
> > So the question is why GC_write_fault_handler thinks it's bad.  It
> > might be useful to step into the handler and see what it's doing.
> 
> So I tried just that, and it seems the first thing the handler does, is
> check if the signal is "OK", in the sense that the signal number and
> other information is appropriate:
> 
> STATIC void GC_write_fault_handler(int sig, siginfo_t *si, void *raw_sc)
> {
> char *addr = si -> si_addr;
> unsigned i;
> 
> if (SIG_OK && CODE_OK) {
> //... handles unprotecting and returns
> }
> GC_err_printf("Segfault at %p\n", addr);
> ABORT("Unexpected bus error or segmentation fault");
> }
> 
> The SIG_OK and CODE_OK macros are defined earlier in the file, and for
> FreeBSD they are (at least in 7.2alpha4, the CVS server on SourceForge
> is down at the moment, so I could not check the latest):
> 
> #   if defined(FREEBSD)
> #     define SIG_OK TRUE
> #     define CODE_OK (si -> si_code == BUS_PAGE_FAULT)
> ...
> 
> The problem is that BUS_PAGE_FAULT is only for SIGBUS, and then only for
> the machine-dependent si_trapno field, *not* the si_code field.
> 
> In case of the segfault I get here, I always get SIGSEGV, not SIGBUS,
> and then the si_code field is SEGV_ACCERR, which means "invalid
> permissions for mapped object".
> 
> So, the handler always erroneously concludes there is an unexpected bus
> error, and aborts here, even if the SIGSEGV was just fine.
> 
> To make it work correctly, I changed the definition of the SIG_OK and
> CODE_OK macros for FreeBSD to:
> 
> #   if defined(FREEBSD)
> #     define SIG_OK (sig == SIGSEGV)
> #     define CODE_OK (si -> si_code == SEGV_ACCERR)
> ...
> 
> And then all tests pass correctly.  Does this seem reasonable?



More information about the Gc mailing list