| author | |
| committer | |
| log | 348751462632234f2bee10f5faad3711eff89172 |
| tree | c3e32c4b93cab79e6140f61b39f9c915d0f7f2ca |
| parent | 3e467c778a83fac08ae2f124af05a4cf6dc95470 |
The mincore syscall is available on some UNIX like operating systems
and allows a user to determine if a page is resident in memory.3 files changed, 39 insertions(+), 0 deletions(-)
lib/std/c/linux.zig+6| ... | ... | @@ -289,6 +289,12 @@ pub extern "c" fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: *con |
| 289 | 289 | pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int; |
| 290 | 290 | pub extern "c" fn malloc_usable_size(?*const anyopaque) usize; |
| 291 | 291 | |
| 292 | pub extern "c" fn mincore( | |
| 293 | addr: *align(std.mem.page_size) anyopaque, | |
| 294 | length: usize, | |
| 295 | vec: [*]u8, | |
| 296 | ) c_int; | |
| 297 | ||
| 292 | 298 | pub extern "c" fn madvise( |
| 293 | 299 | addr: *align(std.mem.page_size) anyopaque, |
| 294 | 300 | length: usize, |
lib/std/os.zig+29| ... | ... | @@ -6974,6 +6974,35 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void |
| 6974 | 6974 | } |
| 6975 | 6975 | } |
| 6976 | 6976 | |
| 6977 | pub const MincoreError = error{ | |
| 6978 | /// A kernel resource was temporarily unavailable. | |
| 6979 | SystemResources, | |
| 6980 | /// vec points to an invalid address. | |
| 6981 | InvalidAddress, | |
| 6982 | /// addr is not page-aligned. | |
| 6983 | InvalidSyscall, | |
| 6984 | /// One of the following: | |
| 6985 | /// * length is greater than user space TASK_SIZE - addr | |
| 6986 | /// * addr + length contains unmapped memory | |
| 6987 | OutOfMemory, | |
| 6988 | /// The mincore syscall is not available on this version and configuration | |
| 6989 | /// of this UNIX-like kernel. | |
| 6990 | MincoreUnavailable, | |
| 6991 | } || UnexpectedError; | |
| 6992 | ||
| 6993 | /// Determine whether pages are resident in memory. | |
| 6994 | pub fn mincore(ptr: [*]align(mem.page_size) u8, length: usize, vec: [*]u8) MincoreError!void { | |
| 6995 | return switch (errno(system.mincore(ptr, length, vec))) { | |
| 6996 | .SUCCESS => {}, | |
| 6997 | .AGAIN => error.SystemResources, | |
| 6998 | .FAULT => error.InvalidAddress, | |
| 6999 | .INVAL => error.InvalidSyscall, | |
| 7000 | .NOMEM => error.OutOfMemory, | |
| 7001 | .NOSYS => error.MincoreUnavailable, | |
| 7002 | else => |err| unexpectedErrno(err), | |
| 7003 | }; | |
| 7004 | } | |
| 7005 | ||
| 6977 | 7006 | pub const MadviseError = error{ |
| 6978 | 7007 | /// advice is MADV.REMOVE, but the specified address range is not a shared writable mapping. |
| 6979 | 7008 | AccessDenied, |
lib/std/os/linux.zig+4| ... | ... | @@ -1699,6 +1699,10 @@ pub fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: ?*const rlimit, |
| 1699 | 1699 | ); |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | pub fn mincore(address: [*]u8, len: usize, vec: [*]u8) usize { | |
| 1703 | return syscall3(.mincore, @ptrToInt(address), len, @ptrToInt(vec)); | |
| 1704 | } | |
| 1705 | ||
| 1702 | 1706 | pub fn madvise(address: [*]u8, len: usize, advice: u32) usize { |
| 1703 | 1707 | return syscall3(.madvise, @ptrToInt(address), len, advice); |
| 1704 | 1708 | } |