Skip to content

Commit c26cf5c

Browse files
committed
runtime: fix nanotime for macOS Sierra
This is a cherry-pick of https://go-review.googlesource.com/24812 to the release-branch-go1.4 In the beta version of the macOS Sierra (10.12) release, the gettimeofday system call changed on x86. Previously it always returned the time in the AX/DX registers. Now, if AX is returned as 0, it means that the system call has stored the values into the memory pointed to by the first argument, just as the libc gettimeofday function does. The libc function handles both cases, and we need to do so as well. Fixes #16272. Change-Id: I490ed0a82e251fce73becc4722cbe276feebc7b7 Reviewed-on: https://go-review.googlesource.com/31729 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent f8c06b1 commit c26cf5c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/runtime/sys_darwin_386.s

+5
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ systime:
187187
MOVL $0, 8(SP) // time zone pointer
188188
MOVL $116, AX
189189
INT $0x80
190+
CMPL AX, $0
191+
JNE inreg
192+
MOVL 12(SP), AX
193+
MOVL 16(SP), DX
194+
inreg:
190195
// sec is in AX, usec in DX
191196
// convert to DX:AX nsec
192197
MOVL DX, BX

src/runtime/sys_darwin_amd64.s

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,15 @@ timeloop:
141141

142142
systime:
143143
// Fall back to system call (usually first call in this thread).
144-
MOVQ SP, DI // must be non-nil, unused
144+
MOVQ SP, DI
145145
MOVQ $0, SI
146146
MOVL $(0x2000000+116), AX
147147
SYSCALL
148+
CMPQ AX, $0
149+
JNE inreg
150+
MOVQ 0(SP), AX
151+
MOVL 8(SP), DX
152+
inreg:
148153
// sec is in AX, usec in DX
149154
// return nsec in AX
150155
IMULQ $1000000000, AX

0 commit comments

Comments
 (0)