Skip to content

[wasm] Assertion in marshal.c:399 if GetFunctionPointerForDelegate is called more than once #38573

Closed

Description

@lambdageek

Run the following code on a platform that doesn't define MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED

using System;

public delegate int MyDelegate (int i);

public class C
{
  int p;
  public C () { p = 42; }

  public int F1 (int i) => p + i;
  public int F2 (int i) => p - i;

  public static void Main()
  {
    var c = new C ();
    MyDelegate d1 = new MyDelegate (c.F1);
    MyDelegate d2 = new MyDelegate (c.F2);

    IntPtr i1 = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate (d1);
    IntPtr i2 = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate (d2);

    Console.WriteLine ($"i1 = {i1}, i2 = {i2}");
    GC.KeepAlive (c);
    GC.KeepAlive (d1);
    GC.KeepAlive (d2);
  }
    
}

Expected Output:

i1 = 12345678, i2 = 24681012

(or some other distinct arbitrary pointer values)

Actual Output:
WASM:

WASM-ERR: * Assertion at /__w/1/s/src/mono/mono/metadata/marshal.c:399, condition `<disabled>' not met

on non-WASM:

* Assertion at marshal.c:399, condition `mono_gchandle_target_equal (gchandle, MONO_HANDLE_CAST (MonoObject, d))' not met

Activity

  1. added
    untriaged
    on Jun 29, 2020
  2. lambdageek commented on Jun 29, 2020

    @lambdageek
    MemberAuthor

    One way to test this on non-wasm is to change

    #define MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED 1

    to

    #undef MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED

    And then run the above repro with mono --interp Program.exe

  3. lambdageek commented on Jun 29, 2020

    @lambdageek
    MemberAuthor

    Because on platforms without MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED the same function is returned for all calls to interp_create_method_pointer, any two arbitrary calls to GetFunctionPointerForDelegate anywhere in the program will trigger this assertion

  4. lambdageek commented on Jun 29, 2020

    @lambdageek
    MemberAuthor
  5. lateralusX commented on Jun 29, 2020

    @lateralusX
    Member

    Disabled delegate callbacks in eventpipe library on WASM due to hitting this issue, triggering:

    WASM-ERR: * Assertion at /__w/1/s/src/mono/mono/metadata/marshal.c:399, condition ' not met`

    When this is fixed on WASM we should re-enable delegate callbacks in eventpipe library src/mono/mono/metadata/icall-eventpipe.c.

  6. removed
    untriaged
    on Jun 30, 2020
  7. added this to the 5.0.0 milestone on Jun 30, 2020
  8. vargaz commented on Jul 20, 2020

    @vargaz
    Contributor

    This is fixed now by 4647328f7699a11b39297883791fcf7056906e9e.

  9. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-Interop-mono

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions