diff options
| author | LemonBoy <thatlemon@gmail.com> | 2019-09-27 18:18:38 +0200 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2019-09-27 18:18:38 +0200 |
| commit | 5aaa7d0fbb885db646ebd6557afc8def93ff860f (patch) | |
| tree | 9da513b5b0e04f317fc79deea15bf50c2c6b001e /lib/std/os/linux.zig | |
| parent | 805f9b309bee2d1a6c4fa34f1bc2746a8e60c35f (diff) | |
| download | zig-5aaa7d0fbb885db646ebd6557afc8def93ff860f.tar.gz zig-5aaa7d0fbb885db646ebd6557afc8def93ff860f.zip | |
Avoid truncating mmap2 offsets if not multiple of page size
Diffstat (limited to 'lib/std/os/linux.zig')
| -rw-r--r-- | lib/std/os/linux.zig | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index eb2f71cf99..9550518842 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -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, + ); } } |
