mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Make mmap use SYS_mmap2 if it exists
This commit is contained in:
parent
223b773e03
commit
57de61084e
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user