Skip to content

Commit 28e4a20

Browse files
heap: make page size work with macos
1 parent 31a5e22 commit 28e4a20

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/std/c/darwin.zig

+3-1
Original file line numberDiff line numberDiff line change
@@ -3693,7 +3693,7 @@ pub const MachTask = extern struct {
36933693
return left;
36943694
}
36953695

3696-
fn getPageSize(task: MachTask) MachError!usize {
3696+
pub fn getPageSize(task: MachTask) MachError!usize {
36973697
if (task.isValid()) {
36983698
var info_count = TASK_VM_INFO_COUNT;
36993699
var vm_info: task_vm_info_data_t = undefined;
@@ -3846,3 +3846,5 @@ pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost
38463846
pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
38473847
pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
38483848
pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
3849+
3850+
pub extern "c" fn getpagesize() c_int;

lib/std/heap.zig

+2-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ pub fn pageSize() usize {
584584
if (page_size) |pg_size| return pg_size;
585585
page_size = switch (builtin.os.tag) {
586586
.linux => if (builtin.link_libc) @intCast(std.c.sysconf(std.os.linux.SC.PAGESIZE)) else std.os.linux.getauxval(std.elf.AT_PAGESZ),
587-
else => mem.page_size,
587+
.macos => std.os.darwin.machTaskForSelf().getPageSize() catch mem.page_size,
588+
else => if (builtin.link_libc and @hasDecl(std.c, "getpagesize")) std.c.getpagesize() else mem.page_size,
588589
};
589590
return page_size.?;
590591
}

0 commit comments

Comments
 (0)