]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, syscall: fix kernel gettimeofday ABI change on iOS 10
authorShenghou Ma <minux@golang.org>
Fri, 5 Aug 2016 01:34:06 +0000 (21:34 -0400)
committerMinux Ma <minux@golang.org>
Fri, 5 Aug 2016 20:47:34 +0000 (20:47 +0000)
Fixes #16570 on iOS.

Thanks Daniel Burhans for reporting the bug and testing the fix.

Change-Id: I43ae7b78c8f85a131ed3d93ea59da9f32a02cd8f
Reviewed-on: https://go-review.googlesource.com/25481
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/sys_darwin_arm.s
src/runtime/sys_darwin_arm64.s
src/syscall/syscall_darwin_arm.go
src/syscall/syscall_darwin_arm64.go
src/syscall/syscall_darwin_test.go

index 6b6437dddd1d2a8cf8f33584617eb3c5fc59d590..52f6a94d46300f3ac855bb5f693d0c4c31e1f396 100644 (file)
@@ -162,11 +162,15 @@ TEXT runtime·mincore(SB),NOSPLIT,$0
 TEXT time·now(SB), 7, $32
        MOVW    $8(R13), R0  // timeval
        MOVW    $0, R1  // zone
+       MOVW    $0, R2  // see issue 16570
        MOVW    $SYS_gettimeofday, R12
        SWI     $0x80 // Note: R0 is tv_sec, R1 is tv_usec
-
+       CMP     $0, R0
+       BNE     inreg
+       MOVW    8(R13), R0
+       MOVW    12(R13), R1
+inreg:
        MOVW    R1, R2  // usec
-
        MOVW    R0, sec+0(FP)
        MOVW    $0, R1
        MOVW    R1, loc+4(FP)
@@ -178,9 +182,14 @@ TEXT time·now(SB), 7, $32
 TEXT runtime·nanotime(SB),NOSPLIT,$32
        MOVW    $8(R13), R0  // timeval
        MOVW    $0, R1  // zone
+       MOVW    $0, R2  // see issue 16570
        MOVW    $SYS_gettimeofday, R12
        SWI     $0x80 // Note: R0 is tv_sec, R1 is tv_usec
-
+       CMP     $0, R0
+       BNE     inreg
+       MOVW    8(R13), R0
+       MOVW    12(R13), R1
+inreg:
        MOVW    R1, R2
        MOVW    $1000000000, R3
        MULLU   R0, R3, (R1, R0)
index a3b851d2fc80e96e7d7921a3b94a400a8f3f6ed0..8e6b5b1ebfc6a73bbe555889eaa696cb378a11a8 100644 (file)
@@ -155,9 +155,14 @@ TEXT time·now(SB),NOSPLIT,$40-12
        MOVD    RSP, R0 // timeval
        MOVD    R0, R9  // this is how dyld calls gettimeofday
        MOVW    $0, R1  // zone
+       MOVD    $0, R2  // see issue 16570
        MOVW    $SYS_gettimeofday, R16
        SVC     $0x80   // Note: x0 is tv_sec, w1 is tv_usec
-
+       CMP     $0, R0
+       BNE     inreg
+       MOVD    0(RSP), R0
+       MOVW    8(RSP), R1
+inreg:
        MOVD    R0, sec+0(FP)
        MOVW    $1000, R3
        MUL     R3, R1
@@ -168,9 +173,14 @@ TEXT runtime·nanotime(SB),NOSPLIT,$40
        MOVD    RSP, R0 // timeval
        MOVD    R0, R9  // this is how dyld calls gettimeofday
        MOVW    $0, R1  // zone
+       MOVD    $0, R2  // see issue 16570
        MOVW    $SYS_gettimeofday, R16
        SVC     $0x80   // Note: x0 is tv_sec, w1 is tv_usec
-
+       CMP     $0, R0
+       BNE     inreg
+       MOVD    0(RSP), R0
+       MOVW    8(RSP), R1
+inreg:
        MOVW    $1000000000, R3
        MUL     R3, R0
        MOVW    $1000, R3
index c302d8313198d60cd2b1c9912cac95c445918aa6..fe431039f48ec1e8945d599829173fecf157956f 100644 (file)
@@ -26,14 +26,19 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
 }
 
 //sysnb        gettimeofday(tp *Timeval) (sec int32, usec int32, err error)
-func Gettimeofday(tv *Timeval) (err error) {
+func Gettimeofday(tv *Timeval) error {
        // The tv passed to gettimeofday must be non-nil
        // but is otherwise unused. The answers come back
        // in the two registers.
        sec, usec, err := gettimeofday(tv)
-       tv.Sec = int32(sec)
-       tv.Usec = int32(usec)
-       return err
+       if err != nil {
+               return err
+       }
+       if sec != 0 || usec != 0 {
+               tv.Sec = int32(sec)
+               tv.Usec = int32(usec)
+       }
+       return nil
 }
 
 func SetKevent(k *Kevent_t, fd, mode, flags int) {
index 29f40d4229ce330fb736246b43dd57abad62d257..d396e253323ad816e20c34031713d9f765d7275f 100644 (file)
@@ -26,14 +26,19 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
 }
 
 //sysnb        gettimeofday(tp *Timeval) (sec int64, usec int32, err error)
-func Gettimeofday(tv *Timeval) (err error) {
+func Gettimeofday(tv *Timeval) error {
        // The tv passed to gettimeofday must be non-nil
        // but is otherwise unused. The answers come back
        // in the two registers.
        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) {
index dd0e32b968f7fd99203f4d760953d76c142fd4bf..cea5636d07d5c08f49e0ea7b621c001a17b8bb60 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // +build darwin
-// +build amd64 386
+// +build amd64 386 arm arm64
 
 package syscall_test