More mongodb80 patches (still broken)

- Add proper futex implementation for OpenBSD in waitable_atomic.cpp
- Fix libmongocrypt DLL path handling on OpenBSD
- mozjs patches:
  - Fix visibility flags in toolchain configuration
  - Resolve dlmalloc compilation issues
  - Limit executable memory for OpenBSD's datasize limits
  - Add mutable section attribute for read-only pages
  - Remove conflicting type definitions in math_private.h
This commit is contained in:
rsadowski
2025-09-26 16:10:41 +00:00
parent e590c05b9d
commit 1f4bd80bc2
7 changed files with 124 additions and 10 deletions
@@ -1,27 +1,68 @@
Index: src/mongo/platform/waitable_atomic.cpp
--- src/mongo/platform/waitable_atomic.cpp.orig
+++ src/mongo/platform/waitable_atomic.cpp
@@ -235,6 +235,23 @@ bool waitUntil(const void* uaddr,
return timeoutOverflow || errno != ETIMEDOUT;
}
@@ -38,6 +38,13 @@
#include <synchapi.h>
#endif
+#ifdef __OpenBSD__
+#include <sys/futex.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <unistd.h>
+#endif
+
namespace mongo::waitable_atomic_details {
using stdx::chrono::system_clock;
@@ -233,6 +240,50 @@ bool waitUntil(const void* uaddr,
// There isn't a good list of possible errors, so assuming that anything other than a timeout
// error is a possible spurious wakeup.
return timeoutOverflow || errno != ETIMEDOUT;
+}
+
+#elif defined(__OpenBSD__)
+
+void notifyOne(const void* uaddr) {
+ auto* addr = reinterpret_cast<volatile uint32_t*>(const_cast<void*>(uaddr));
+ futex(addr, FUTEX_WAKE_PRIVATE, 1, nullptr, nullptr);
+}
+
+void notifyMany(const void* uaddr, int nToWake) {
+ auto* addr = reinterpret_cast<volatile uint32_t*>(const_cast<void*>(uaddr));
+ futex(addr, FUTEX_WAKE_PRIVATE, nToWake, nullptr, nullptr);
+}
+
+void notifyAll(const void* uaddr) {
+ auto* addr = reinterpret_cast<volatile uint32_t*>(const_cast<void*>(uaddr));
+ futex(addr, FUTEX_WAKE_PRIVATE, INT_MAX, nullptr, nullptr);
+}
+
+bool waitUntil(const void* uaddr,
+ uint32_t old,
+ boost::optional<system_clock::time_point> deadline) {
+ return true;
+}
+ auto* addr = reinterpret_cast<volatile uint32_t*>(const_cast<void*>(uaddr));
+
+ if (!deadline) {
+ int ret = futex(addr, FUTEX_WAIT_PRIVATE, old, nullptr, nullptr);
+ return ret == 0;
+ }
+
+ auto now = system_clock::now();
+ if (*deadline <= now) {
+ return false; // Already timed out
+ }
+
+ auto duration = *deadline - now;
+ auto sec = std::chrono::duration_cast<std::chrono::seconds>(duration);
+ auto nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - sec);
+
+ struct timespec timeout;
+ timeout.tv_sec = sec.count();
+ timeout.tv_nsec = nsec.count();
+
+ int ret = futex(addr, FUTEX_WAIT_PRIVATE, old, &timeout, nullptr);
+ return ret == 0;
}
#else
#error "Need an implementation of waitUntil(), notifyOne(), notifyMany(), notifyAll() for this OS"
#endif
@@ -7,10 +7,10 @@ Index: src/third_party/libmongocrypt/dist/src/os_posix/os_dll.c
+#elif defined(__OpenBSD__)
+
+// XXXX
+mcr_dll_path_result mcr_dll_path(mcr_dll dll) {
+ mcr_dll_path_result r;
+ return r;
+ mcr_dll_path_result r;
+ memset(&r, 0, sizeof(r));
+ return r;
+}
+
#else
@@ -0,0 +1,12 @@
Index: src/third_party/mozjs/mozilla-release/build/moz.configure/toolchain.configure
--- src/third_party/mozjs/mozilla-release/build/moz.configure/toolchain.configure.orig
+++ src/third_party/mozjs/mozilla-release/build/moz.configure/toolchain.configure
@@ -2291,7 +2291,7 @@ set_define("_LIBCPP_HIDE_FROM_ABI", libcxx_override_vi
@depends(target, build_environment)
def visibility_flags(target, env):
if target.os != "WINNT":
- if target.kernel == "Darwin":
+ if target.kernel == 'Darwin' or target.kernel == 'OpenBSD':
return ("-fvisibility=hidden", "-fvisibility-inlines-hidden")
return (
"-I%s/system_wrappers" % os.path.join(env.dist),
@@ -0,0 +1,19 @@
Index: src/third_party/mozjs/mozilla-release/js/src/ctypes/libffi/src/dlmalloc.c
--- src/third_party/mozjs/mozilla-release/js/src/ctypes/libffi/src/dlmalloc.c.orig
+++ src/third_party/mozjs/mozilla-release/js/src/ctypes/libffi/src/dlmalloc.c
@@ -2525,7 +2525,6 @@ static int init_mparams(void) {
#if (FOOTERS && !INSECURE)
{
-#if USE_DEV_RANDOM
int fd;
unsigned char buf[sizeof(size_t)];
/* Try to use /dev/urandom, else fall back on using time */
@@ -2535,7 +2534,6 @@ static int init_mparams(void) {
close(fd);
}
else
-#endif /* USE_DEV_RANDOM */
s = (size_t)(time(0) ^ (size_t)0x55555555U);
s |= (size_t)8U; /* ensure nonzero */
@@ -0,0 +1,14 @@
Index: src/third_party/mozjs/mozilla-release/js/src/jit/ProcessExecutableMemory.h
--- src/third_party/mozjs/mozilla-release/js/src/jit/ProcessExecutableMemory.h.orig
+++ src/third_party/mozjs/mozilla-release/js/src/jit/ProcessExecutableMemory.h
@@ -14,7 +14,9 @@ namespace jit {
// Limit on the number of bytes of executable memory to prevent JIT spraying
// attacks.
-#if JS_BITS_PER_WORD == 32
+// attacks. Default datasize is 768Mb on OpenBSD, keep MaxCodeBytesPerProcess
+// low there otherwise the js engine hits ulimit quickly.
+#if JS_BITS_PER_WORD == 32 || defined(__OpenBSD__)
static const size_t MaxCodeBytesPerProcess = 140 * 1024 * 1024;
#else
// This is the largest number which satisfies various alignment static
@@ -0,0 +1,15 @@
Index: src/third_party/mozjs/mozilla-release/js/xpconnect/src/xpcpublic.h
--- src/third_party/mozjs/mozilla-release/js/xpconnect/src/xpcpublic.h.orig
+++ src/third_party/mozjs/mozilla-release/js/xpconnect/src/xpcpublic.h
@@ -909,7 +909,11 @@ struct alignas(kAutomationPageSize) ReadOnlyPage final
// TSan is confused by write access to read-only section.
static ReadOnlyPage sInstance;
#else
+#ifdef __OpenBSD__
+ static const volatile ReadOnlyPage sInstance __attribute__((section(".openbsd.mutable")));
+#else
static const volatile ReadOnlyPage sInstance;
+#endif
#endif
private:
@@ -0,0 +1,13 @@
Index: src/third_party/mozjs/mozilla-release/modules/fdlibm/src/math_private.h
--- src/third_party/mozjs/mozilla-release/modules/fdlibm/src/math_private.h.orig
+++ src/third_party/mozjs/mozilla-release/modules/fdlibm/src/math_private.h
@@ -30,9 +30,7 @@
* Adapted from https://github.com/freebsd/freebsd-src/search?q=__double_t
*/
-typedef double __double_t;
typedef __double_t double_t;
-typedef float __float_t;
/*
* The original fdlibm code used statements like: