Assert GCRuntime::enter/leaveUnsafe region is main-thread only

This commit is contained in:
Amelia Hart 2026-07-27 17:59:06 +02:00 committed by wuggy
commit fc206f5ab1
3 changed files with 8 additions and 6 deletions

View file

@ -54,8 +54,6 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
// activation (if any) comes around.
void* savedPrevJitTop_;
JS::AutoCheckCannotGC nogc_;
static const unsigned StorageSpace = 8 * sizeof(void*);
mozilla::AlignedStorage<StorageSpace> storage_;
js::wasm::ProfilingFrameIterator& wasmIter() {
@ -139,7 +137,7 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
void iteratorConstruct();
void iteratorDestroy();
bool iteratorDone();
};
} JS_HAZ_GC_INVALIDATED;
JS_FRIEND_API(bool)
IsProfilingEnabledForContext(JSContext* cx);

View file

@ -714,13 +714,18 @@ class GCRuntime
#endif // DEBUG
bool isInsideUnsafeRegion() { return inUnsafeRegion != 0; }
void enterUnsafeRegion() { ++inUnsafeRegion; }
void enterUnsafeRegion() {
MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt));
++inUnsafeRegion;
}
void leaveUnsafeRegion() {
MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt));
MOZ_ASSERT(inUnsafeRegion > 0);
--inUnsafeRegion;
}
void verifyIsSafeToGC() {
MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt));
MOZ_DIAGNOSTIC_ASSERT(!isInsideUnsafeRegion(),
"[AutoAssertNoGC] possible GC in GC-unsafe region");
}

View file

@ -1739,8 +1739,7 @@ JS::ProfilingFrameIterator::ProfilingFrameIterator(JSContext* cx, const Register
: rt_(cx),
sampleBufferGen_(sampleBufferGen),
activation_(nullptr),
savedPrevJitTop_(nullptr),
nogc_(cx)
savedPrevJitTop_(nullptr)
{
if (!cx->spsProfiler.enabled())
MOZ_CRASH("ProfilingFrameIterator called when spsProfiler not enabled for runtime.");