diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index ffc360eaad..52ad8f6c43 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -918,6 +918,8 @@ void Zig::GlobalObject::resetOnEachMicrotaskTick() } } +extern "C" size_t Bun__reported_memory_size; + // executionContextId: -1 for main thread // executionContextId: maxInt32 for macros // executionContextId: >-1 for workers @@ -953,6 +955,12 @@ extern "C" JSC::JSGlobalObject* Zig__GlobalObject__create(void* console_client, if (shouldDisableStopIfNecessaryTimer) { vm.heap.disableStopIfNecessaryTimer(); } + + // This is used to tell us in the crash reporter how much RSS the system has. + // + // JSC already calls this inside JSC::VM::tryCreate and it's cached + // internally, so there's little cost to calling this multiple times. + Bun__reported_memory_size = WTF::ramSize(); } // Every JS VM's RunLoop should use Bun's RunLoop implementation diff --git a/src/bun.js/bindings/workaround-missing-symbols.cpp b/src/bun.js/bindings/workaround-missing-symbols.cpp index 988529cda5..928db9754f 100644 --- a/src/bun.js/bindings/workaround-missing-symbols.cpp +++ b/src/bun.js/bindings/workaround-missing-symbols.cpp @@ -242,7 +242,39 @@ extern "C" __attribute__((used)) char __libc_single_threaded = 0; #include #include "headers.h" -void std::__libcpp_verbose_abort(char const* format, ...) +// Check if the stdlib declaration already has noexcept by looking at the header +#ifdef _LIBCPP___VERBOSE_ABORT +#if __has_include(<__verbose_abort>) +#include <__verbose_abort> +#endif +#endif + +#ifdef _LIBCPP_VERBOSE_ABORT_NOEXCEPT +// Workaround for this error: +// workaround-missing-symbols.cpp:245:11: error: '__libcpp_verbose_abort' is missing exception specification 'noexcept' +// 2025-07-10 15:59:47 PDT +// 245 | void std::__libcpp_verbose_abort(char const* format, ...) +// 2025-07-10 15:59:47 PDT +// | ^ +// 2025-07-10 15:59:47 PDT +// | noexcept +// 2025-07-10 15:59:47 PDT +// /opt/homebrew/Cellar/llvm/20.1.7/bin/../include/c++/v1/__verbose_abort:30:28: note: previous declaration is here +// 2025-07-10 15:59:47 PDT +// 30 | __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT; +// 2025-07-10 15:59:47 PDT +// | ^ +// 2025-07-10 15:59:47 PDT +// 1 error generated. +// 2025-07-10 15:59:47 PDT +// [515/540] Building CXX +#define BUN_VERBOSE_ABORT_NOEXCEPT _LIBCPP_VERBOSE_ABORT_NOEXCEPT +#else +#define BUN_VERBOSE_ABORT_NOEXCEPT +#endif + +// Provide our implementation +void std::__libcpp_verbose_abort(char const* format, ...) BUN_VERBOSE_ABORT_NOEXCEPT { va_list list; va_start(list, format); @@ -253,6 +285,8 @@ void std::__libcpp_verbose_abort(char const* format, ...) Bun__panic(buffer, len); } +#undef BUN_VERBOSE_ABORT_NOEXCEPT + #endif #ifndef U_SHOW_CPLUSPLUS_API diff --git a/src/crash_handler.zig b/src/crash_handler.zig index 78f7595d2c..a90b93871f 100644 --- a/src/crash_handler.zig +++ b/src/crash_handler.zig @@ -907,6 +907,9 @@ pub fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows extern "c" fn gnu_get_libc_version() ?[*:0]const u8; +// Only populated after JSC::VM::tryCreate +export var Bun__reported_memory_size: usize = 0; + pub fn printMetadata(writer: anytype) !void { if (Output.enable_ansi_colors) { try writer.writeAll(Output.prettyFmt("", true)); @@ -981,12 +984,19 @@ pub fn printMetadata(writer: anytype) !void { user_msecs, system_msecs, }); - try writer.print("RSS: {:<3.2} | Peak: {:<3.2} | Commit: {:<3.2} | Faults: {d}\n", .{ + + try writer.print("RSS: {:<3.2} | Peak: {:<3.2} | Commit: {:<3.2} | Faults: {d}", .{ std.fmt.fmtIntSizeDec(current_rss), std.fmt.fmtIntSizeDec(peak_rss), std.fmt.fmtIntSizeDec(current_commit), page_faults, }); + + if (Bun__reported_memory_size > 0) { + try writer.print(" | Machine: {:<3.2}", .{std.fmt.fmtIntSizeDec(Bun__reported_memory_size)}); + } + + try writer.writeAll("\n"); } if (Output.enable_ansi_colors) {