Source file
src/runtime/time_fake.go
1
2
3
4
5
6
7
8
9
10
11
12 package runtime
13
14 import "unsafe"
15
16
17
18 var faketime int64 = 1257894000000000000
19
20 var faketimeState struct {
21 lock mutex
22
23
24 lastfaketime int64
25
26
27
28
29
30
31 lastfd uintptr
32 }
33
34
35 func nanotime() int64 {
36 return faketime
37 }
38
39
40 func time_now() (sec int64, nsec int32, mono int64) {
41 return faketime / 1e9, int32(faketime % 1e9), faketime
42 }
43
44
45
46
47
48 func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
49 if !(fd == 1 || fd == 2) {
50
51 return write1(fd, p, n)
52 }
53
54
55
56
57 lock(&faketimeState.lock)
58
59
60
61
62 t := faketimeState.lastfaketime
63 if fd != faketimeState.lastfd {
64 t++
65 faketimeState.lastfd = fd
66 }
67 if faketime > t {
68 t = faketime
69 }
70 faketimeState.lastfaketime = t
71
72
73 var buf [4 + 8 + 4]byte
74 buf[2] = 'P'
75 buf[3] = 'B'
76 tu := uint64(t)
77 buf[4] = byte(tu >> (7 * 8))
78 buf[5] = byte(tu >> (6 * 8))
79 buf[6] = byte(tu >> (5 * 8))
80 buf[7] = byte(tu >> (4 * 8))
81 buf[8] = byte(tu >> (3 * 8))
82 buf[9] = byte(tu >> (2 * 8))
83 buf[10] = byte(tu >> (1 * 8))
84 buf[11] = byte(tu >> (0 * 8))
85 nu := uint32(n)
86 buf[12] = byte(nu >> (3 * 8))
87 buf[13] = byte(nu >> (2 * 8))
88 buf[14] = byte(nu >> (1 * 8))
89 buf[15] = byte(nu >> (0 * 8))
90 write1(fd, unsafe.Pointer(&buf[0]), int32(len(buf)))
91
92
93 res := write1(fd, p, n)
94
95 unlock(&faketimeState.lock)
96 return res
97 }
98
View as plain text