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] Implement support for CallConvSuppressGCTransition #46451

Closed
lambdageek opened this issue Dec 29, 2020 · 1 comment · Fixed by #47006 or mono/mono#20746
Closed

[Mono] Implement support for CallConvSuppressGCTransition #46451

lambdageek opened this issue Dec 29, 2020 · 1 comment · Fixed by #47006 or mono/mono#20746
Labels
area-Interop-mono untriaged New issue has not been triaged by the area owner
Milestone

Comments

@lambdageek
Copy link
Member

lambdageek commented Dec 29, 2020

See #38134. The CoreCLR implementation is in #46343

This gives the ability to declare a function pointer that can be called without a GC transition.

For example:

delegate* unmanaged[Cdecl, SuppressGCTransition]<int*, int> fptr
        = (delegate* unmanaged[Cdecl, SuppressGCTransition]<int*, int>)GetNextUIntFunctionPointer();

The call to GetNextUintFunctionPointer returns a pointer to some unmanaged function. By declaring its calling convention as [Cdecl, SuppressGCTransition] (as opposed to [Cdecl]) the caller code does not need to do a managed-to-native transition when calling through fptr. All the rules of SuppressGCTransitionAttribute still apply: the native function can't block, throw exceptions, call back into the runtime, manipulate locks or other concurrency primitives, etc.


Re-enable Interop/PInvoke/Attributes/SuppressGCTransition/SuppressGCTransitionTest/ in src/tests/issues.targets once this is fixed.

@lambdageek
Copy link
Member Author

I'm not actually sure that mono today emits a GC transition for something like:

  int n;
  unsafe {
    delegate* unmanaged[Cdecl]<int*, int> fptr
        = (delegate* unmanaged[Cdecl]<int*, int>)GetNextUIntFunctionPointer();
    fptr(&n);
  }

We need to complete #38480 - the calli call for the last line in the example needs to emit a gc transition

lambdageek added a commit to lambdageek/runtime that referenced this issue Jan 14, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 14, 2021
monojenkins pushed a commit to monojenkins/mono that referenced this issue Jan 14, 2021
* Parse modopt encoded calling conventions
   Add `suppress_gc_transition` bit to `MonoMethodSignature` to add support for the `SuppressGCTransition` unmanaged calling convention modifier.

* Don't emit a wrapper on `calli` if `suppress_gc_transition` is set

   This adds support for `delegate* unmanaged[Cdecl, SuppressGCTransition] <TRet, TArgs...>` function pointers. (And other base calling conventions other than Cdecl).

* Allow blittable types in `mono_marshal_get_native_func_wrapper_indirect`

   This was already used by C++/CLI, so the C# function pointers spec allows blittable types in unmanaged function pointer types.

* Remove SuppressGCTransitionTest from exclude list

Fixes dotnet/runtime#46451
lambdageek added a commit to mono/mono that referenced this issue Jan 15, 2021
* Parse modopt encoded calling conventions
   Add `suppress_gc_transition` bit to `MonoMethodSignature` to add support for the `SuppressGCTransition` unmanaged calling convention modifier.

* Don't emit a wrapper on `calli` if `suppress_gc_transition` is set

   This adds support for `delegate* unmanaged[Cdecl, SuppressGCTransition] <TRet, TArgs...>` function pointers. (And other base calling conventions other than Cdecl).

* Allow blittable types in `mono_marshal_get_native_func_wrapper_indirect`

   This was already used by C++/CLI, so the C# function pointers spec allows blittable types in unmanaged function pointer types.

* Remove SuppressGCTransitionTest from exclude list

Fixes dotnet/runtime#46451

Co-authored-by: lambdageek <[email protected]>
lambdageek added a commit that referenced this issue Jan 15, 2021
* [metadata] Parse modopt encoded calling conventions

Add suppress_gc_transition bit to MonoMethodSignature to add support for
the SuppressGCTransition unmanaged calling convention modifier.

* [mini] Don't emit a wrapper on calli if suppress_gc_transition is set

This adds support for `delegate* unmanaged[Cdecl, SuppressGCTransition] <TRet,
TArgs...>` function pointers.
(And other base calling conventions other than Cdecl).

* [marshal] Allow blittable types in mono_marshal_get_native_func_wrapper_indirect

This was already used by C++/CLI, so the C# function pointers spec allows blittable types in
unmanaged function pointer types.

* [tests] Remove SuppressGCTransitionTest from exclude list

Fixes #46451
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 15, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Feb 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Interop-mono untriaged New issue has not been triaged by the area owner
Projects
None yet
2 participants