aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorShenghou Ma <minux@golang.org>2016-04-05 23:09:39 -0400
committerMinux Ma <minux@golang.org>2016-04-06 04:23:37 +0000
commita2eded3421f144983c0ccb9e6c0a325fa1ba1f82 (patch)
tree04d3f62dfc749967cf69dd3d93737d9f4c884ca9 /src/runtime
parentdb9348b866775974b5e04eed04c03de47f1c2d46 (diff)
downloadgo-a2eded3421f144983c0ccb9e6c0a325fa1ba1f82.tar.xz
runtime: get randomness from AT_RANDOM AUXV on linux/arm64
Fixes #15147. Change-Id: Ibfe46c747dea987787a51eb0c95ccd8c5f24f366 Reviewed-on: https://go-review.googlesource.com/21580 Run-TryBot: Minux Ma <minux@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/os_linux_arm64.go26
-rw-r--r--src/runtime/vdso_none.go1
2 files changed, 27 insertions, 0 deletions
diff --git a/src/runtime/os_linux_arm64.go b/src/runtime/os_linux_arm64.go
index 3f994f128b..57184b0d3a 100644
--- a/src/runtime/os_linux_arm64.go
+++ b/src/runtime/os_linux_arm64.go
@@ -4,6 +4,11 @@
package runtime
+import (
+ "runtime/internal/sys"
+ "unsafe"
+)
+
const (
_AT_NULL = 0
_AT_RANDOM = 25 // introduced in 2.6.29
@@ -11,6 +16,27 @@ const (
var randomNumber uint32
+func sysargs(argc int32, argv **byte) {
+ // skip over argv, envv to get to auxv
+ n := argc + 1
+ for argv_index(argv, n) != nil {
+ n++
+ }
+ n++
+ auxv := (*[1 << 29]uint64)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
+
+ for i := 0; auxv[i] != _AT_NULL; i += 2 {
+ switch auxv[i] {
+ case _AT_RANDOM: // kernel provides a pointer to 16-bytes worth of random data
+ startupRandomData = (*[16]byte)(unsafe.Pointer(uintptr(auxv[i+1])))[:]
+ // the pointer provided may not be word aligned, so we must treat it
+ // as a byte array.
+ randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
+ uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
+ }
+ }
+}
+
//go:nosplit
func cputicks() int64 {
// Currently cputicks() is used in blocking profiler and to seed fastrand1().
diff --git a/src/runtime/vdso_none.go b/src/runtime/vdso_none.go
index b4e0a0e349..e14e1a4707 100644
--- a/src/runtime/vdso_none.go
+++ b/src/runtime/vdso_none.go
@@ -5,6 +5,7 @@
// +build !linux !amd64
// +build !linux !386
// +build !linux !arm
+// +build !linux !arm64
package runtime