Debian Codegraph @

src/runtime/time_nofake.go

raw
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build !faketime
6
7 package runtime
8
9 import "unsafe"
10
11 // faketime is the simulated time in nanoseconds since 1970 for the
12 // playground.
13 //
14 // Zero means not to use faketime.
15 var faketime int64
16
17 // Exported via linkname for use by time and internal/poll.
18 //
19 // Many external packages also linkname nanotime for a fast monotonic time.
20 // Such code should be updated to use:
21 //
22 // var start = time.Now() // at init time
23 //
24 // and then replace nanotime() with time.Since(start), which is equally fast.
25 //
26 // However, all the code linknaming nanotime is never going to go away.
27 // Do not remove or change the type signature.
28 // See go.dev/issue/67401.
29 //
30 //go:linkname nanotime
31 //go:nosplit
32 func nanotime() int64 {
33 return nanotime1()
34 }
35
36 // overrideWrite allows write to be redirected externally, by
37 // linkname'ing this and set it to a write function.
38 //
39 // overrideWrite should be an internal detail,
40 // but widely used packages access it using linkname.
41 // Notable members of the hall of shame include:
42 // - golang.zx2c4.com/wireguard/windows
43 //
44 // Do not remove or change the type signature.
45 // See go.dev/issue/67401.
46 //
47 //go:linkname overrideWrite
48 var overrideWrite func(fd uintptr, p unsafe.Pointer, n int32) int32
49
50 // write must be nosplit on Windows (see write1)
51 //
52 //go:nosplit
53 func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
54 if overrideWrite != nil {
55 return overrideWrite(fd, noescape(p), n)
56 }
57 return write1(fd, p, n)
58 }