os: add mach VM tags

This commit is contained in:
Mitchell Hashimoto
2026-01-09 20:17:33 -08:00
parent ec2912dbaf
commit 6f1544b4a3
2 changed files with 39 additions and 0 deletions

35
src/os/mach.zig Normal file
View File

@@ -0,0 +1,35 @@
const std = @import("std");
/// macOS virtual memory tags for use with mach_vm_map/mach_vm_allocate.
/// These identify memory regions in tools like vmmap and Instruments.
pub const VMTag = enum(u8) {
application_specific_1 = 240,
application_specific_2 = 241,
application_specific_3 = 242,
application_specific_4 = 243,
application_specific_5 = 244,
application_specific_6 = 245,
application_specific_7 = 246,
application_specific_8 = 247,
application_specific_9 = 248,
application_specific_10 = 249,
application_specific_11 = 250,
application_specific_12 = 251,
application_specific_13 = 252,
application_specific_14 = 253,
application_specific_15 = 254,
application_specific_16 = 255,
// We ignore the rest because we never realistic set them.
_,
/// Converts the tag to the format expected by mach_vm_map/mach_vm_allocate.
/// Equivalent to C macro: VM_MAKE_TAG(tag)
pub fn make(self: VMTag) i32 {
return @bitCast(@as(u32, @intFromEnum(self)) << 24);
}
};
test "VMTag.make" {
try std.testing.expectEqual(@as(i32, @bitCast(@as(u32, 240) << 24)), VMTag.application_specific_1.make());
}

View File

@@ -23,6 +23,7 @@ pub const args = @import("args.zig");
pub const cgroup = @import("cgroup.zig");
pub const hostname = @import("hostname.zig");
pub const i18n = @import("i18n.zig");
pub const mach = @import("mach.zig");
pub const path = @import("path.zig");
pub const passwd = @import("passwd.zig");
pub const xdg = @import("xdg.zig");
@@ -73,5 +74,8 @@ test {
if (comptime builtin.os.tag == .linux) {
_ = kernel_info;
} else if (comptime builtin.os.tag.isDarwin()) {
_ = mach;
_ = macos;
}
}