Skip to content
Snippets Groups Projects
Commit 4fc3e1db authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix egregious race/infinite loop bug for FreeBSD and NetBSD

The allocator has a loop trying to map an aligned page, and there's
an obvious (and commented-on) race condition in it.  The purpose
is apparently to get an aligned allocation using mmap().

For FreeBSD and NetBSD, we can simply pass the desired alignment
to mmap() and we're good.

Other platforms are still hosed though.

This generally didn't happen, but something about FreeBSD 14.2 on
a many core (16+HT) system causes it to park in the loop and stay
there, adding new threads to to fun as it goes along.

This uses MAP_ALLOCED() if defined avoid the loop completely.
We'll see if it works soon enough.
parent e5085ece
No related branches found
No related tags found
No related merge requests found
Pipeline #8052 failed
......@@ -67,7 +67,7 @@ $(JS_SRC): | $(3RDPSRCDIR)
$(JS_IDIR): | $(3RDPODIR)
$(QUIET)$(IFNOTEXIST) mkdir $(JS_IDIR)
$(JSLIB_BUILD): $(3RDP_ROOT)/dist/libmozjs.tgz $(3RDP_ROOT)/dist/libffi.tgz $(3RDP_ROOT)/build/js_src_jsnativestack_cpp.patch $(3RDP_ROOT)/build/js-configure.patch $(3RDP_ROOT)/build/js-configure.in.patch $(3RDP_ROOT)/build/imacro-asm-fix.patch $(3RDP_ROOT)/build/js-volatile-outside-functions.patch $(3RDP_ROOT)/build/js-Wno-misleading-indentation.patch $(3RDP_ROOT)/build/js-allow-python3.patch $(3RDP_ROOT)/build/js-no-rwx-pages.patch $(3RDP_ROOT)/build/js-disable-shell.patch $(3RDP_ROOT)/build/js-darwin-configure.patch $(3RDP_ROOT)/build/js-keep-ffi-cache.patch $(3RDP_ROOT)/build/js-support-mingw-cross.patch $(3RDP_ROOT)/build/js-int-main-conf.patch $(3RDP_ROOT)/build/js-include-headers.patch $(3RDP_ROOT)/build/js-macos-configure.patch $(3RDP_ROOT)/build/js-isfinite.patch $(3RDP_ROOT)/build/js-libffi-prefix.patch | $(JS_SRC) $(JS_IDIR)
$(JSLIB_BUILD): $(3RDP_ROOT)/dist/libmozjs.tgz $(3RDP_ROOT)/dist/libffi.tgz $(3RDP_ROOT)/build/js_src_jsnativestack_cpp.patch $(3RDP_ROOT)/build/js-configure.patch $(3RDP_ROOT)/build/js-configure.in.patch $(3RDP_ROOT)/build/imacro-asm-fix.patch $(3RDP_ROOT)/build/js-volatile-outside-functions.patch $(3RDP_ROOT)/build/js-Wno-misleading-indentation.patch $(3RDP_ROOT)/build/js-allow-python3.patch $(3RDP_ROOT)/build/js-no-rwx-pages.patch $(3RDP_ROOT)/build/js-disable-shell.patch $(3RDP_ROOT)/build/js-darwin-configure.patch $(3RDP_ROOT)/build/js-keep-ffi-cache.patch $(3RDP_ROOT)/build/js-support-mingw-cross.patch $(3RDP_ROOT)/build/js-int-main-conf.patch $(3RDP_ROOT)/build/js-include-headers.patch $(3RDP_ROOT)/build/js-macos-configure.patch $(3RDP_ROOT)/build/js-isfinite.patch $(3RDP_ROOT)/build/js-libffi-prefix.patch $(3RDP_ROOT)/build/js-map-aligned.patch | $(JS_SRC) $(JS_IDIR)
@echo Creating $@ ...
$(QUIET)-rm -rf $(JS_SRC)/*
$(QUIET)tar -xzpC $(JS_SRC) -f $(3RDPDISTDIR)/libmozjs.tgz
......@@ -95,6 +95,7 @@ $(JSLIB_BUILD): $(3RDP_ROOT)/dist/libmozjs.tgz $(3RDP_ROOT)/dist/libffi.tgz $(3R
$(QUIET)patch -b -p0 -d $(JS_SRC) < js-macos-configure.patch
$(QUIET)patch -b -p0 -d $(JS_SRC) < js-isfinite.patch
$(QUIET)patch -b -p0 -d $(JS_SRC) < js-libffi-prefix.patch
$(QUIET)patch -b -p0 -d $(JS_SRC) < js-map-aligned.patch
-$(QUIET)cd $(JS_SRC)/js-1.8.5/js/src && autoconf-2.13
-$(QUIET)cd $(JS_SRC)/js-1.8.5/js/src && autoconf2.13
$(QUIET)chmod 0755 $(JS_SRC)/js-1.8.5/js/src/build/hcc
......
--- js-1.8.5/js/src/jsgcchunk.cpp.orig 2025-01-26 17:00:34.835529000 -0500
+++ js-1.8.5/js/src/jsgcchunk.cpp 2025-01-26 17:04:41.172785000 -0500
@@ -290,6 +290,19 @@
#elif defined(XP_UNIX) || defined(XP_BEOS)
+# if defined(MAP_ALIGNED)
+# define JS_GC_HAS_MAP_SHIFT_ALIGN
+static void *
+MapShiftAlignedPages(size_t size, uint8_t shift)
+{
+ void *p = mmap(NULL, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_NOSYNC | MAP_ALIGNED(shift) | MAP_ANON, -1, 0);
+ if (p == MAP_FAILED)
+ return NULL;
+ return p;
+}
+# else
+
/* Required on Solaris 10. Might improve performance elsewhere. */
# if defined(SOLARIS) && defined(MAP_ALIGN)
# define JS_GC_HAS_MAP_ALIGN
@@ -335,6 +348,7 @@
}
# endif /* !JS_GC_HAS_MAP_ALIGN */
+# endif
static void
UnmapPages(void *addr, size_t size)
@@ -365,7 +379,11 @@
{
void *p;
-#ifdef JS_GC_HAS_MAP_ALIGN
+#ifdef JS_GC_HAS_MAP_SHIFT_ALIGN
+ p = MapShiftAlignedPages(GC_CHUNK_SIZE, GC_CHUNK_SHIFT);
+ if (!p)
+ return NULL;
+#elif defined(JS_GC_HAS_MAP_ALIGN)
p = MapAlignedPages(GC_CHUNK_SIZE, GC_CHUNK_SIZE);
if (!p)
return NULL;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment