2023-01-02 14:28:25 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
const c = @import("c");
|
|
|
|
|
|
2024-07-02 14:19:04 +00:00
|
|
|
pub fn madvise(ptr: [*]align(std.heap.page_size_min) u8, length: usize, advice: u32) std.posix.MadviseError!void {
|
2023-01-02 14:28:25 +00:00
|
|
|
switch (std.posix.errno(c.madvise(ptr, @intCast(length), @intCast(advice)))) {
|
|
|
|
|
.SUCCESS => return,
|
|
|
|
|
.ACCES => return error.AccessDenied,
|
|
|
|
|
.AGAIN => return error.SystemResources,
|
|
|
|
|
.BADF => unreachable, // The map exists, but the area maps something that isn't a file.
|
|
|
|
|
.INVAL => return error.InvalidSyscall,
|
|
|
|
|
.IO => return error.WouldExceedMaximumResidentSetSize,
|
|
|
|
|
.NOMEM => return error.OutOfMemory,
|
|
|
|
|
.NOSYS => return error.MadviseUnavailable,
|
|
|
|
|
else => |err| return std.posix.unexpectedErrno(err),
|
|
|
|
|
}
|
|
|
|
|
}
|