Repository navigation
[fix] Fix the extern early return in HXTAllocation - #1419
Open
dimensionscape wants to merge 1 commit into
Open
dimensionscape wants to merge 1 commit into
dimensionscape wants to merge 1 commit into
Conversation
HXTAllocation skips allocations made inside a CFFI call, but before returning it unlocked alloc_mutex, which it has not locked yet (the lock is taken a few lines further down). Unlocking a mutex the thread does not own is undefined behaviour. On Windows it leaves the mutex held, and the next thread that tracks an allocation or stashes blocks forever. The same check also read getCurrentStackFrame(), which is mStackFrames.back() and undefined while no frame is on the stack. Drop the stray unlock and check the stack depth first. The new telemetry test allocates inside an extern frame on one thread, then stashes on another; without the fix it deadlocks on Windows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HXTAllocation skips allocations made inside a CFFI call (an extern stack frame), but before returning it calls alloc_mutex.unlock() on a mutex it hasn’t locked yet; the lock is taken a few lines later. Unlocking a mutex the thread doesn’t own is undefined behaviour. On Windows it leaves alloc_mutex held, so the next thread that tracks an allocation or stashes telemetry blocks forever. The bug dates back to the original telemetry merge (2015); #1298 only changed Unlock() to unlock().
The same check also calls getCurrentStackFrame(), which is mStackFrames.back() and undefined when no frame is on the stack.
This PR drops the stray unlock and checks the stack depth first. Builds with HXCPP_PROFILE_EXTERNS are unaffected.
Test: test/telemetry/TestAllocations.hx allocates inside an extern frame on one thread (the same frame cpp.Lib.load primitives push), then stashes on another. Without the fix the telemetry tests deadlock on Windows; with it they pass in release and debug.