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 noreply@github.comGitHub <noreply@github.com> 2025-08-25 19:25:53+00:00
log91040b567863e7c068b21d7c6bbf76a1d28a2b2d
treeb33b08ab3c110f4a9d002f29ec18fcc34ce032e7
parenta7769e25beaf928b44449bd3746b3eb326255687
signaturebadge-check Signed by PGP key B5690EEEBB952194

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.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{