Repository navigation
Ask only tslang's own pointer type_info for its box thunk (Linux) - #358
Merged
Merged
Conversation
An untyped `catch (e)` on Linux took every exception whose type_info is a __pointer_type_info for a tslang class, and called the box thunk it loads from a fifth field. Only tslang's _ZTIP<n><name> has that field. A C++ `throw "boom"` (`_ZTIPKc`) from a linked native library read past the end of libstdc++'s type_info and called what it found: a segfault in the __pointer_type_info vtable. The same held for any pointer to a C++ class, and for a type_info emitted before the field existed. tslang's pointer type_info now sets a bit of its own in __flags (0x40000000; libstdc++ defines only the low qualifier bits), and the catch reads the thunk field only when that bit is set. Anything else is boxed as an opaque value. A throw and its catch emit their type_infos alike, so libstdc++'s qualifier check still sees equal flags. New Linux-only test test-jit-foreign-throw-catch: a small C++ library throws a const char*, a pointer to a C++ struct and an int into untyped catches, beside a tslang class that must still box as itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
An untyped
catch (e)on Linux treated every exception whose type_info is a__pointer_type_infoas a tslang class, and called the box thunk it loads from a fifth field (#351). Only tslang's_ZTIP<n><name>has that field.A C++
throw "boom"(_ZTIPKc) from a linked native library read past the end of libstdc++'s type_info and called whatever it found there: a segfault inside the__pointer_type_infovtable, reproduced. The same applied to any pointer to a C++ class, and to a type_info emitted before the field existed.__flags(0x40000000). libstdc++ defines only the low qualifier bits. A throw and its catch emit their type_infos alike, so libstdc++'s qualifier check still sees equal flags.Verification
test-jit-foreign-throw-catch. A small C++ library (foreign-throw/foreign_throw.cpp, built by the tester's CMake) throws aconst char*, a pointer to a C++ struct and an int into untyped catches. Beside them, a tslang class must still box as itself (instanceof). Onmainit segfaults.🤖 Generated with Claude Code