dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.

Home Page:http://dot.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wasm: runtime failure for NotifyCollectionChangedEventArgs

yowl opened this issue · comments

commented

The following code:

        var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new string[] { "1" });
        if (e.NewItems != null) 
        {
            foreach (string newItems in e.NewItems)
            {
            }
        }

Causes the runtime exception

exception thrown: RuntimeError: function signature mismatch,RuntimeError: function signature mismatch
    at S_P_CoreLib_System_Runtime_CalliIntrinsics__Call<IntPtr> (wasm-function[801]:0x75e1b)
    at S_P_CoreLib_Internal_Runtime_EEType__GetArrayEEType (wasm-function[381]:0x2a027)
    at S_P_CoreLib_System_Runtime_DispatchResolve__FindInterfaceMethodImplementationTarget (wasm-function[373]:0x292eb)
    at System_ObjectModel_System_Collections_Specialized_ReadOnlyList__GetEnumerator (wasm-function[2668]:0x1af87d)
    at HelloWasm_Program__Main (wasm-function[496]:0x3e4f5)
    at HelloWasm__Module___MainMethodWrapper (wasm-function[479]:0x36aa9)
    at StartupCodeMain (wasm-function[469]:0x364dc)
    at __managed__Main (wasm-function[20456]:0xf91e44)
    at main (wasm-function[22390]:0x10d38c7)
    at E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:1969:22
commented

Not really sure how to fix this

        [RuntimeExport("GetSystemArrayEEType")]
        private static unsafe EEType* GetSystemArrayEEType()

The RuntimeExport function pointer is the one that ends up in main.cpp which does not get the wasm shadow stack arg:

static const pfn c_classlibFunctions[] = {
    &GetRuntimeException,
    &FailFast,
    nullptr, // &UnhandledExceptionHandler,
    &AppendExceptionStackFrame,
    nullptr, // &CheckStaticClassConstruction,
    &GetSystemArrayEEType,

But its called from managed IL through the CallIIntrinsic which wants to inject the shadow stack argument and hence there is a mismatch.

commented

What I do see is some provision here in CalliIntrinsic

            if (target.Name == "StdCall")
                flags |= MethodSignatureFlags.UnmanagedCallingConventionStdCall;

But maybe that's for something else as that flag is not set for EEType.GetArrayEEType

What I do see is some provision here in CalliIntrinsic

Yes, that's for something else.

One way to fix this would be to inline GetSystemArrayEEType in EEType to avoid the problematic indirection.

internal EEType* GetArrayEEType()
{
#if INPLACE_RUNTIME
   return EETypePtr.EETypePtrOf<Array>().ToPointer();
#else
   ... existing impl...
#endif
}
commented

Thanks!, that fixes it