Cast IMPs to the correct signature before calling - #418
Open
HendrikHuebner wants to merge 1 commit into
Open
Conversation
Comment on lines
+253
to
+258
| typedef id (*NewAutoreleasePoolIMP)(id, SEL); | ||
| typedef void (*DeleteAutoreleasePoolIMP)(id, SEL); | ||
| typedef void (*AutoreleaseAddIMP)(id, SEL, id); | ||
| static NewAutoreleasePoolIMP NewAutoreleasePool; | ||
| static DeleteAutoreleasePoolIMP DeleteAutoreleasePool; | ||
| static AutoreleaseAddIMP AutoreleaseAdd; |
Member
There was a problem hiding this comment.
How about something like this:
Suggested change
| typedef id (*NewAutoreleasePoolIMP)(id, SEL); | |
| typedef void (*DeleteAutoreleasePoolIMP)(id, SEL); | |
| typedef void (*AutoreleaseAddIMP)(id, SEL, id); | |
| static NewAutoreleasePoolIMP NewAutoreleasePool; | |
| static DeleteAutoreleasePoolIMP DeleteAutoreleasePool; | |
| static AutoreleaseAddIMP AutoreleaseAdd; | |
| template<typename Return, typename... Arguments> | |
| using Selector = Return(*)(id, SEL, Arguments...); | |
| static Selector<id> NewAutoreleasePool; | |
| static Selector<void> DeleteAutoreleasePoolIMP DeleteAutoreleasePool; | |
| static Selector<void, id> AutoreleaseAdd; |
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);
};| @@ -46,7 +49,8 @@ PRIVATE void call_cxx_destruct(id obj) | |||
| 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.
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.