mirror of
https://github.com/golang/go
synced 2024-11-19 03:44:40 -07:00
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>
This commit is contained in:
parent
db9348b866
commit
a2eded3421
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user