diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2022-12-16 20:19:33 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-02-16 19:34:38 +0000 |
| commit | 1a9893a969e0a73dc4f1e48ed40ccaf29ec238a6 (patch) | |
| tree | 9cf5add65f658ae241275c76387fa4743b868f0b /src/runtime/os_linux.go | |
| parent | 518889b35cb07f3e71963f2ccfc0f96ee26a51ce (diff) | |
| download | go-1a9893a969e0a73dc4f1e48ed40ccaf29ec238a6.tar.xz | |
runtime: expose auxv for use by x/sys/cpu
Updates #57336
Change-Id: I181885f59bac59360b855d3990326ea2b268bd28
Reviewed-on: https://go-review.googlesource.com/c/go/+/458256
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/os_linux.go')
| -rw-r--r-- | src/runtime/os_linux.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 37cd8e6482..194d698798 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -226,6 +226,8 @@ var addrspace_vec [1]byte func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32 +var auxvreadbuf [128]uintptr + func sysargs(argc int32, argv **byte) { n := argc + 1 @@ -238,8 +240,10 @@ func sysargs(argc int32, argv **byte) { n++ // now argv+n is auxv - auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*goarch.PtrSize)) - if sysauxv(auxv[:]) != 0 { + auxvp := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*goarch.PtrSize)) + + if pairs := sysauxv(auxvp[:]); pairs != 0 { + auxv = auxvp[: pairs*2 : pairs*2] return } // In some situations we don't get a loader-provided @@ -269,23 +273,24 @@ func sysargs(argc int32, argv **byte) { munmap(p, size) return } - var buf [128]uintptr - n = read(fd, noescape(unsafe.Pointer(&buf[0])), int32(unsafe.Sizeof(buf))) + + n = read(fd, noescape(unsafe.Pointer(&auxvreadbuf[0])), int32(unsafe.Sizeof(auxvreadbuf))) closefd(fd) if n < 0 { return } // Make sure buf is terminated, even if we didn't read // the whole file. - buf[len(buf)-2] = _AT_NULL - sysauxv(buf[:]) + auxvreadbuf[len(auxvreadbuf)-2] = _AT_NULL + pairs := sysauxv(auxvreadbuf[:]) + auxv = auxvreadbuf[: pairs*2 : pairs*2] } // startupRandomData holds random bytes initialized at startup. These come from // the ELF AT_RANDOM auxiliary vector. var startupRandomData []byte -func sysauxv(auxv []uintptr) int { +func sysauxv(auxv []uintptr) (pairs int) { var i int for ; auxv[i] != _AT_NULL; i += 2 { tag, val := auxv[i], auxv[i+1] |
