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

[mono] Make some icalls pass/return object references using ObjectHandleOnStack/QCallTypeHandle #62141

Merged
merged 17 commits into from
Jan 6, 2022

Conversation

vargaz
Copy link
Contributor

@vargaz vargaz commented Nov 29, 2021

…tack argument.

@ghost
Copy link

ghost commented Nov 29, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

…tack argument.

Author: vargaz
Assignees: -
Labels:

area-VM-meta-mono

Milestone: -

@vargaz
Copy link
Contributor Author

vargaz commented Dec 1, 2021

The wasm failures are relevant.

@vargaz vargaz force-pushed the qcalls branch 2 times, most recently from 548a3a2 to 87a6f09 Compare December 6, 2021 17:17
@vargaz
Copy link
Contributor Author

vargaz commented Dec 6, 2021

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Dec 6, 2021

The wasm failures are probably becaue ObjectHandleOnStack is a structure and its passed incorrectly as an argument to icalls on wasm.

@vargaz
Copy link
Contributor Author

vargaz commented Dec 20, 2021

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek
Copy link
Member

Pass ObjectHandleOnStack by ref, valuetypes cannot be passed to icalls on mono.

@vargaz I don't think this PR is worth it if we can't use the exact same managed declarations and callers that coreclr do.

We may need to teach our marshalling code that ObjectHandleOnStack is just an IntPtr

For example:

[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "TypeName_GetModifiers")]
private static partial void _GetModifiers(SafeTypeNameParserHandle pTypeNameParser, ObjectHandleOnStack retArray);

_GetModifiers(m_NativeParser, ObjectHandleOnStack.Create(ref modifiers));

@vargaz
Copy link
Contributor Author

vargaz commented Dec 21, 2021

Some of the types passed are more complicated, QCallTypeReference is a struct with 2 fields for example.

@lambdageek
Copy link
Member

lambdageek commented Dec 22, 2021

Some of the types passed are more complicated, QCallTypeReference is a struct with 2 fields for example.

I think I'm wrong: there's nothing special for marshaling. All these types are represented as blittable structs and are just passed using the normal ABI calling convention.


But also, QCalls are PInvokes, not icalls.
So (later, in other PRs) when we go to unify the managed side with CoreCLR, we will also need to tweak the native side: get the declarations out of icall-decl, into the QCall tables, and change the implementations to use MONO_ENTER_GC_UNSAFE/MONO_EXIT_GC_UNSAFE before they call into runtime internals.

@lambdageek
Copy link
Member

Is this the reference for the wasm32 ABI that Emscripten uses? https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md#function-calling-sequence

@vargaz
Copy link
Contributor Author

vargaz commented Dec 22, 2021

Yes, there was an issue passing scalar structs on wasm both in AOT and the interpreter, which is also fixed by this PR.

@vargaz
Copy link
Contributor Author

vargaz commented Jan 4, 2022

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Jan 5, 2022

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Jan 5, 2022

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Jan 6, 2022

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Jan 6, 2022

Failures are unrelated

@vargaz vargaz merged commit 01cc900 into dotnet:main Jan 6, 2022
@vargaz vargaz deleted the qcalls branch January 6, 2022 22:16
@ghost ghost locked as resolved and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants