aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/os_linux_arm.go
diff options
context:
space:
mode:
authorDave Cheney <dave@cheney.net>2014-11-15 09:57:02 +1100
committerDave Cheney <dave@cheney.net>2014-11-15 09:57:02 +1100
commit14d23bfd7bd969901f1912131c2a208d34e4b354 (patch)
tree4115bc3a33c8d693172278413428dd8c8301ce15 /src/runtime/os_linux_arm.go
parent1f420c13bd693fc94e112927602b75a4da9dbc0f (diff)
downloadgo-14d23bfd7bd969901f1912131c2a208d34e4b354.tar.gz
go-14d23bfd7bd969901f1912131c2a208d34e4b354.zip
[dev.cc] runtime: fix bus error accessing auxv random data on arm5
It's rather unsporting of the kernel to give us a pointer to unaligned memory. This fixes one crash, the next crash occurs in the soft float emulation. LGTM=minux, rsc, austin R=minux, rsc, austin CC=golang-codereviews https://golang.org/cl/177730043
Diffstat (limited to 'src/runtime/os_linux_arm.go')
-rw-r--r--src/runtime/os_linux_arm.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/runtime/os_linux_arm.go b/src/runtime/os_linux_arm.go
index 9b0ade6148..d5b37d6ab5 100644
--- a/src/runtime/os_linux_arm.go
+++ b/src/runtime/os_linux_arm.go
@@ -50,9 +50,12 @@ func setup_auxv(argc int32, argv **byte) {
for i := 0; auxv[i] != _AT_NULL; i += 2 {
switch auxv[i] {
- case _AT_RANDOM: // kernel provided 16-byte worth of random data
+ case _AT_RANDOM: // kernel provides a pointer to 16-bytes worth of random data
if auxv[i+1] != 0 {
- randomNumber = *(*uint32)(unsafe.Pointer(uintptr(auxv[i+1])))
+ // the pointer provided may not be word alined, so we must to treat it
+ // as a byte array.
+ rnd := (*[16]byte)(unsafe.Pointer(uintptr(auxv[i+1])))
+ randomNumber = uint32(rnd[0]) | uint32(rnd[1])<<8 | uint32(rnd[2])<<16 | uint32(rnd[3])<<24
}
case _AT_PLATFORM: // v5l, v6l, v7l