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

feat(hostcallDuringLoad): Allow updating the context with InvokeContext #55

Merged
merged 2 commits into from
Sep 26, 2023
Merged
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
17 changes: 16 additions & 1 deletion engines/wazero/wazero.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading