Skip to content

Commit 4af3c17

Browse files
committed
runtime: wrap nanotime, walltime, and write
In preparation for general faketime support, this renames the existing nanotime, walltime, and write functions to nanotime1, walltime1, and write1 and wraps them with trivial Go functions. This will let us inject different implementations on all platforms when faketime is enabled. Updates #30439. Change-Id: Ice5ccc513a32a6d89ea051638676d3ee05b00418 Reviewed-on: https://go-review.googlesource.com/c/go/+/192738 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 6719d88 commit 4af3c17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+164
-133
lines changed

misc/wasm/wasm_exec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@
248248
this.mem = new DataView(this._inst.exports.mem.buffer);
249249
},
250250

251-
// func nanotime() int64
252-
"runtime.nanotime": (sp) => {
251+
// func nanotime1() int64
252+
"runtime.nanotime1": (sp) => {
253253
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
254254
},
255255

256-
// func walltime() (sec int64, nsec int32)
257-
"runtime.walltime": (sp) => {
256+
// func walltime1() (sec int64, nsec int32)
257+
"runtime.walltime1": (sp) => {
258258
const msec = (new Date).getTime();
259259
setInt64(sp + 8, msec / 1000);
260260
this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);

src/runtime/os2_aix.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,10 @@ func exit(code int32) {
390390
exit1(code)
391391
}
392392

393-
func write1(fd, p uintptr, n int32) int32
393+
func write2(fd, p uintptr, n int32) int32
394394

395395
//go:nosplit
396-
func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
396+
func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
397397
_g_ := getg()
398398

399399
// Check the validity of g because without a g during
@@ -402,7 +402,7 @@ func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
402402
r, _ := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
403403
return int32(r)
404404
}
405-
return write1(fd, uintptr(p), n)
405+
return write2(fd, uintptr(p), n)
406406

407407
}
408408

src/runtime/os3_solaris.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,11 @@ func munmap(addr unsafe.Pointer, n uintptr) {
393393
sysvicall2(&libc_munmap, uintptr(addr), uintptr(n))
394394
}
395395

396-
func nanotime1()
396+
func nanotime2()
397397

398398
//go:nosplit
399-
func nanotime() int64 {
400-
return int64(sysvicall0((*libcFunc)(unsafe.Pointer(funcPC(nanotime1)))))
399+
func nanotime1() int64 {
400+
return int64(sysvicall0((*libcFunc)(unsafe.Pointer(funcPC(nanotime2)))))
401401
}
402402

403403
//go:nosplit
@@ -499,7 +499,7 @@ func usleep(µs uint32) {
499499
}
500500

501501
//go:nosplit
502-
func write(fd uintptr, buf unsafe.Pointer, nbyte int32) int32 {
502+
func write1(fd uintptr, buf unsafe.Pointer, nbyte int32) int32 {
503503
return int32(sysvicall3(&libc_write, uintptr(fd), uintptr(buf), uintptr(nbyte)))
504504
}
505505

src/runtime/os_aix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ const (
323323
)
324324

325325
//go:nosplit
326-
func nanotime() int64 {
326+
func nanotime1() int64 {
327327
tp := &timespec{}
328328
if clock_gettime(_CLOCK_REALTIME, tp) != 0 {
329329
throw("syscall clock_gettime failed")
330330
}
331331
return tp.tv_sec*1000000000 + tp.tv_nsec
332332
}
333333

334-
func walltime() (sec int64, nsec int32) {
334+
func walltime1() (sec int64, nsec int32) {
335335
ts := &timespec{}
336336
if clock_gettime(_CLOCK_REALTIME, ts) != 0 {
337337
throw("syscall clock_gettime failed")

src/runtime/os_js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func exit(code int32)
1414

15-
func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
15+
func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
1616
if fd > 2 {
1717
throw("runtime.write to fd > 2 is unsupported")
1818
}

src/runtime/os_nacl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ var lastfaketime int64
300300
// but the timestamp must increase if the fd changes.
301301
var lastfaketimefd int32
302302

303+
func walltime() (sec int64, nsec int32)
304+
303305
/*
304306
An attempt at IRT. Doesn't work. See end of sys_nacl_amd64.s.
305307

src/runtime/os_plan9.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func usleep(µs uint32) {
328328
}
329329

330330
//go:nosplit
331-
func nanotime() int64 {
331+
func nanotime1() int64 {
332332
var scratch int64
333333
ns := nsec(&scratch)
334334
// TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
@@ -373,7 +373,7 @@ func postnote(pid uint64, msg []byte) int {
373373
return -1
374374
}
375375
len := findnull(&msg[0])
376-
if write(uintptr(fd), unsafe.Pointer(&msg[0]), int32(len)) != int64(len) {
376+
if write1(uintptr(fd), unsafe.Pointer(&msg[0]), int32(len)) != int32(len) {
377377
closefd(fd)
378378
return -1
379379
}
@@ -451,8 +451,8 @@ func read(fd int32, buf unsafe.Pointer, n int32) int32 {
451451
}
452452

453453
//go:nosplit
454-
func write(fd uintptr, buf unsafe.Pointer, n int32) int64 {
455-
return int64(pwrite(int32(fd), buf, n, -1))
454+
func write1(fd uintptr, buf unsafe.Pointer, n int32) int32 {
455+
return pwrite(int32(fd), buf, n, -1)
456456
}
457457

458458
var _badsignal = []byte("runtime: signal received on thread not created by Go.\n")

src/runtime/os_windows.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,6 @@ func osinit() {
416416
stdcall2(_SetProcessPriorityBoost, currentProcess, 1)
417417
}
418418

419-
func nanotime() int64
420-
421419
// useQPCTime controls whether time.now and nanotime use QueryPerformanceCounter.
422420
// This is only set to 1 when running under Wine.
423421
var useQPCTime uint8
@@ -542,8 +540,12 @@ func exit(code int32) {
542540
stdcall1(_ExitProcess, uintptr(code))
543541
}
544542

543+
// write1 must be nosplit because it's used as a last resort in
544+
// functions like badmorestackg0. In such cases, we'll always take the
545+
// ASCII path.
546+
//
545547
//go:nosplit
546-
func write(fd uintptr, buf unsafe.Pointer, n int32) int32 {
548+
func write1(fd uintptr, buf unsafe.Pointer, n int32) int32 {
547549
const (
548550
_STD_OUTPUT_HANDLE = ^uintptr(10) // -11
549551
_STD_ERROR_HANDLE = ^uintptr(11) // -12
@@ -640,6 +642,9 @@ func writeConsoleUTF16(handle uintptr, b []uint16) {
640642
return
641643
}
642644

645+
// walltime1 isn't implemented on Windows, but will never be called.
646+
func walltime1() (sec int64, nsec int32)
647+
643648
//go:nosplit
644649
func semasleep(ns int64) int32 {
645650
const (

src/runtime/stubs2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func exit(code int32)
2121
func usleep(usec uint32)
2222

2323
//go:noescape
24-
func write(fd uintptr, p unsafe.Pointer, n int32) int32
24+
func write1(fd uintptr, p unsafe.Pointer, n int32) int32
2525

2626
//go:noescape
2727
func open(name *byte, mode, perm int32) int32

src/runtime/stubs3.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
// +build !plan9
66
// +build !solaris
7-
// +build !windows
87
// +build !nacl
98
// +build !freebsd
109
// +build !darwin
1110
// +build !aix
1211

1312
package runtime
1413

15-
func nanotime() int64
14+
func nanotime1() int64

0 commit comments

Comments
 (0)