mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.os.linux: use heap.pageSize() instead of MMAP2_UNIT
This commit is contained in:
parent
6fd358d287
commit
bcb4ba9afd
12 changed files with 15 additions and 43 deletions
|
|
@ -1601,10 +1601,6 @@ pub const MSF = switch (native_os) {
|
|||
},
|
||||
else => void,
|
||||
};
|
||||
pub const MMAP2_UNIT = switch (native_os) {
|
||||
.linux => linux.MMAP2_UNIT,
|
||||
else => void,
|
||||
};
|
||||
pub const NAME_MAX = switch (native_os) {
|
||||
.linux => linux.NAME_MAX,
|
||||
.emscripten => emscripten.NAME_MAX,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx;
|
|||
pub const F = arch_bits.F;
|
||||
pub const Flock = arch_bits.Flock;
|
||||
pub const HWCAP = arch_bits.HWCAP;
|
||||
pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT;
|
||||
pub const REG = arch_bits.REG;
|
||||
pub const SC = arch_bits.SC;
|
||||
pub const Stat = arch_bits.Stat;
|
||||
|
|
@ -928,7 +927,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: MAP, fd: i32, of
|
|||
prot,
|
||||
@as(u32, @bitCast(flags)),
|
||||
@bitCast(@as(isize, fd)),
|
||||
@truncate(@as(u64, @bitCast(offset)) / MMAP2_UNIT),
|
||||
@truncate(@as(u64, @bitCast(offset)) / std.heap.pageSize()),
|
||||
);
|
||||
} else {
|
||||
// The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so
|
||||
|
|
|
|||
|
|
@ -170,8 +170,6 @@ pub fn restore_rt() callconv(.naked) noreturn {
|
|||
}
|
||||
}
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const F = struct {
|
||||
pub const DUPFD = 0;
|
||||
pub const GETFD = 1;
|
||||
|
|
|
|||
|
|
@ -251,8 +251,6 @@ pub const Stat = extern struct {
|
|||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO = void;
|
||||
|
||||
/// TODO
|
||||
|
|
|
|||
|
|
@ -261,10 +261,6 @@ pub const Stat = extern struct {
|
|||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
// m68k has multiple minimum page sizes.
|
||||
// glibc sets MMAP2_PAGE_UNIT to -1 so it is queried at runtime.
|
||||
pub const MMAP2_UNIT = -1;
|
||||
|
||||
// No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6.
|
||||
pub const VDSO = void;
|
||||
|
||||
|
|
|
|||
|
|
@ -294,8 +294,6 @@ pub const F = struct {
|
|||
pub const GETOWNER_UIDS = 17;
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6";
|
||||
|
|
|
|||
|
|
@ -273,8 +273,6 @@ pub const F = struct {
|
|||
pub const GETOWNER_UIDS = 17;
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6";
|
||||
|
|
|
|||
|
|
@ -348,7 +348,5 @@ pub const ucontext_t = extern struct {
|
|||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
|
|
|||
|
|
@ -256,8 +256,6 @@ pub const Stat = extern struct {
|
|||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_4.15";
|
||||
|
|
|
|||
|
|
@ -508,14 +508,7 @@ pub fn initStatic(phdrs: []elf.Phdr) void {
|
|||
break :blk main_thread_area_buffer[0..area_desc.size];
|
||||
}
|
||||
|
||||
const begin_addr = mmap(
|
||||
null,
|
||||
area_desc.size + area_desc.alignment - 1,
|
||||
posix.PROT.READ | posix.PROT.WRITE,
|
||||
.{ .TYPE = .PRIVATE, .ANONYMOUS = true },
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
const begin_addr = mmap_tls(area_desc.size + area_desc.alignment - 1);
|
||||
if (@call(.always_inline, linux.E.init, .{begin_addr}) != .SUCCESS) @trap();
|
||||
|
||||
const area_ptr: [*]align(page_size_min) u8 = @ptrFromInt(begin_addr);
|
||||
|
|
@ -530,16 +523,19 @@ pub fn initStatic(phdrs: []elf.Phdr) void {
|
|||
setThreadPointer(tp_value);
|
||||
}
|
||||
|
||||
inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd: i32, offset: i64) usize {
|
||||
inline fn mmap_tls(length: usize) usize {
|
||||
const prot = posix.PROT.READ | posix.PROT.WRITE;
|
||||
const flags: linux.MAP = .{ .TYPE = .PRIVATE, .ANONYMOUS = true };
|
||||
|
||||
if (@hasField(linux.SYS, "mmap2")) {
|
||||
return @call(.always_inline, linux.syscall6, .{
|
||||
.mmap2,
|
||||
@intFromPtr(address),
|
||||
0,
|
||||
length,
|
||||
prot,
|
||||
@as(u32, @bitCast(flags)),
|
||||
@as(usize, @bitCast(@as(isize, fd))),
|
||||
@as(usize, @truncate(@as(u64, @bitCast(offset)) / linux.MMAP2_UNIT)),
|
||||
@as(usize, @bitCast(@as(isize, -1))),
|
||||
0,
|
||||
});
|
||||
} else {
|
||||
// The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so
|
||||
|
|
@ -547,21 +543,21 @@ inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd
|
|||
return if (native_arch == .s390x) @call(.always_inline, linux.syscall1, .{
|
||||
.mmap,
|
||||
@intFromPtr(&[_]usize{
|
||||
@intFromPtr(address),
|
||||
0,
|
||||
length,
|
||||
prot,
|
||||
@as(u32, @bitCast(flags)),
|
||||
@as(usize, @bitCast(@as(isize, fd))),
|
||||
@as(u64, @bitCast(offset)),
|
||||
@as(usize, @bitCast(@as(isize, -1))),
|
||||
0,
|
||||
}),
|
||||
}) else @call(.always_inline, linux.syscall6, .{
|
||||
.mmap,
|
||||
@intFromPtr(address),
|
||||
0,
|
||||
length,
|
||||
prot,
|
||||
@as(u32, @bitCast(flags)),
|
||||
@as(usize, @bitCast(@as(isize, fd))),
|
||||
@as(u64, @bitCast(offset)),
|
||||
@as(usize, @bitCast(@as(isize, -1))),
|
||||
0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,8 +230,6 @@ pub const F = struct {
|
|||
pub const UNLCK = 2;
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6";
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ pub const MADV = system.MADV;
|
|||
pub const MAP = system.MAP;
|
||||
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
|
||||
pub const MFD = system.MFD;
|
||||
pub const MMAP2_UNIT = system.MMAP2_UNIT;
|
||||
pub const MREMAP = system.MREMAP;
|
||||
pub const MSF = system.MSF;
|
||||
pub const MSG = system.MSG;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue