From 17eb004fdbe522a4fe5f6101b8fb5f821d4ec006 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Wed, 13 Nov 2024 23:09:36 -0500 Subject: [PATCH] Add system time to guest environment. --- proc/proc.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/proc/proc.go b/proc/proc.go index 40fb7ce..02a6bf0 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -3,10 +3,12 @@ package proc import ( "bytes" "context" + "crypto/rand" "errors" "io" "log/slog" "path" + "runtime" "strings" "capnproto.org/go/capnp/v3" @@ -35,7 +37,12 @@ func (cfg Config) Bind(ctx context.Context, p *P) (err error) { WithStdin(&p.mailbox). WithStdout(cfg.Stdout). WithStderr(cfg.Stderr). - WithEnv("WW_PROTO", proto) + WithEnv("WW_PROTO", proto). + WithRandSource(rand.Reader). + WithOsyield(runtime.Gosched). + WithSysNanosleep(). + WithSysNanotime(). + WithSysWalltime() p.Mod, err = cfg.Runtime.InstantiateModule(ctx, cfg.Module, cfg.WithEnv(mc)) @@ -122,11 +129,3 @@ func (p *P) ToWasmStack(stack capnp.UInt64List) []uint64 { return p.stack } - -// rd io.LimitedReader -// func (p *P) ReadFrom(r io.Reader) (int64, error) { -// p.buf.Reset() -// p.rd.R = r -// p.rd.N = 1<<32 - 1 // max uint32 -// return io.Copy(&p.buf, r) -// }