Skip to content

Commit 44ea11d

Browse files
jeffectivealexrp
authored andcommitted
#24471: add mlock syscalls to std.os.linux
1 parent 7ee6dab commit 44ea11d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/std/os/linux.zig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,44 @@ pub fn munmap(address: [*]const u8, length: usize) usize {
10141014
return syscall2(.munmap, @intFromPtr(address), length);
10151015
}
10161016

1017+
pub fn mlock(address: [*]const u8, length: usize) usize {
1018+
return syscall2(.mlock, @intFromPtr(address), length);
1019+
}
1020+
1021+
pub fn munlock(address: [*]const u8, length: usize) usize {
1022+
return syscall2(.munlock, @intFromPtr(address), length);
1023+
}
1024+
1025+
pub const MLOCK = packed struct(u32) {
1026+
ONFAULT: bool = false,
1027+
_1: u31 = 0,
1028+
};
1029+
1030+
pub fn mlock2(address: [*]const u8, length: usize, flags: MLOCK) usize {
1031+
return syscall3(.mlock2, @intFromPtr(address), length, @as(u32, @bitCast(flags)));
1032+
}
1033+
1034+
pub const MCL = if (native_arch.isSPARC() or native_arch.isPowerPC()) packed struct(u32) {
1035+
_0: u13 = 0,
1036+
CURRENT: bool = false,
1037+
FUTURE: bool = false,
1038+
ONFAULT: bool = false,
1039+
_4: u16 = 0,
1040+
} else packed struct(u32) {
1041+
CURRENT: bool = false,
1042+
FUTURE: bool = false,
1043+
ONFAULT: bool = false,
1044+
_3: u29 = 0,
1045+
};
1046+
1047+
pub fn mlockall(flags: MCL) usize {
1048+
return syscall1(.mlockall, @as(u32, @bitCast(flags)));
1049+
}
1050+
1051+
pub fn munlockall() usize {
1052+
return syscall0(.munlockall);
1053+
}
1054+
10171055
pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
10181056
if (@hasField(SYS, "poll")) {
10191057
return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout)));

0 commit comments

Comments
 (0)