diff --git a/engines/wazero/wazero.go b/engines/wazero/wazero.go index 7b9dd72..9d45da2 100644 --- a/engines/wazero/wazero.go +++ b/engines/wazero/wazero.go @@ -124,7 +124,7 @@ func (e *engine) New(ctx context.Context, host wapc.HostCallHandler, guest []byt m := &Module{runtime: r, wapcHostCallHandler: host} m.config = wazero.NewModuleConfig(). - WithStartFunctions(functionStart, functionInit) // Call any WASI or waPC start functions on instantiate. + WithStartFunctions() // Manually call _start and _init if config.Stdout != nil { m.config = m.config.WithStdout(config.Stdout) @@ -371,6 +371,21 @@ func (m *Module) Instantiate(ctx context.Context) (wapc.Instance, error) { return nil, err } + // Call any WASI or waPC start functions on instantiate. + funcs := []string{functionStart, functionInit} + for _, f := range funcs { + exportedFunc := module.ExportedFunction(f) + if exportedFunc != nil { + ic := invokeContext{operation: f, guestReq: nil} + ictx := newInvokeContext(ctx, &ic) + if _, err := exportedFunc.Call(ictx); err != nil { + module.Close(ctx) + + return nil, fmt.Errorf("error calling %s: %v", f, err) + } + } + } + instance := Instance{name: moduleName, m: module} if instance.guestCall = module.ExportedFunction(functionGuestCall); instance.guestCall == nil {