Cast IMPs to the correct signature before calling - #418
Open
HendrikHuebner wants to merge 1 commit into
Open
Conversation
Comment on lines
+572
to
+574
| NewAutoreleasePool = reinterpret_cast<NewAutoreleasePoolIMP>( | ||
| class_getMethodImplementation(object_getClass(AutoreleasePool), | ||
| SELECTOR(new))); |
Member
There was a problem hiding this comment.
Can we consolidate the casts with something like:
auto storeSelector = [](auto &target, IMP imp)
{
target = reinterpret_cast<std::remove_reference_t<decltype(target)>>(imp);
};| // `.cxx_destruct` method may deallocate the class. | ||
| Class currentClass = cls; | ||
| cls = cls->super_class; | ||
| if (currentClass->cxx_destruct) |
Member
There was a problem hiding this comment.
We should probably change the type of these from IMP and do the cast when we set them.
Contributor
Author
|
updated |
davidchisnall
approved these changes
Aug 25, 2026
Member
|
Please can you squash for merging? |
HendrikHuebner
force-pushed
the
wasm-imp-signatures
branch
from
August 26, 2026 11:03
3a1c6c5 to
e5455f2
Compare
Contributor
Author
|
Done. I don't think I have permissions to merge PRs myself. |
davidchisnall
force-pushed
the
wasm-imp-signatures
branch
from
August 28, 2026 16:06
e5455f2 to
90a06b5
Compare
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.
This PR ensures we do not call any raw IMP function pointers without casting them to the correct type first.
Calling a funtion pointer with a mismatching signature is technically UB I believe but tends to work just fine on many native platforms.
With WebAssembly, this is a problem however, because WASM indirect calls require an exact signature match. This can cause runtime failures.