Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

madvise

Public Function
std.posix.madvise
pub fn madvise(ptr: [*]align(page_size_min) u8, length: usize, advice: u32) MadviseError!void

Give advice about use of memory. This syscall is optional and is sometimes configured to be disabled.

Params

Errors

AccessDenied

advice is MADV.REMOVE, but the specified address range is not a shared writable mapping.

PermissionDenied

advice is MADV.HWPOISON, but the caller does not have the CAP_SYS_ADMIN capability.

SystemResources

A kernel resource was temporarily unavailable.

InvalidSyscall

One of the following:

  • addr is not page-aligned or length is negative
  • advice is not valid
  • advice is MADV.DONTNEED or MADV.REMOVE and the specified address range includes locked, Huge TLB pages, or VM_PFNMAP pages.
  • advice is MADV.MERGEABLE or MADV.UNMERGEABLE, but the kernel was not configured with CONFIG_KSM.
  • advice is MADV.FREE or MADV.WIPEONFORK but the specified address range includes file, Huge TLB, MAP.SHARED, or VM_PFNMAP ranges.
WouldExceedMaximumResidentSetSize

(for MADV.WILLNEED) Paging in this area would exceed the process's maximum resident set size.

OutOfMemory

One of the following:

  • (for MADV.WILLNEED) Not enough memory: paging in failed.
  • Addresses in the specified range are not currently mapped, or are outside the address space of the process.
MadviseUnavailable

The madvise syscall is not available on this version and configuration of the Linux kernel.

Unexpected

The operating system returned an undocumented error code.

File

posix.zig:1408
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
pub fn madvise(ptr: [*]align(page_size_min) u8, length: usize, advice: u32) MadviseError!void {
    switch (errno(system.madvise(ptr, length, advice))) {
        .SUCCESS => return,
        .PERM => return error.PermissionDenied,
        .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 unexpectedErrno(err),
    }
}