Commit 5ac29058 by Ian Lance Taylor

sync/atomic, runtime/internal/atomic: don't assume reads from 0 fail

    
    For a misaligned address force a panic rather than assuming that reading
    from the address 0 will cause one.
    
    Reviewed-on: https://go-review.googlesource.com/69850

From-SVN: r254610
parent d60edaba
7fd845bd9414c348bfa30bd24aa0bb8e4eebf83a b03c5dc36d6d0c0d3bef434936e8b924d253595b
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -34,7 +34,7 @@ uint64_t ...@@ -34,7 +34,7 @@ uint64_t
Load64 (uint64_t *ptr) Load64 (uint64_t *ptr)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
return __atomic_load_n (ptr, __ATOMIC_ACQUIRE); return __atomic_load_n (ptr, __ATOMIC_ACQUIRE);
} }
...@@ -66,7 +66,7 @@ int64_t ...@@ -66,7 +66,7 @@ int64_t
Loadint64 (int64_t *ptr) Loadint64 (int64_t *ptr)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
return __atomic_load_n (ptr, __ATOMIC_ACQUIRE); return __atomic_load_n (ptr, __ATOMIC_ACQUIRE);
} }
...@@ -88,7 +88,7 @@ uint64_t ...@@ -88,7 +88,7 @@ uint64_t
Xadd64 (uint64_t *ptr, int64_t delta) Xadd64 (uint64_t *ptr, int64_t delta)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
return __atomic_add_fetch (ptr, (uint64_t) delta, __ATOMIC_SEQ_CST); return __atomic_add_fetch (ptr, (uint64_t) delta, __ATOMIC_SEQ_CST);
} }
...@@ -110,7 +110,7 @@ int64_t ...@@ -110,7 +110,7 @@ int64_t
Xaddint64 (int64_t *ptr, int64_t delta) Xaddint64 (int64_t *ptr, int64_t delta)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
return __atomic_add_fetch (ptr, delta, __ATOMIC_SEQ_CST); return __atomic_add_fetch (ptr, delta, __ATOMIC_SEQ_CST);
} }
...@@ -132,7 +132,7 @@ uint64_t ...@@ -132,7 +132,7 @@ uint64_t
Xchg64 (uint64_t *ptr, uint64_t new) Xchg64 (uint64_t *ptr, uint64_t new)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST); return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST);
} }
...@@ -184,7 +184,7 @@ _Bool ...@@ -184,7 +184,7 @@ _Bool
Cas64 (uint64_t *ptr, uint64_t old, uint64_t new) Cas64 (uint64_t *ptr, uint64_t old, uint64_t new)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
return __atomic_compare_exchange_n (ptr, &old, new, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); return __atomic_compare_exchange_n (ptr, &old, new, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
} }
...@@ -226,7 +226,7 @@ void ...@@ -226,7 +226,7 @@ void
Store64 (uint64_t *ptr, uint64_t val) Store64 (uint64_t *ptr, uint64_t val)
{ {
if (((uintptr_t) ptr & 7) != 0) if (((uintptr_t) ptr & 7) != 0)
ptr = NULL; panicmem ();
__atomic_store_n (ptr, val, __ATOMIC_SEQ_CST); __atomic_store_n (ptr, val, __ATOMIC_SEQ_CST);
} }
......
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
//go:linkname makefuncreturning runtime.makefuncreturning //go:linkname makefuncreturning runtime.makefuncreturning
//go:linkname gorecover runtime.gorecover //go:linkname gorecover runtime.gorecover
//go:linkname deferredrecover runtime.deferredrecover //go:linkname deferredrecover runtime.deferredrecover
//go:linkname panicmem runtime.panicmem
// Temporary for C code to call: // Temporary for C code to call:
//go:linkname throw runtime.throw //go:linkname throw runtime.throw
......
...@@ -26,7 +26,7 @@ int64_t ...@@ -26,7 +26,7 @@ int64_t
SwapInt64 (int64_t *addr, int64_t new) SwapInt64 (int64_t *addr, int64_t new)
{ {
if (((uintptr_t) addr & 7) != 0) if (((uintptr_t) addr & 7) != 0)
addr = NULL; panicmem ();
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST); return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
} }
...@@ -48,7 +48,7 @@ uint64_t ...@@ -48,7 +48,7 @@ uint64_t
SwapUint64 (uint64_t *addr, uint64_t new) SwapUint64 (uint64_t *addr, uint64_t new)
{ {
if (((uintptr_t) addr & 7) != 0) if (((uintptr_t) addr & 7) != 0)
addr = NULL; panicmem ();
return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST); return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
} }
...@@ -215,7 +215,7 @@ LoadInt64 (int64_t *addr) ...@@ -215,7 +215,7 @@ LoadInt64 (int64_t *addr)
int64_t v; int64_t v;
if (((uintptr_t) addr & 7) != 0) if (((uintptr_t) addr & 7) != 0)
addr = NULL; panicmem ();
v = *addr; v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v)) while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr; v = *addr;
...@@ -247,7 +247,7 @@ LoadUint64 (uint64_t *addr) ...@@ -247,7 +247,7 @@ LoadUint64 (uint64_t *addr)
uint64_t v; uint64_t v;
if (((uintptr_t) addr & 7) != 0) if (((uintptr_t) addr & 7) != 0)
addr = NULL; panicmem ();
v = *addr; v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, v)) while (! __sync_bool_compare_and_swap (addr, v, v))
v = *addr; v = *addr;
...@@ -308,7 +308,7 @@ StoreInt64 (int64_t *addr, int64_t val) ...@@ -308,7 +308,7 @@ StoreInt64 (int64_t *addr, int64_t val)
int64_t v; int64_t v;
if (((uintptr_t) addr & 7) != 0) if (((uintptr_t) addr & 7) != 0)
addr = NULL; panicmem ();
v = *addr; v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val)) while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr; v = *addr;
...@@ -338,7 +338,7 @@ StoreUint64 (uint64_t *addr, uint64_t val) ...@@ -338,7 +338,7 @@ StoreUint64 (uint64_t *addr, uint64_t val)
uint64_t v; uint64_t v;
if (((uintptr_t) addr & 7) != 0) if (((uintptr_t) addr & 7) != 0)
addr = NULL; panicmem ();
v = *addr; v = *addr;
while (! __sync_bool_compare_and_swap (addr, v, val)) while (! __sync_bool_compare_and_swap (addr, v, val))
v = *addr; v = *addr;
......
...@@ -211,6 +211,8 @@ extern uint32 runtime_panicking(void) ...@@ -211,6 +211,8 @@ extern uint32 runtime_panicking(void)
extern bool runtime_isstarted; extern bool runtime_isstarted;
extern bool runtime_isarchive; extern bool runtime_isarchive;
extern void panicmem(void) __asm__ (GOSYM_PREFIX "runtime.panicmem");
/* /*
* common functions and data * common functions and data
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment