mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 07:07:33 -04:00
cpu: don't panic on error reading /proc/self/auxv
On Android /proc/self/auxv is not readable, leading to a panic in init. Instead of panic'ing in this case, introduce the Initialized global bool to report whether the CPU features were initialized i.e. /proc/self/auxv was successfullly read. Fixes golang/go#30413 Change-Id: Ib520f202990614a76bceb0bf9d19a88eadd13e10 Reviewed-on: https://go-review.googlesource.com/c/164057 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
775f8194d0
commit
92a0ff1e1e
@@ -6,6 +6,13 @@
|
|||||||
// various CPU architectures.
|
// various CPU architectures.
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
// Initialized reports whether the CPU features were initialized.
|
||||||
|
//
|
||||||
|
// For some GOOS/GOARCH combinations initialization of the CPU features depends
|
||||||
|
// on reading an operating specific file, e.g. /proc/self/auxv on linux/arm
|
||||||
|
// Initialized will report false if reading the file fails.
|
||||||
|
var Initialized bool
|
||||||
|
|
||||||
// CacheLinePad is used to pad structs to avoid false sharing.
|
// CacheLinePad is used to pad structs to avoid false sharing.
|
||||||
type CacheLinePad struct{ _ [cacheLineSize]byte }
|
type CacheLinePad struct{ _ [cacheLineSize]byte }
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -28,7 +28,9 @@ var hwCap2 uint
|
|||||||
func init() {
|
func init() {
|
||||||
buf, err := ioutil.ReadFile(procAuxv)
|
buf, err := ioutil.ReadFile(procAuxv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("read proc auxv failed: " + err.Error())
|
// e.g. on android /proc/self/auxv is not accessible, so silently
|
||||||
|
// ignore the error and leave Initialized = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bo := hostByteOrder()
|
bo := hostByteOrder()
|
||||||
@@ -52,4 +54,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
doinit()
|
doinit()
|
||||||
|
|
||||||
|
Initialized = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import (
|
|||||||
|
|
||||||
func TestAMD64minimalFeatures(t *testing.T) {
|
func TestAMD64minimalFeatures(t *testing.T) {
|
||||||
if runtime.GOARCH == "amd64" {
|
if runtime.GOARCH == "amd64" {
|
||||||
|
if !cpu.Initialized {
|
||||||
|
t.Fatal("Initialized expected true, got false")
|
||||||
|
}
|
||||||
if !cpu.X86.HasSSE2 {
|
if !cpu.X86.HasSSE2 {
|
||||||
t.Fatal("HasSSE2 expected true, got false")
|
t.Fatal("HasSSE2 expected true, got false")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ package cpu
|
|||||||
const cacheLineSize = 64
|
const cacheLineSize = 64
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Initialized = true
|
||||||
|
|
||||||
maxID, _, _, _ := cpuid(0, 0)
|
maxID, _, _, _ := cpuid(0, 0)
|
||||||
|
|
||||||
if maxID < 1 {
|
if maxID < 1 {
|
||||||
|
|||||||
Reference in New Issue
Block a user