summary refs log tree commit diff
path: root/pkgs/development/compilers/go/fix-systime-1.6.patch
blob: e4a3932001e50528278406bd8cf791b32f747adf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s
index e09b906ba5..fa8ff2f65c 100644
--- a/src/runtime/sys_darwin_amd64.s
+++ b/src/runtime/sys_darwin_amd64.s
@@ -157,6 +157,7 @@ systime:
 	// Fall back to system call (usually first call in this thread).
 	MOVQ	SP, DI
 	MOVQ	$0, SI
+	MOVQ	$0, DX  // required as of Sierra; Issue 16570
 	MOVL	$(0x2000000+116), AX
 	SYSCALL
 	CMPQ	AX, $0
diff --git a/src/syscall/syscall_darwin_amd64.go b/src/syscall/syscall_darwin_amd64.go
index 70b53b87f4..79083117b6 100644
--- a/src/syscall/syscall_darwin_amd64.go
+++ b/src/syscall/syscall_darwin_amd64.go
@@ -26,14 +26,21 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
 }
 
 //sysnb	gettimeofday(tp *Timeval) (sec int64, usec int32, err error)
-func Gettimeofday(tv *Timeval) (err error) {
-	// The tv passed to gettimeofday must be non-nil
-	// but is otherwise unused.  The answers come back
-	// in the two registers.
+func Gettimeofday(tv *Timeval) error {
+	// The tv passed to gettimeofday must be non-nil.
+	// Before macOS Sierra (10.12), tv was otherwise unused and
+	// the answers came back in the two registers.
+	// As of Sierra, gettimeofday return zeros and populates
+	// tv itself.
 	sec, usec, err := gettimeofday(tv)
-	tv.Sec = sec
-	tv.Usec = usec
-	return err
+	if err != nil {
+		return err
+	}
+	if sec != 0 || usec != 0 {
+		tv.Sec = sec
+		tv.Usec = usec
+	}
+	return nil
 }
 
 func SetKevent(k *Kevent_t, fd, mode, flags int) {