]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/internal/atomic: crash on unaligned 64-bit ops on 32-bit MIPS
authorCherry Zhang <cherryyz@google.com>
Mon, 21 Nov 2016 23:23:12 +0000 (18:23 -0500)
committerCherry Zhang <cherryyz@google.com>
Tue, 22 Nov 2016 02:05:07 +0000 (02:05 +0000)
This check was originally implemented by Vladimir in
https://go-review.googlesource.com/c/31489/1/src/runtime/internal/atomic/atomic_mipsx.go#30
but removed due to my comment (Sorry!). This CL adds it back.

Fixes #17786.

Change-Id: I7ff4c2539fc9e2afd8199964b587a8ccf093b896
Reviewed-on: https://go-review.googlesource.com/33431
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/internal/atomic/atomic_mipsx.go
src/runtime/internal/atomic/atomic_test.go
src/sync/atomic/atomic_test.go

index 20b000c7a0df29c040767e2c05e8032745115a40..93a1f1a9ddd138bd95ba62de7d0c0f5676b99204 100644 (file)
@@ -25,7 +25,11 @@ func spinUnlock(state *uint32)
 
 //go:nosplit
 func lockAndCheck(addr *uint64) {
-       //  force dereference before taking lock
+       // ensure 8-byte alignement
+       if uintptr(unsafe.Pointer(addr))&7 != 0 {
+               addr = nil
+       }
+       // force dereference before taking lock
        _ = *addr
 
        spinLock(&lock.state)
index f7ba90a0730cfb4e06d78c74ed6804730af2bb0e..879a82f9c82cc432fd382649ebced8cb71aa69d9 100644 (file)
@@ -87,8 +87,8 @@ func TestUnaligned64(t *testing.T) {
                if unsafe.Sizeof(int(0)) != 4 {
                        t.Skip("test only runs on 32-bit systems")
                }
-       case "amd64p32", "mips", "mipsle":
-               // amd64p32 and mips can handle unaligned atomics.
+       case "amd64p32":
+               // amd64p32 can handle unaligned atomics.
                t.Skipf("test not needed on %v", runtime.GOARCH)
        }
 
index c151f46fa9b2138f713c3dec15351a0c35a21c67..6d0831c3f9d326b72592e5a4872c96e9ad7e97b8 100644 (file)
@@ -1401,8 +1401,8 @@ func TestUnaligned64(t *testing.T) {
                if unsafe.Sizeof(int(0)) != 4 {
                        t.Skip("test only runs on 32-bit systems")
                }
-       case "amd64p32", "mips", "mipsle":
-               // amd64p32 and mips can handle unaligned atomics.
+       case "amd64p32":
+               // amd64p32 can handle unaligned atomics.
                t.Skipf("test not needed on %v", runtime.GOARCH)
        }