commit 6f07cc95d0c17c7778b37eea646a20886bc7d34c (tree)
parent b2578329afc672f24503cbf580ff73a4a1625f28
Author: Sardorbek Imomaliev <3041675+imomaliev@users.noreply.github.com>
Date: Mon, 25 Aug 2025 20:25:53 +0100
add macOS handling for totalSystemMemory (#24903)
* add macos handling for totalSystemMemory
* fix return type cast for .freebsd in totalSystemMemory
* add handling for the whole Darwin family in totalSystemMemory
Diffstat:
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/std/process.zig b/lib/std/process.zig
@@ -1762,7 +1762,20 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
error.NameTooLong, error.UnknownName => unreachable,
else => return error.UnknownTotalSystemMemory,
};
- return @as(usize, @intCast(physmem));
+ return @as(u64, @intCast(physmem));
+ },
+ // whole Darwin family
+ .driverkit, .ios, .macos, .tvos, .visionos, .watchos => {
+ // "hw.memsize" returns uint64_t
+ var physmem: u64 = undefined;
+ var len: usize = @sizeOf(u64);
+ posix.sysctlbynameZ("hw.memsize", &physmem, &len, null, 0) catch |err| switch (err) {
+ error.PermissionDenied => unreachable, // only when setting values,
+ error.SystemResources => unreachable, // memory already on the stack
+ error.UnknownName => unreachable, // constant, known good value
+ else => return error.UnknownTotalSystemMemory,
+ };
+ return physmem;
},
.openbsd => {
const mib: [2]c_int = [_]c_int{