authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-09-27 18:18:38+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-09-27 18:18:38+02:00
log5aaa7d0fbb885db646ebd6557afc8def93ff860f
tree9da513b5b0e04f317fc79deea15bf50c2c6b001e
parent805f9b309bee2d1a6c4fa34f1bc2746a8e60c35f

Avoid truncating mmap2 offsets if not multiple of page size


1 files changed, 22 insertions(+), 2 deletions(-)

lib/std/os/linux.zig+22-2
...@@ -193,9 +193,29 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {...@@ -193,9 +193,29 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
193193
194pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize {194pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize {
195 if (@hasDecl(@This(), "SYS_mmap2")) {195 if (@hasDecl(@This(), "SYS_mmap2")) {
196 return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @truncate(usize, offset / MMAP2_UNIT));196 // Make sure the offset is also specified in multiples of page size
197 if ((offset & (MMAP2_UNIT - 1)) != 0)
198 return @bitCast(usize, isize(-EINVAL));
199
200 return syscall6(
201 SYS_mmap2,
202 @ptrToInt(address),
203 length,
204 prot,
205 flags,
206 @bitCast(usize, isize(fd)),
207 @truncate(usize, offset / MMAP2_UNIT),
208 );
197 } else {209 } else {
198 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), offset);210 return syscall6(
211 SYS_mmap,
212 @ptrToInt(address),
213 length,
214 prot,
215 flags,
216 @bitCast(usize, isize(fd)),
217 offset,
218 );
199 }219 }
200}220}
201221