Skip to content

[Mono] Implement support for CallConvSuppressGCTransition #46451

Closed
mono/mono
#20746

Description

@lambdageek

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.

Activity

  1. added this to the 6.0.0 milestone on Dec 29, 2020
  2. added
    untriaged
    on Dec 29, 2020
  3. lambdageek commented on Dec 29, 2020

    @lambdageek
    MemberAuthor

    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

  4. ghost added
    in-pr
    on Jan 14, 2021
  5. added a commit that references this issue on Jan 14, 2021
    6aeac6a
  6. added 2 commits that reference this issue on Jan 15, 2021
    722addc
    a3b37a2
  7. ghost removed
    in-pr
    on Jan 15, 2021
  8. ghost locked as resolved and limited conversation to collaborators on Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Interop-monountriaged

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions