Skip to content
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

Add UnmanagedCallersOnly attribute to SafeDeleteSslContext.ReadFromConnection/WriteToConnection methods #55947

Merged
merged 8 commits into from
Aug 17, 2021

Conversation

MaximLipnin
Copy link
Contributor

@MaximLipnin MaximLipnin commented Jul 19, 2021

Fixes #55736

@ghost
Copy link

ghost commented Jul 19, 2021

Tagging subscribers to this area: @dotnet/ncl, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

#55736

It doesn't work yet and needs any feedback about the correctness of approach.

Author: MaximLipnin
Assignees: -
Labels:

area-System.Net.Security

Milestone: -

@mdh1418
Copy link
Member

mdh1418 commented Jul 19, 2021

I'm not very familiar, but based on what @lambdageek mentioned #55736 (comment), UnmanagedCallersOnlyAttribute the changes seem like the right path. Are void* and void** blittable?

Perhaps once Argument 2: cannot convert from '&method group' to 'delegate* unmanaged<void*, byte*, void**>' and An object reference is required for the non-static field, method, or property 'SafeDeleteSslContext._outputBuffer' are resolved we'll know more?

@jkotas
Copy link
Member

jkotas commented Jul 19, 2021

An object reference is required for the non-static field, method, or property 'SafeDeleteSslContext._outputBuffer

You will need to have some way to go from the call arguments back to the object. Do these APIs have a way to pass pointer to user data around? If not, you will need to pass the extra data around using some sort of global state, e.g. Dictionary that uses connection pointer as the key.

@lambdageek
Copy link
Member

In theory that void* connection is the user data. You have to call https://developer.apple.com/documentation/security/1398843-sslsetconnection to assign a connection value to an SSLContext (somewhere before

osStatus = Interop.AppleCrypto.SslSetIoCallbacks(
_sslContext,
&ReadFromConnection,
&WriteToConnection);
) and then the Apple API will pass it back to the read and write callbacks.

We could probably just put a GCHandle to this SafeDeleteSslContext into the connection value. No need for a dictionary.

…SslContext instance is associated to an ssl session
@steveisok
Copy link
Member

@MaximLipnin I put up a commit that should help. Please validate.

Thanks for the tips everyone.

Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@steveisok steveisok marked this pull request as ready for review August 16, 2021 03:05
@steveisok
Copy link
Member

@MaximLipnin You might want to merge w/ main b/c it'll resolve a bunch of test failures on iOS.

@karelz karelz added the runtime-mono specific to the Mono runtime label Aug 17, 2021
@akoeplinger akoeplinger merged commit fb9dac8 into dotnet:main Aug 17, 2021
@MaximLipnin MaximLipnin deleted the add_pinvoke_callback_attr branch August 18, 2021 06:09
@karelz karelz added this to the 6.0.0 milestone Aug 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Security runtime-mono specific to the Mono runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mono: AOT compiler can't compile System.Net.SafeDeleteSslContext:ReadFromConnection (Mac Catalyst)
7 participants