aboutsummaryrefslogtreecommitdiff
path: root/lib/std/process.zig
diff options
context:
space:
mode:
authorTristan Ross <tristan.ross@midstall.com>2024-01-21 22:16:22 -0800
committerAndrew Kelley <andrew@ziglang.org>2024-01-23 00:17:53 -0800
commitc0e0bb385cec80f3c370fb9e1c3b7116fae1bd9c (patch)
tree763a7a74362fe90129e15f336bf2e40d0cb7a4f1 /lib/std/process.zig
parent68ea1121fc73d35311b29d15b731a3e424867265 (diff)
downloadzig-c0e0bb385cec80f3c370fb9e1c3b7116fae1bd9c.tar.gz
zig-c0e0bb385cec80f3c370fb9e1c3b7116fae1bd9c.zip
std.process: return u64 in totalSystemMemory
Diffstat (limited to 'lib/std/process.zig')
-rw-r--r--lib/std/process.zig15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/std/process.zig b/lib/std/process.zig
index 0ab8a30d96..e51076d889 100644
--- a/lib/std/process.zig
+++ b/lib/std/process.zig
@@ -1522,8 +1522,11 @@ pub const TotalSystemMemoryError = error{
UnknownTotalSystemMemory,
};
-/// Returns the total system memory, in bytes.
-pub fn totalSystemMemory() TotalSystemMemoryError!usize {
+/// Returns the total system memory, in bytes as a u64.
+/// We return a u64 instead of usize due to PAE on ARM
+/// and Linux's /proc/meminfo reporting more memory when
+/// using QEMU user mode emulation.
+pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
switch (builtin.os.tag) {
.linux => {
return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;
@@ -1552,7 +1555,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
else => return error.UnknownTotalSystemMemory,
};
assert(physmem >= 0);
- return @as(usize, @bitCast(physmem));
+ return @as(u64, @bitCast(physmem));
},
.windows => {
var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;
@@ -1565,13 +1568,13 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
if (rc != .SUCCESS) {
return error.UnknownTotalSystemMemory;
}
- return @as(usize, sbi.NumberOfPhysicalPages) * sbi.PageSize;
+ return @as(u64, sbi.NumberOfPhysicalPages) * sbi.PageSize;
},
else => return error.UnknownTotalSystemMemory,
}
}
-fn totalSystemMemoryLinux() !usize {
+fn totalSystemMemoryLinux() !u64 {
var file = try std.fs.openFileAbsoluteZ("/proc/meminfo", .{});
defer file.close();
var buf: [50]u8 = undefined;
@@ -1583,7 +1586,7 @@ fn totalSystemMemoryLinux() !usize {
const int_text = it.next() orelse return error.Unexpected;
const units = it.next() orelse return error.Unexpected;
if (!std.mem.eql(u8, units, "kB")) return error.Unexpected;
- const kilobytes = try std.fmt.parseInt(usize, int_text, 10);
+ const kilobytes = try std.fmt.parseInt(u64, int_text, 10);
return kilobytes * 1024;
}