aboutsummaryrefslogtreecommitdiff
path: root/core/sys
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2022-09-02 04:11:02 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2022-09-02 04:11:02 +0200
commit1637de3ebbe8c165895e4e9642a78aa951e57fe2 (patch)
tree6a9319b17c8149252b8df3eb7c546c74166bcbe4 /core/sys
parent45691a462282016368d1740fccb4488a331ca172 (diff)
[sys/info] Parse xnu kernel version
Diffstat (limited to 'core/sys')
-rw-r--r--core/sys/info/platform_darwin.odin45
1 files changed, 34 insertions, 11 deletions
diff --git a/core/sys/info/platform_darwin.odin b/core/sys/info/platform_darwin.odin
index 21153a6ad..50ec6e124 100644
--- a/core/sys/info/platform_darwin.odin
+++ b/core/sys/info/platform_darwin.odin
@@ -3,10 +3,33 @@ package sysinfo
import sys "core:sys/darwin"
import "core:intrinsics"
+import "core:strconv"
+import "core:strings"
+import "core:fmt"
@(init, private)
-init_os_version :: proc "c" () {
+init_os_version :: proc () {
os_version.platform = .MacOS
+
+ mib := []i32{CTL_KERN, KERN_OSRELEASE}
+ version_bits: [12]u8 // enough for 999.999.999\x00
+ ok := sysctl(mib, &version_bits)
+ if !ok {
+ return
+ }
+
+ triplet := strings.split(string(cstring(&version_bits[0])), ".", context.temp_allocator)
+ if len(triplet) == 3 {
+ major, major_ok := strconv.parse_int(triplet[0])
+ minor, minor_ok := strconv.parse_int(triplet[1])
+ patch, patch_ok := strconv.parse_int(triplet[2])
+
+ if major_ok && minor_ok && patch_ok {
+ os_version.major = major
+ os_version.minor = minor
+ os_version.patch = patch
+ }
+ }
}
@(init)
@@ -14,7 +37,7 @@ init_ram :: proc() {
// Retrieve RAM info using `sysinfo`
mib := []i32{CTL_HW, HW_MEMSIZE}
- mem_size: i64
+ mem_size: u64
ok := sysctl(mib, &mem_size)
ram.total_ram = int(mem_size)
}
@@ -35,24 +58,24 @@ sysctl :: proc(mib: []i32, val: ^$T) -> (ok: bool) {
// See sysctl.h for xnu/dwrwin for details
CTL_KERN :: 1
- KERN_OSTYPE :: 1 /* string: system version */
- KERN_OSRELEASE :: 2 /* string: system release */
- KERN_OSREV :: 3 /* int: system revision */
- KERN_VERSION :: 4 /* string: compile time info */
- KERN_OSRELDATE :: 26 /* int: OS release date */
- KERN_OSVERSION :: 65 /* for build number i.e. 9A127 */
+ KERN_OSTYPE :: 1 // Darwin
+ KERN_OSRELEASE :: 2 // 21.5.0 for 12.4 Monterey
+ KERN_OSREV :: 3 // i32: system revision
+ KERN_VERSION :: 4 // Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
+ KERN_OSRELDATE :: 26 // i32: OS release date
+ KERN_OSVERSION :: 65 // Build number, e.g. 21F79
CTL_VM :: 2
CTL_VFS :: 3
CTL_NET :: 4
CTL_DEBUG :: 5
CTL_HW :: 6
- HW_MACHINE :: 1 /* string: machine class */
- HW_MODEL :: 2 /* string: specific machine model */
+ HW_MACHINE :: 1 // x86_64
+ HW_MODEL :: 2 // MacbookPro14,1
HW_NCPU :: 3 /* int: number of cpus */
HW_BYTEORDER :: 4 /* int: machine byte order */
HW_MACHINE_ARCH :: 12 /* string: machine architecture */
HW_VECTORUNIT :: 13 /* int: has HW vector unit? */
- HW_MEMSIZE :: 24 /* uint64_t: physical ram size */
+ HW_MEMSIZE :: 24 // u64
HW_AVAILCPU :: 25 /* int: number of available CPUs */
CTL_MACHDEP :: 7