authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-08-29 00:55:22+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-08-29 00:55:22+02:00
log57de61084e1a805838243e5428e774a591197454
treeb9b102bd55050fae200b9b5a61ac6d1f50dda702
parent223b773e038b7af6ee1dec1c69836c135049d1ba

Make mmap use SYS_mmap2 if it exists


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

std/os/bits/linux/arm-eabi.zig+2
...@@ -397,6 +397,8 @@ pub const SYS_usr32 = 0x0f0004;...@@ -397,6 +397,8 @@ pub const SYS_usr32 = 0x0f0004;
397pub const SYS_set_tls = 0x0f0005;397pub const SYS_set_tls = 0x0f0005;
398pub const SYS_get_tls = 0x0f0006;398pub const SYS_get_tls = 0x0f0006;
399399
400pub const MMAP2_UNIT = 4096;
401
400pub const O_CREAT = 0o100;402pub const O_CREAT = 0o100;
401pub const O_EXCL = 0o200;403pub const O_EXCL = 0o200;
402pub const O_NOCTTY = 0o400;404pub const O_NOCTTY = 0o400;
std/os/linux.zig+5-1
...@@ -190,7 +190,11 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {...@@ -190,7 +190,11 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
190}190}
191191
192pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {192pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
193 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));193 if (@hasDecl(@This(), "SYS_mmap2")) {
194 return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, @divTrunc(offset, MMAP2_UNIT)));
195 } else {
196 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
197 }
194}198}
195199
196pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {200pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {