]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use a single definition of time_now for faketime
authorIan Lance Taylor <iant@golang.org>
Tue, 27 Apr 2021 23:22:25 +0000 (16:22 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 28 Apr 2021 20:17:20 +0000 (20:17 +0000)
Build other definitions with the !faketime build tag.

This makes it easy for us to add new assembly implementations of time.now.

Change-Id: I4e48e41a4a04ab001030e6d1cdd9cebfa0161b0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/314274
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/time_fake.go
src/runtime/time_windows_386.s
src/runtime/time_windows_amd64.s
src/runtime/time_windows_arm.s
src/runtime/time_windows_arm64.s
src/runtime/timeasm.go
src/runtime/timestub.go

index 1238744ebf6bfba6bb0a8798e8eb547f00219099..9d9a1e2ca680be4c2f89ddbe7c033277442cf5b7 100644 (file)
@@ -5,17 +5,10 @@
 //go:build faketime && !windows
 // +build faketime,!windows
 
-// Faketime isn't currently supported on Windows. This would require:
-//
-// 1. Shadowing time_now, which is implemented in assembly on Windows.
-//    Since that's exported directly to the time package from runtime
-//    assembly, this would involve moving it from sys_windows_*.s into
-//    its own assembly files build-tagged with !faketime and using the
-//    implementation of time_now from timestub.go in faketime mode.
-//
-// 2. Modifying syscall.Write to call syscall.faketimeWrite,
-//    translating the Stdout and Stderr handles into FDs 1 and 2.
-//    (See CL 192739 PS 3.)
+// Faketime isn't currently supported on Windows. This would require
+// modifying syscall.Write to call syscall.faketimeWrite,
+// translating the Stdout and Stderr handles into FDs 1 and 2.
+// (See CL 192739 PS 3.)
 
 package runtime
 
@@ -48,6 +41,12 @@ func walltime() (sec int64, nsec int32) {
        return faketime / 1000000000, int32(faketime % 1000000000)
 }
 
+//go:linkname time_now time.now
+func time_now() (sec int64, nsec int32, mono int64) {
+       sec, nsec = walltime()
+       return sec, nsec, nanotime()
+}
+
 func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
        if !(fd == 1 || fd == 2) {
                // Do an ordinary write.
index d1235c94140169d37dd9424434e435974a353148..19ce6910d73b59e9cdc58c3844df3846a995f57d 100644 (file)
@@ -2,6 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build !faketime
+// +build !faketime
+
 #include "go_asm.h"
 #include "textflag.h"
 #include "time_windows.h"
index 7d1fcfbcf5051062d3e81a40de7fde22bb6f1a54..93ab960b067cd5a810d27effdb31cf84712792bd 100644 (file)
@@ -2,6 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build !faketime
+// +build !faketime
+
 #include "go_asm.h"
 #include "textflag.h"
 #include "time_windows.h"
index 70d0b60f787c3cc984ee293bcf4513cf11e79bef..7c763b66edd2f6b4716f67bc5987a2f5e69ab915 100644 (file)
@@ -2,6 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build !faketime
+// +build !faketime
+
 #include "go_asm.h"
 #include "textflag.h"
 #include "time_windows.h"
index 61ce7577ce052db506cc7257576f273b54842763..ef52ce4c99441eb02c5c00a933e9d0be44fffc88 100644 (file)
@@ -2,6 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build !faketime
+// +build !faketime
+
 #include "go_asm.h"
 #include "textflag.h"
 #include "time_windows.h"
index fe38a086fc77745d596e5ee951765525a31335cc..f0c09461bdc2b08c22448368e321363c7ce0fdd9 100644 (file)
@@ -4,8 +4,8 @@
 
 // Declarations for operating systems implementing time.now directly in assembly.
 
-//go:build windows
-// +build windows
+//go:build !faketime && windows
+// +build !faketime,windows
 
 package runtime
 
index 2ef8d4665fabd9e771ade58af7585e465abcb526..a3d9d5828655952bcec7959934e42ef64505cbde 100644 (file)
@@ -5,8 +5,8 @@
 // Declarations for operating systems implementing time.now
 // indirectly, in terms of walltime and nanotime assembly.
 
-//go:build !windows
-// +build !windows
+//go:build !faketime && !windows
+// +build !faketime,!windows
 
 package runtime