Skip to content

Commit

Permalink
feat(syswall): Adding syswall, rand and time capability to wazero
Browse files Browse the repository at this point in the history
  • Loading branch information
ritesh089 committed Sep 29, 2023
1 parent 70a4115 commit e8f054d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion engines/wazero/wazero.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wazero

import (
"context"
"crypto/rand"
"errors"
"fmt"
"sync/atomic"
Expand Down Expand Up @@ -124,14 +125,16 @@ 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)
}
if config.Stderr != nil {
m.config = m.config.WithStderr(config.Stderr)
}
m.config = m.config.WithRandSource(rand.Reader).WithSysNanosleep().WithSysNanotime().WithSysWalltime()

mod = m

if _, err = instantiateWapcHost(ctx, r, m.wapcHostCallHandler, config.Logger); err != nil {
Expand Down Expand Up @@ -371,6 +374,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 e8f054d

Please sign in to comment.