Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use rb_current_ec_noinline in assertions #13217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Apr 30, 2025

When doing a coroutine transfer from one thread to another, there's a risk that the compiler will reuse an address from TLS before the transfer to the new thread.

These VM assertions are all in places we would not otherwise be reading from TLS, but using the value of ec or cr passed in. Switching these to test against rb_current_ec_noinline() instead ensures there isn't an optimization applied to how we read ruby_current_ec.

Currently it seems we were hitting this on LLVM 18 specifically, but I don't know of any reason other versions wouldn't have the same issue.

cc @ko1

When doing a coroutine transfer from one thread to another, there's a
risk that the compiler will reuse an address from TLS before the
transfer to the new thread.

These VM assertions are all in places we would not otherwise be reading
from TLS, but using the value of `ec` or `cr` passed in. Switching these
to test against rb_current_ec_noinline() instead ensures there isn't an
optimization applied to how we read ruby_current_ec.

Currently it seems we were hitting this on LLVM 18 specifically, but I
don't know of any reason other versions wouldn't have the same issue.
Copy link

All Tests passed!

✖️no tests failed ✔️61957 tests passed(1 flake)

@jhawthorn jhawthorn enabled auto-merge (rebase) April 30, 2025 22:08
@jhawthorn jhawthorn merged commit 7866e12 into ruby:master Apr 30, 2025
86 checks passed
@samuel-williams-shopify
Copy link

samuel-williams-shopify commented May 2, 2025

I think it would be a good idea to add documentation explaining the issue adjacent to the code, as it may be non-obvious why the inline variant is used, and as there are no tests, nothing is preventing future regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants