Skip to content

Commit

Permalink
feat(hostcallDuringLoad): Allow updating the context with InvokeConte…
Browse files Browse the repository at this point in the history
…xt (#55)

* feat(hostcallAtStart): Allow hostcalls from start

* feat(hostcallAtStart): Allow hostcalls from start

---------

Co-authored-by: rrai35 <ritesh.rai@aexp.com>
  • Loading branch information
ritesh089 and ritesh089 authored Sep 26, 2023
1 parent 70a4115 commit 83499bd
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 83499bd

Please sign in to comment.