From 776fdd239f690ed4d9edb2b3ce9b7a9180d5b2a0 Mon Sep 17 00:00:00 2001 From: Muhammad Azeez Date: Mon, 16 Oct 2023 08:29:55 +0300 Subject: [PATCH 1/3] fix: ensure mono is only initialized once --- src/Extism.Pdk.MSBuild/FFIGenerator.cs | 6 ------ src/Extism.Pdk/build/Extism.Pdk.targets | 3 +++ src/Extism.Pdk/native/env.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Extism.Pdk.MSBuild/FFIGenerator.cs b/src/Extism.Pdk.MSBuild/FFIGenerator.cs index 43427bb..90e472f 100644 --- a/src/Extism.Pdk.MSBuild/FFIGenerator.cs +++ b/src/Extism.Pdk.MSBuild/FFIGenerator.cs @@ -97,14 +97,8 @@ private FileEntry GenerateExports(string assemblyFileName, MethodDefinition[] ex WASI_AFTER_RUNTIME_LOADED_DECLARATIONS #endif - bool mono_runtime_initialized = false; void initialize_runtime() { - if (mono_runtime_initialized) { - return; - } - mono_wasm_load_runtime("", 0); - mono_runtime_initialized = true; } // end of _initialize diff --git a/src/Extism.Pdk/build/Extism.Pdk.targets b/src/Extism.Pdk/build/Extism.Pdk.targets index 1bd1a6d..41a1610 100644 --- a/src/Extism.Pdk/build/Extism.Pdk.targets +++ b/src/Extism.Pdk/build/Extism.Pdk.targets @@ -9,6 +9,9 @@ <_WasiSdkClangArgs Include="-Wl,--wrap=mono_runtime_run_main" /> + + + <_WasiSdkClangArgs Include="-Wl,--wrap=mono_wasm_load_runtime" /> \ No newline at end of file diff --git a/src/Extism.Pdk/native/env.c b/src/Extism.Pdk/native/env.c index 1832de2..6658442 100644 --- a/src/Extism.Pdk/native/env.c +++ b/src/Extism.Pdk/native/env.c @@ -232,4 +232,17 @@ int __wrap_mono_runtime_run_main(MonoMethod *method, int argc, char *argv[], Mon } return __real_mono_runtime_run_main(method, argc, argv, exc); +} + +// Wrap mono_wasm_load_runtime to make sure we don't initialize mono more than once +void __real_mono_wasm_load_runtime(const char* unused, int debug_level); + +bool mono_runtime_initialized = false; +void __wrap_mono_wasm_load_runtime(const char* unused, int debug_level) { + if (mono_runtime_initialized) { + return; + } + + __real_mono_wasm_load_runtime(unused, debug_level); + mono_runtime_initialized = true; } \ No newline at end of file From 779a7efcb9a96cf43927ef0cb1ddeaec24737ae4 Mon Sep 17 00:00:00 2001 From: Muhammad Azeez Date: Mon, 16 Oct 2023 08:41:11 +0300 Subject: [PATCH 2/3] upate version to rc3 --- src/Extism.Pdk/Extism.Pdk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extism.Pdk/Extism.Pdk.csproj b/src/Extism.Pdk/Extism.Pdk.csproj index ad8db5e..b36dd18 100644 --- a/src/Extism.Pdk/Extism.Pdk.csproj +++ b/src/Extism.Pdk/Extism.Pdk.csproj @@ -14,7 +14,7 @@ Extism.Pdk - 1.0.0-rc2 + 1.0.0-rc3 Extism Contributors Extism PDK that allows compiling .NET apps into wasm Extism plugins. extism, wasm, plugin From 386b1f9d929c39f5dbe1ef7e5d0f5b127a676376 Mon Sep 17 00:00:00 2001 From: Muhammad Azeez Date: Mon, 16 Oct 2023 08:42:53 +0300 Subject: [PATCH 3/3] fix tests --- tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt b/tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt index f24fe41..2b1cb01 100644 --- a/tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt +++ b/tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt @@ -24,14 +24,8 @@ void mono_wasm_load_runtime(const char* unused, int debug_level); WASI_AFTER_RUNTIME_LOADED_DECLARATIONS #endif -bool mono_runtime_initialized = false; void initialize_runtime() { - if (mono_runtime_initialized) { - return; - } - mono_wasm_load_runtime("", 0); - mono_runtime_initialized = true; } // end of _initialize