mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
The ARM64 flags were not being correctly set for Mac M series laptops. Fixes golang/go#43046 Change-Id: I1d884dccd3f3a0a010ad7babbab26b73731ab583 Reviewed-on: https://go-review.googlesource.com/c/sys/+/737260 Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
// Copyright 2024 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Minimal copy from internal/cpu and runtime to make sysctl calls.
|
|
|
|
//go:build darwin && arm64 && gc
|
|
|
|
package cpu
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
type Errno = syscall.Errno
|
|
|
|
// adapted from internal/cpu/cpu_arm64_darwin.go
|
|
func darwinSysctlEnabled(name []byte) bool {
|
|
out := int32(0)
|
|
nout := unsafe.Sizeof(out)
|
|
if ret := sysctlbyname(&name[0], (*byte)(unsafe.Pointer(&out)), &nout, nil, 0); ret != nil {
|
|
return false
|
|
}
|
|
return out > 0
|
|
}
|
|
|
|
//go:cgo_import_dynamic libc_sysctl sysctl "/usr/lib/libSystem.B.dylib"
|
|
|
|
var libc_sysctlbyname_trampoline_addr uintptr
|
|
|
|
// adapted from runtime/sys_darwin.go in the pattern of sysctl() above, as defined in x/sys/unix
|
|
func sysctlbyname(name *byte, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
|
|
if _, _, err := syscall_syscall6(
|
|
libc_sysctlbyname_trampoline_addr,
|
|
uintptr(unsafe.Pointer(name)),
|
|
uintptr(unsafe.Pointer(old)),
|
|
uintptr(unsafe.Pointer(oldlen)),
|
|
uintptr(unsafe.Pointer(new)),
|
|
uintptr(newlen),
|
|
0,
|
|
); err != 0 {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
//go:cgo_import_dynamic libc_sysctlbyname sysctlbyname "/usr/lib/libSystem.B.dylib"
|
|
|
|
// Implemented in the runtime package (runtime/sys_darwin.go)
|
|
func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
|
|
|
//go:linkname syscall_syscall6 syscall.syscall6
|