Zig 0.17.0-dev (Split by item) 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.
std › Io › Uring › fileMemoryMapSetLength Private Function fileMemoryMapSetLength Doc Source Private Function std.Io.Uring.fileMemoryMapSetLength
fn fileMemoryMapSetLength (
userdata : ?*anyopaque ,
mm : *File .MemoryMap ,
new_len : usize ,
) File .MemoryMap .SetLengthError !void Params userdata : ?*anyopaque mm : *File .MemoryMap new_len : usize File Io/Uring.zig: 4077
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111 fn fileMemoryMapSetLength (
userdata : ?*anyopaque ,
mm : *File .MemoryMap ,
new_len : usize ,
) File .MemoryMap .SetLengthError !void {
const ev : *Evented = @ptrCast (@alignCast (userdata ));
const page_size = std .heap .pageSize ();
const alignment : Alignment = .fromByteUnits (page_size );
const page_align = std .heap .page_size_min ;
const old_memory = mm .memory ;
if (alignment .forward (new_len ) == alignment .forward (old_memory .len )) {
mm .memory .len = new_len ;
return ;
}
const flags : linux .MREMAP = .{ .MAYMOVE = true };
const addr_hint : ?[*]const u8 = null ;
var sync : CancelRegion .Sync = try .init (ev );
defer sync .deinit (ev );
const new_memory = while (true ) {
try sync .cancel_region .await (.nothing );
const rc = linux .mremap (old_memory .ptr , old_memory .len , new_len , flags , addr_hint );
switch (linux .errno (rc )) {
.SUCCESS => break @as ([*]align (page_align ) u8 , @ptrFromInt (rc ))[0 ..new_len ],
.INTR => {},
.AGAIN => return error .LockedMemoryLimitExceeded ,
.NOMEM => return error .OutOfMemory ,
.INVAL => |err | return errnoBug (err ),
.FAULT => |err | return errnoBug (err ),
else => |err | return unexpectedErrno (err ),
}
};
mm .memory = new_memory ;
}