1
2
3
4
5
6
7
8
9
10 package cpu
11
12 import (
13 "syscall"
14 "unsafe"
15 )
16
17 type _C_int int32
18
19
20 func darwinOSRelease(release *[256]byte) error {
21
22 const (
23 CTL_KERN = 0x1
24 KERN_OSRELEASE = 0x2
25 )
26
27 mib := []_C_int{CTL_KERN, KERN_OSRELEASE}
28 n := unsafe.Sizeof(*release)
29
30 return sysctl(mib, &release[0], &n, nil, 0)
31 }
32
33 type Errno = syscall.Errno
34
35 var _zero uintptr
36
37
38 func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
39 var _p0 unsafe.Pointer
40 if len(mib) > 0 {
41 _p0 = unsafe.Pointer(&mib[0])
42 } else {
43 _p0 = unsafe.Pointer(&_zero)
44 }
45 if _, _, err := syscall_syscall6(
46 libc_sysctl_trampoline_addr,
47 uintptr(_p0),
48 uintptr(len(mib)),
49 uintptr(unsafe.Pointer(old)),
50 uintptr(unsafe.Pointer(oldlen)),
51 uintptr(unsafe.Pointer(new)),
52 uintptr(newlen),
53 ); err != 0 {
54 return err
55 }
56
57 return nil
58 }
59
60 var libc_sysctl_trampoline_addr uintptr
61
62
63 func darwinSysctlEnabled(name []byte) bool {
64 out := int32(0)
65 nout := unsafe.Sizeof(out)
66 if ret := sysctlbyname(&name[0], (*byte)(unsafe.Pointer(&out)), &nout, nil, 0); ret != nil {
67 return false
68 }
69 return out > 0
70 }
71
72
73
74 var libc_sysctlbyname_trampoline_addr uintptr
75
76
77 func sysctlbyname(name *byte, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
78 if _, _, err := syscall_syscall6(
79 libc_sysctlbyname_trampoline_addr,
80 uintptr(unsafe.Pointer(name)),
81 uintptr(unsafe.Pointer(old)),
82 uintptr(unsafe.Pointer(oldlen)),
83 uintptr(unsafe.Pointer(new)),
84 uintptr(newlen),
85 0,
86 ); err != 0 {
87 return err
88 }
89
90 return nil
91 }
92
93
94
95
96 func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
97
98
99
View as plain text