mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Avoid truncating mmap2 offsets if not multiple of page size
This commit is contained in:
parent
805f9b309b
commit
5aaa7d0fbb
1 changed files with 22 additions and 2 deletions
|
|
@ -193,9 +193,29 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
|
|||
|
||||
pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize {
|
||||
if (@hasDecl(@This(), "SYS_mmap2")) {
|
||||
return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @truncate(usize, offset / MMAP2_UNIT));
|
||||
// Make sure the offset is also specified in multiples of page size
|
||||
if ((offset & (MMAP2_UNIT - 1)) != 0)
|
||||
return @bitCast(usize, isize(-EINVAL));
|
||||
|
||||
return syscall6(
|
||||
SYS_mmap2,
|
||||
@ptrToInt(address),
|
||||
length,
|
||||
prot,
|
||||
flags,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@truncate(usize, offset / MMAP2_UNIT),
|
||||
);
|
||||
} else {
|
||||
return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), offset);
|
||||
return syscall6(
|
||||
SYS_mmap,
|
||||
@ptrToInt(address),
|
||||
length,
|
||||
prot,
|
||||
flags,
|
||||
@bitCast(usize, isize(fd)),
|
||||
offset,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue