this is definitely wrong

This commit is contained in:
Alistair Smith
2026-02-13 18:49:10 -08:00
parent 4a9c54d03b
commit b20003779f

View File

@@ -13,9 +13,6 @@
#include "BunInjectedScriptHost.h"
#include <JavaScriptCore/JSGlobalObjectInspectorController.h>
#include <sys/mman.h>
#include <unistd.h>
#include <JavaScriptCore/JSCConfig.h>
#include "InspectorLifecycleAgent.h"
#include "InspectorTestReporterAgent.h"
#include "InspectorBunFrontendDevServerAgent.h"
@@ -1009,24 +1006,7 @@ extern "C" void VM__cancelStop(JSC::VM* vm)
// Called from Zig and from the STW callback when the inspector activates.
// Sets runtimeInspectorActivated so that connect() and
// interruptForMessageDelivery() use STW-based message delivery.
// Also enables usePollingTraps for 100% reliable trap delivery in DFG/FTL.
// Since JSC::Options are mprotected read-only after init, we temporarily
// unprotect the config page, write, and re-protect.
extern "C" void Bun__activateRuntimeInspectorMode()
{
Bun::runtimeInspectorActivated.store(true);
// Enable polling traps so NeedDebuggerBreak is checked at every loop
// back-edge in DFG/FTL code. Without this, while(true){} can only be
// interrupted by signal-based traps (~94% reliable per attempt).
auto& options = g_jscConfig.options;
if (!options.usePollingTraps) {
// The config page is frozen (mprotect PROT_READ). Temporarily make it writable.
size_t pageSize = sysconf(_SC_PAGESIZE);
void* pageBase = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(&options) & ~(pageSize - 1));
size_t protectSize = (reinterpret_cast<uintptr_t>(&options) + sizeof(options) - reinterpret_cast<uintptr_t>(pageBase) + pageSize - 1) & ~(pageSize - 1);
mprotect(pageBase, protectSize, PROT_READ | PROT_WRITE);
options.usePollingTraps = true;
mprotect(pageBase, protectSize, PROT_READ);
}
}