runtime: fix time base for time.Now()

This function previously returned the atomic time, that isn't affected
by system time changes but also has a time base at some arbitrary time
in the past. This makes sense for baremetal platforms (which typically
don't know the wall time) but it gives surprising results on Linux and
macOS: time.Now() usually returns a time somewhere near the start of
1970.

This commit fixes this by obtaining both time values: the monotonic time
and the wall clock time. This is also how the Go runtime implements the
time.now function.
This commit is contained in:
Ayke van Laethem
2021-07-20 13:21:25 +02:00
committed by Ron Evans
parent 73cf187552
commit 03481789b0
6 changed files with 58 additions and 28 deletions
+8
View File
@@ -50,6 +50,14 @@ func putchar(c byte) {
}
}
//go:linkname now time.now
func now() (sec int64, nsec int32, mono int64) {
mono = nanotime()
sec = mono / (1000 * 1000 * 1000)
nsec = int32(mono - sec*(1000*1000*1000))
return
}
// Abort executes the wasm 'unreachable' instruction.
func abort() {
trap()