| ... | @@ -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 { |
| 193 | | 193 | |
| 194 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize { | 194 | pub 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 | } |
| 201 | | 221 | |