authorgravatar for 3041675+imomaliev@users.noreply.github.comSardorbek Imomaliev <3041675+imomaliev@users.noreply.github.com> 2025-08-25 20:25:53+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-26 00:11:34+02:00
log6f07cc95d0c17c7778b37eea646a20886bc7d34c
tree68665d2f75440aa4187f3171bdea693df5640264
parentb2578329afc672f24503cbf580ff73a4a1625f28
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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

1 files changed, 14 insertions(+), 1 deletions(-)

lib/std/process.zig+14-1
......@@ -1762,7 +1762,20 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
17621762 error.NameTooLong, error.UnknownName => unreachable,
17631763 else => return error.UnknownTotalSystemMemory,
17641764 };
1765 return @as(usize, @intCast(physmem));
1765 return @as(u64, @intCast(physmem));
1766 },
1767 // whole Darwin family
1768 .driverkit, .ios, .macos, .tvos, .visionos, .watchos => {
1769 // "hw.memsize" returns uint64_t
1770 var physmem: u64 = undefined;
1771 var len: usize = @sizeOf(u64);
1772 posix.sysctlbynameZ("hw.memsize", &physmem, &len, null, 0) catch |err| switch (err) {
1773 error.PermissionDenied => unreachable, // only when setting values,
1774 error.SystemResources => unreachable, // memory already on the stack
1775 error.UnknownName => unreachable, // constant, known good value
1776 else => return error.UnknownTotalSystemMemory,
1777 };
1778 return physmem;
17661779 },
17671780 .openbsd => {
17681781 const mib: [2]c_int = [_]c_int{