From 516dc0c15ff1ab781e0677606b5be72919251b3e Mon Sep 17 00:00:00 2001
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
Date: Wed, 9 Dec 2020 14:07:06 +0100
Subject: [PATCH] runtime: use libc_mach_continuous_time in nanotime on Darwin

This makes timers account for having expired while a computer was
asleep, which is quite common on mobile devices. Note that
continuous_time absolute_time, except that it takes into account
time spent in suspend.

Fixes #24595

Change-Id: Ia3282e8bd86f95ad2b76427063e60a005563f4eb
---
 src/runtime/sys_darwin.go      | 2 +-
 src/runtime/sys_darwin_amd64.s | 2 +-
 src/runtime/sys_darwin_arm64.s | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go
index 4a3f2fc453..4a69403b32 100644
--- a/src/runtime/sys_darwin.go
+++ b/src/runtime/sys_darwin.go
@@ -440,7 +440,7 @@ func setNonblock(fd int32) {
 //go:cgo_import_dynamic libc_usleep usleep "/usr/lib/libSystem.B.dylib"
 
 //go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib"
-//go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib"
+//go:cgo_import_dynamic libc_mach_continuous_time mach_continuous_time "/usr/lib/libSystem.B.dylib"
 //go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib"
 //go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib"
 //go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib"
diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s
index 630fb5df64..4499c88802 100644
--- a/src/runtime/sys_darwin_amd64.s
+++ b/src/runtime/sys_darwin_amd64.s
@@ -114,7 +114,7 @@ TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0
 	PUSHQ	BP
 	MOVQ	SP, BP
 	MOVQ	DI, BX
-	CALL	libc_mach_absolute_time(SB)
+	CALL	libc_mach_continuous_time(SB)
 	MOVQ	AX, 0(BX)
 	MOVL	timebase<>+machTimebaseInfo_numer(SB), SI
 	MOVL	timebase<>+machTimebaseInfo_denom(SB), DI // atomic read
diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s
index 96d2ed1076..f046545395 100644
--- a/src/runtime/sys_darwin_arm64.s
+++ b/src/runtime/sys_darwin_arm64.s
@@ -143,7 +143,7 @@ GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)
 
 TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$40
 	MOVD	R0, R19
-	BL	libc_mach_absolute_time(SB)
+	BL	libc_mach_continuous_time(SB)
 	MOVD	R0, 0(R19)
 	MOVW	timebase<>+machTimebaseInfo_numer(SB), R20
 	MOVD	$timebase<>+machTimebaseInfo_denom(SB), R21
-- 
2.30.1

