Skip to content

Commit fad2bbd

Browse files
runtime: fix nanotime for macOS Sierra
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: Ibe5ad50a2c5b125e92b5a4e787db4b5179f6b723 Reviewed-on: https://go-review.googlesource.com/24812 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
1 parent 84bb9e6 commit fad2bbd

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
@@ -201,6 +201,11 @@ systime:
201201
MOVL $0, 8(SP) // time zone pointer
202202
MOVL $116, AX
203203
INT $0x80
204+
CMPL AX, $0
205+
JNE inreg
206+
MOVL 12(SP), AX
207+
MOVL 16(SP), DX
208+
inreg:
204209
// sec is in AX, usec in DX
205210
// convert to DX:AX nsec
206211
MOVL DX, BX

src/runtime/sys_darwin_amd64.s

+6-1
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ timeloop:
155155

156156
systime:
157157
// Fall back to system call (usually first call in this thread).
158-
MOVQ SP, DI // must be non-nil, unused
158+
MOVQ SP, DI
159159
MOVQ $0, SI
160160
MOVL $(0x2000000+116), AX
161161
SYSCALL
162+
CMPQ AX, $0
163+
JNE inreg
164+
MOVQ 0(SP), AX
165+
MOVL 8(SP), DX
166+
inreg:
162167
// sec is in AX, usec in DX
163168
// return nsec in AX
164169
IMULQ $1000000000, AX

0 commit comments

Comments
 (0)