Skip to content

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Aug 4, 2025

TailCallArgBuffer:State is 32-bit int. The code incorrectly used native int operation to set. It lead to TailCallArgBuffer::Size to be reset as well and needlessly re-allocating the tail call buffer.

Fixes #118166

@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 23:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the tail call buffer implementation where the State field was being incorrectly set using a native integer operation instead of a 32-bit integer operation, causing unintended resets of the Size field and unnecessary buffer re-allocations.

Key changes:

  • Changes EmitSTIND_I() to EmitSTIND_I4() when setting the TailCallArgBuffer state to ensure only the 32-bit State field is modified

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member Author

jkotas commented Aug 4, 2025

This should fix the stress problem hit by the CI. I have noticed that the thread in the bad state is always in the CFG probe called from free method in Debug CRT.

There is still a corner case stress bug hidden somewhere. It is likely specific to combination of WinServer 2016 w/ CFG (and potentially Debug CRT). I suspect that it may be in special casing of CFG inside SetThreadContext in the OS. It should be rare enough that we can live with it.

@jkotas jkotas requested review from VSadov and jakobbotsch August 4, 2025 23:14
TailCallArgBuffer:State is 32-bit int. The code incorrectly used native int operation to set. It lead to TailCallArgBuffer::Size to be reset as well and needlessly re-allocating the tail call buffer.

Fixes dotnet#118166
@jkotas jkotas marked this pull request as draft August 5, 2025 01:10
@jkotas
Copy link
Member Author

jkotas commented Aug 5, 2025

I have realized that we can call malloc/free in pre-emptive mode to make this even more robust, going to push an update in a bit.

…ocation

Move the fast path of the TailCallArgBuffer allocation helper to C# to avoid perf overload of switching to preemptive mode. Also, aggressively inline it to allow zero initialization to be unrolled by the JIT.
@jkotas
Copy link
Member Author

jkotas commented Aug 5, 2025

This is ready for review again

@jkotas jkotas merged commit e1fbcdc into dotnet:main Aug 5, 2025
92 checks passed
@jkotas jkotas deleted the issue-118166 branch August 5, 2025 12:23
@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT/Methodical/tailcall_v4/hijacking/hijacking test hang

2 participants