diff options
| author | Sardorbek Imomaliev <3041675+imomaliev@users.noreply.github.com> | 2025-08-25 20:25:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-25 19:25:53 +0000 |
| commit | 91040b567863e7c068b21d7c6bbf76a1d28a2b2d (patch) | |
| tree | b33b08ab3c110f4a9d002f29ec18fcc34ce032e7 /lib/std/process.zig | |
| parent | a7769e25beaf928b44449bd3746b3eb326255687 (diff) | |
| download | zig-91040b567863e7c068b21d7c6bbf76a1d28a2b2d.tar.gz zig-91040b567863e7c068b21d7c6bbf76a1d28a2b2d.zip | |
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 (limited to 'lib/std/process.zig')
| -rw-r--r-- | lib/std/process.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/std/process.zig b/lib/std/process.zig index 360c3f6af0..1f86ca658a 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1762,7 +1762,20 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 { 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{ |
