diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-03-28 18:11:09 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-04-02 09:54:48 +0000 |
| commit | f861ecca8b4dbdc9f71c3271d1eb6dbc0f71b5c6 (patch) | |
| tree | 859cab799bcd1fa814af51fb807ce950ad7b0d2f /pkg/osutil/osutil.go | |
| parent | 6baf506947ba27ed9ce775cf9351cb0886166083 (diff) | |
syz-fuzzer: use of monotonic time for latency measurement
time.Now/Since may reject to use monotonic time if the fuzzer
messes with system time badly enough. Enforce use of monotonic time.
Diffstat (limited to 'pkg/osutil/osutil.go')
| -rw-r--r-- | pkg/osutil/osutil.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 478c091dc..a619f9169 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -17,6 +17,7 @@ import ( "sync" "syscall" "time" + _ "unsafe" // required to use go:linkname ) const ( @@ -337,3 +338,14 @@ func Abs(path string) string { } return filepath.Join(wd, path) } + +// MonotonicNano returns monotonic time in nanoseconds from some unspecified point in time. +// Useful mostly to measure time intervals. +// This function should be used inside of tested VMs b/c time.Now may reject to use monotonic time +// if the fuzzer messes with system time (sets time past Y2157, see comments in time/time.go). +// This is a hacky way to use the private runtime function. +// If this ever breaks, we can either provide specializations for different Go versions +// using build tags, or fall back to time.Now. +// +//go:linkname MonotonicNano runtime.nanotime +func MonotonicNano() time.Duration |
