Commit a2eded34 authored by Shenghou Ma's avatar Shenghou Ma Committed by Minux Ma

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent db9348b8
......@@ -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().
......
......@@ -5,6 +5,7 @@
// +build !linux !amd64
// +build !linux !386
// +build !linux !arm
// +build !linux !arm64
package runtime
......
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