rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.84k stars 12.66k forks source link

Reset rustc's scoped TLS state during unwinding. #47201

Open eddyb opened 6 years ago

eddyb commented 6 years ago

This should only happen in the event of an ICE, but right now, if a Drop implementation (for e.g. a field in Session) would try to access, say, the TLS_TCX, it would use-after-free the global TyCtxt.

joshlf commented 6 years ago

Isn't this disallowed by the LocalKey requirement that a key's "initializer cannot recursively depend on itself"? To be fair, that wording was only added to the documentation recently.

eddyb commented 6 years ago

@joshlf We use thread_local to hold a raw pointer in a Cell in order to do scoped TLS, the actual usage of LocalKey itself is trivial, it's what we do with the pointer that matters.