Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure mono is only initialized once #22

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Extism.Pdk.MSBuild/FFIGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,8 @@
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
Expand Down Expand Up @@ -270,7 +264,7 @@

public class FileEntry
{
public string Name { get; set; }

Check warning on line 267 in src/Extism.Pdk.MSBuild/FFIGenerator.cs

View workflow job for this annotation

GitHub Actions / Test .NET PDK (ubuntu-latest, stable)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 267 in src/Extism.Pdk.MSBuild/FFIGenerator.cs

View workflow job for this annotation

GitHub Actions / Test .NET PDK (ubuntu-latest, stable)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string Content { get; set; }

Check warning on line 268 in src/Extism.Pdk.MSBuild/FFIGenerator.cs

View workflow job for this annotation

GitHub Actions / Test .NET PDK (ubuntu-latest, stable)

Non-nullable property 'Content' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 268 in src/Extism.Pdk.MSBuild/FFIGenerator.cs

View workflow job for this annotation

GitHub Actions / Test .NET PDK (ubuntu-latest, stable)

Non-nullable property 'Content' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
}
2 changes: 1 addition & 1 deletion src/Extism.Pdk/Extism.Pdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<PackageId>Extism.Pdk</PackageId>
<Version>1.0.0-rc2</Version>
<Version>1.0.0-rc3</Version>
<Authors>Extism Contributors</Authors>
<Description>Extism PDK that allows compiling .NET apps into wasm Extism plugins.</Description>
<Tags>extism, wasm, plugin</Tags>
Expand Down
3 changes: 3 additions & 0 deletions src/Extism.Pdk/build/Extism.Pdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<!-- Wrap mono_runtime_run_main because we have to make sure at least one argument is passed in to Mono -->
<!-- See native/env.c for the implementation -->
<_WasiSdkClangArgs Include="-Wl,--wrap=mono_runtime_run_main" />

<!-- Wrap mono_wasm_load_runtime to ensure mono is loaded only once when _start is called after an exported function -->
<_WasiSdkClangArgs Include="-Wl,--wrap=mono_wasm_load_runtime" />
</ItemGroup>
</Target>
</Project>
13 changes: 13 additions & 0 deletions src/Extism.Pdk/native/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 0 additions & 6 deletions tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading