Skip to content

Commit 4f1ffaa

Browse files
committed
Simplify workaround for UnmanagedCallersOnly
1 parent 22a1295 commit 4f1ffaa

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

src/mono/sample/wasi/native/Program.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,15 @@ public static int MyExport(int number)
1717
[DllImport("*", EntryPoint = "UnmanagedFunc")]
1818
public static extern void MyImport(); // calls ManagedFunc aka MyExport
1919

20-
[DllImport("*")]
21-
public static unsafe extern void ReferenceFuncPtr(delegate* unmanaged<int,int> funcPtr);
22-
23-
static bool AlwaysFalse(string [] args) => false;
24-
2520
public unsafe static int Main(string[] args)
2621
{
2722
Console.WriteLine($"main: {args.Length}");
28-
MyImport();
29-
30-
if (AlwaysFalse(args))
31-
{
32-
// never called (would an error on wasm) and doesn't actually do anything
33-
// but required for wasm_native_to_interp_ftndesc initialization
34-
// the lookup happens before main when this is here
35-
ReferenceFuncPtr(&MyExport);
23+
// workaround to force the interpreter to initialize wasm_native_to_interp_ftndesc for MyExport
24+
if (args.Length > 10000) {
25+
((IntPtr)(delegate* unmanaged<int,int>)&MyExport).ToString();
3626
}
3727

28+
MyImport();
3829
return 0;
3930
}
4031
}

src/mono/sample/wasi/native/Wasi.Native.Sample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<WasmBuildNative>true</WasmBuildNative>
88
<WasmNativeStrip>false</WasmNativeStrip>
99
<IsBrowserWasmProject>false</IsBrowserWasmProject>
10+
<WasmSingleFileBundle>true</WasmSingleFileBundle>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/mono/sample/wasi/native/local.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,4 @@ void UnmanagedFunc()
88
printf("UnmanagedFunc calling ManagedFunc\n");
99
ret = ManagedFunc(123);
1010
printf("ManagedFunc returned %d\n", ret);
11-
}
12-
13-
14-
#ifdef PARSING_FUNCTION_POINTERS_IS_SUPPORTED
15-
/*
16-
warning WASM0001: Could not get pinvoke, or callbacks for method 'Test::ReferenceFuncPtr' because 'Parsing function pointe
17-
r types in signatures is not supported.'
18-
warning WASM0001: Skipping pinvoke 'Test::ReferenceFuncPtr' because 'Parsing function pointer types in signatures is not s
19-
upported.'
20-
*/
21-
typedef int (*ManagedFuncPtr)(int);
22-
23-
void ReferenceFuncPtr(ManagedFuncPtr funcPtr) {
24-
printf("ReferenceFuncPtr %p\n", funcPtr);
25-
}
26-
#endif
11+
}

0 commit comments

Comments
 (0)