Make mmap use SYS_mmap2 if it exists

This commit is contained in:
Robin Voetter 2019-08-29 00:55:22 +02:00
parent 223b773e03
commit 57de61084e
2 changed files with 7 additions and 1 deletions

View File

@ -397,6 +397,8 @@ pub const SYS_usr32 = 0x0f0004;
pub const SYS_set_tls = 0x0f0005;
pub const SYS_get_tls = 0x0f0006;
pub const MMAP2_UNIT = 4096;
pub const O_CREAT = 0o100;
pub const O_EXCL = 0o200;
pub const O_NOCTTY = 0o400;

View File

@ -190,7 +190,11 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
}
pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
if (@hasDecl(@This(), "SYS_mmap2")) {
return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, @divTrunc(offset, MMAP2_UNIT)));
} else {
return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
}
}
pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {