diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 | 
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 | 
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip  | |
Make Nix builds work
Diffstat (limited to 'vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go')
| -rw-r--r-- | vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go | 53 | 
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go b/vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go new file mode 100644 index 0000000..4cd64c7 --- /dev/null +++ b/vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go  | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | // Copyright 2022 The Go Authors. All rights reserved. | ||
| 2 | // Use of this source code is governed by a BSD-style | ||
| 3 | // license that can be found in the LICENSE file. | ||
| 4 | |||
| 5 | //go:build linux && arm64 | ||
| 6 | |||
| 7 | package cpu | ||
| 8 | |||
| 9 | import ( | ||
| 10 | "errors" | ||
| 11 | "io" | ||
| 12 | "os" | ||
| 13 | "strings" | ||
| 14 | ) | ||
| 15 | |||
| 16 | func readLinuxProcCPUInfo() error { | ||
| 17 | f, err := os.Open("/proc/cpuinfo") | ||
| 18 | if err != nil { | ||
| 19 | return err | ||
| 20 | } | ||
| 21 | defer f.Close() | ||
| 22 | |||
| 23 | var buf [1 << 10]byte // enough for first CPU | ||
| 24 | n, err := io.ReadFull(f, buf[:]) | ||
| 25 | if err != nil && err != io.ErrUnexpectedEOF { | ||
| 26 | return err | ||
| 27 | } | ||
| 28 | in := string(buf[:n]) | ||
| 29 | const features = "\nFeatures : " | ||
| 30 | i := strings.Index(in, features) | ||
| 31 | if i == -1 { | ||
| 32 | return errors.New("no CPU features found") | ||
| 33 | } | ||
| 34 | in = in[i+len(features):] | ||
| 35 | if i := strings.Index(in, "\n"); i != -1 { | ||
| 36 | in = in[:i] | ||
| 37 | } | ||
| 38 | m := map[string]*bool{} | ||
| 39 | |||
| 40 | initOptions() // need it early here; it's harmless to call twice | ||
| 41 | for _, o := range options { | ||
| 42 | m[o.Name] = o.Feature | ||
| 43 | } | ||
| 44 | // The EVTSTRM field has alias "evstrm" in Go, but Linux calls it "evtstrm". | ||
| 45 | m["evtstrm"] = &ARM64.HasEVTSTRM | ||
| 46 | |||
| 47 | for _, f := range strings.Fields(in) { | ||
| 48 | if p, ok := m[f]; ok { | ||
| 49 | *p = true | ||
| 50 | } | ||
| 51 | } | ||
| 52 | return nil | ||
| 53 | } | ||