experimental: adds close notification hook (#1574)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-07-11 09:27:43 +08:00
committed by GitHub
parent 326c267726
commit 0300f4b3c1
10 changed files with 201 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/tetratelabs/wazero/api"
experimentalapi "github.com/tetratelabs/wazero/experimental"
internalclose "github.com/tetratelabs/wazero/internal/close"
internalsock "github.com/tetratelabs/wazero/internal/sock"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/wasm"
@@ -292,8 +293,7 @@ func (r *runtime) InstantiateModule(
code := compiled.(*compiledModule)
config := mConfig.(*moduleConfig)
// Only build listeners on a guest module. A host module doesn't have
// memory, and a guest without memory can't use listeners anyway.
// Only add guest module configuration to guests.
if !code.module.IsHostModule {
if sockConfig, ok := ctx.Value(internalsock.ConfigKey{}).(*internalsock.Config); ok {
config.sockConfig = sockConfig
@@ -320,6 +320,10 @@ func (r *runtime) InstantiateModule(
return
}
if closeNotifier, ok := ctx.Value(internalclose.NotifierKey{}).(internalclose.Notifier); ok {
mod.(*wasm.ModuleInstance).CloseNotifier = closeNotifier
}
// Attach the code closer so that anything afterward closes the compiled
// code when closing the module.
if code.closeWithModule {