From 29a7271f5da9fdb7b4a9a6c9ea61421ce6844a73 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Thu, 13 Sep 2018 19:11:12 -0700 Subject: Plumb monotonic time to netstack Netstack needs to be portable, so this seems to be preferable to using raw system calls. PiperOrigin-RevId: 212917409 Change-Id: I7b2073e7db4b4bf75300717ca23aea4c15be944c --- pkg/sentry/kernel/kernel.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'pkg/sentry') diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go index bc41c3963..316612b37 100644 --- a/pkg/sentry/kernel/kernel.go +++ b/pkg/sentry/kernel/kernel.go @@ -943,6 +943,8 @@ func (k *Kernel) SetExitError(err error) { } } +var _ tcpip.Clock = (*Kernel)(nil) + // NowNanoseconds implements tcpip.Clock.NowNanoseconds. func (k *Kernel) NowNanoseconds() int64 { now, err := k.timekeeper.GetTime(sentrytime.Realtime) @@ -952,6 +954,15 @@ func (k *Kernel) NowNanoseconds() int64 { return now } +// NowMonotonic implements tcpip.Clock.NowMonotonic. +func (k *Kernel) NowMonotonic() int64 { + now, err := k.timekeeper.GetTime(sentrytime.Monotonic) + if err != nil { + panic("Kernel.NowMonotonic: " + err.Error()) + } + return now +} + // SupervisorContext returns a Context with maximum privileges in k. It should // only be used by goroutines outside the control of the emulated kernel // defined by e. -- cgit v1.2.3