diff --git a/src/mono/sample/wasi/native/Program.cs b/src/mono/sample/wasi/native/Program.cs index 83af951acf253..cb2fd0f36caf5 100644 --- a/src/mono/sample/wasi/native/Program.cs +++ b/src/mono/sample/wasi/native/Program.cs @@ -17,24 +17,15 @@ public static int MyExport(int number) [DllImport("*", EntryPoint = "UnmanagedFunc")] public static extern void MyImport(); // calls ManagedFunc aka MyExport - [DllImport("*")] - public static unsafe extern void ReferenceFuncPtr(delegate* unmanaged funcPtr); - - static bool AlwaysFalse(string [] args) => false; - public unsafe static int Main(string[] args) { Console.WriteLine($"main: {args.Length}"); - MyImport(); - - if (AlwaysFalse(args)) - { - // never called (would an error on wasm) and doesn't actually do anything - // but required for wasm_native_to_interp_ftndesc initialization - // the lookup happens before main when this is here - ReferenceFuncPtr(&MyExport); + // workaround to force the interpreter to initialize wasm_native_to_interp_ftndesc for MyExport + if (args.Length > 10000) { + ((IntPtr)(delegate* unmanaged)&MyExport).ToString(); } + MyImport(); return 0; } } diff --git a/src/mono/sample/wasi/native/Wasi.Native.Sample.csproj b/src/mono/sample/wasi/native/Wasi.Native.Sample.csproj index f19036a441d07..9af9d62eeee98 100644 --- a/src/mono/sample/wasi/native/Wasi.Native.Sample.csproj +++ b/src/mono/sample/wasi/native/Wasi.Native.Sample.csproj @@ -7,6 +7,7 @@ true false false + true diff --git a/src/mono/sample/wasi/native/local.c b/src/mono/sample/wasi/native/local.c index 29387fdf9e4b1..9141571f949be 100644 --- a/src/mono/sample/wasi/native/local.c +++ b/src/mono/sample/wasi/native/local.c @@ -8,19 +8,4 @@ void UnmanagedFunc() printf("UnmanagedFunc calling ManagedFunc\n"); ret = ManagedFunc(123); printf("ManagedFunc returned %d\n", ret); -} - - -#ifdef PARSING_FUNCTION_POINTERS_IS_SUPPORTED -/* - warning WASM0001: Could not get pinvoke, or callbacks for method 'Test::ReferenceFuncPtr' because 'Parsing function pointe -r types in signatures is not supported.' -warning WASM0001: Skipping pinvoke 'Test::ReferenceFuncPtr' because 'Parsing function pointer types in signatures is not s -upported.' -*/ -typedef int (*ManagedFuncPtr)(int); - -void ReferenceFuncPtr(ManagedFuncPtr funcPtr) { - printf("ReferenceFuncPtr %p\n", funcPtr); -} -#endif \ No newline at end of file +} \ No newline at end of file