]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: get randomness from AT_RANDOM AUXV on linux/arm64
authorShenghou Ma <minux@golang.org>
Wed, 6 Apr 2016 03:09:39 +0000 (23:09 -0400)
committerMinux Ma <minux@golang.org>
Wed, 6 Apr 2016 04:23:37 +0000 (04:23 +0000)
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>
src/runtime/os_linux_arm64.go
src/runtime/vdso_none.go

index 3f994f128befefd9e6b49ac528d69d7af6e7a995..57184b0d3a442fa18a3a1d4f9539c0e5cd756f12 100644 (file)
@@ -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().
index b4e0a0e3499c72426ce35d622261b6aed0a101a3..e14e1a470791e641303b598223fe902a91c8af57 100644 (file)
@@ -5,6 +5,7 @@
 // +build !linux !amd64
 // +build !linux !386
 // +build !linux !arm
+// +build !linux !arm64
 
 package runtime