Can some Haiku developer comment on this patch to Boehm-GC?

Dear developers,

I recently patched the Boehm-GC package in Haiku because it fails to work with Guile 2.2.7 (compilation breaks at some point). I also proposed the patch upstream and the Boehm-GC people are willing to take into the next revision. However we feel it would be good if somebody with more knowledge in Haiku could give it a look. Seems a problem with mmap. Boehm-GC has already some OS-dependent conditional code in the situation which causes problem, so I think it is just a matter to be sure it makes sense for Haiku and/or does not hint to a further problem in Haikus itself.

It is here:

Thanks,
Max

Yes, this is likely a bug in Haiku; there is already a similar issue that @KapiX is investigating which may be the culprit: https://dev.haiku-os.org/ticket/15804

This is the part of BoehmGC which is relevant (my patch just add || defined(__HAIKU___) at the first preprocessor conditional

      /* We immediately remap it to prevent an intervening mmap from    */
      /* accidentally grabbing the same address space.                  */
      {
#       if defined(AIX) || defined(CYGWIN32) || defined(HPUX)
          /* On AIX, mmap(PROT_NONE) fails with ENOMEM unless the       */
          /* environment variable XPG_SUS_ENV is set to ON.             */
          /* On Cygwin, calling mmap() with the new protection flags on */
          /* an existing memory map with MAP_FIXED is broken.           */
          /* However, calling mprotect() on the given address range     */
          /* with PROT_NONE seems to work fine.                         */
          if (mprotect(start_addr, len, PROT_NONE))
            ABORT("mprotect(PROT_NONE) failed");
#       else
          void * result = mmap(start_addr, len, PROT_NONE,
                               MAP_PRIVATE | MAP_FIXED | OPT_MAP_ANON,
                               zero_fd, 0/* offset */);

          if (result != (void *)start_addr)
            ABORT("mmap(PROT_NONE) failed");
#         if defined(CPPCHECK) || defined(LINT2)
            /* Explicitly store the resource handle to a global variable. */
            GC_noop1((word)result);
#         endif
#       endif /* !CYGWIN32 */
      }
'''

Not exactly, I’m not investigating it in an active manner. A few hours working at this didn’t give me much understanding of the problem, and I don’t intend to spend more time on it in the near future. So, if anyone feels like taking a crack at this, go ahead.

Maybe trying the same thing as boehm-gc (using mprotect with PROT_NONE) would work in WebKit as well. At least this would solve that part?

Nope, doesn’t work. My understanding is it goes in place of unmap, but that wouldn’t work anyway since mmap tries to unmap first.

I’m confused, you managed to trace it to where the error is getting returned at least, but you said you got stuck because adding printfs in there creates loops, or something? Does using the serial-only debug facility break the loops, and let you continue?

As I said before, I didn’t try to debug it any further since. I only started debugging it because maybe I could find and fix the bug quickly, but after 4 hours I’m not much closer to understanding it. Due to time constraints I don’t want to go and learn the guts of VM subsystem right now.

My answer above was about mprotect. I tried using it in my reproducer, but it doesn’t solve the issue.