diff --git a/lib/std/c.zig b/lib/std/c.zig index fc5497a5be3dbf833aad929799f6befa3be2e620..8e50eb979264a6f143d12de6e58861cc58520098 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -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, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 4cf305bb203eb68f3e7a7aae9e0d29bb09638155..04dc452c0cbc7aeb12f65f3252287e4596c185f9 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -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 diff --git a/lib/std/os/linux/arm.zig b/lib/std/os/linux/arm.zig index 10561da27077663227c72852b217850306430930..8f83bb60a1bacc8177ec049e6cbaff93baaf89ca 100644 --- a/lib/std/os/linux/arm.zig +++ b/lib/std/os/linux/arm.zig @@ -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; diff --git a/lib/std/os/linux/hexagon.zig b/lib/std/os/linux/hexagon.zig index b6549fe4a9931b6a5ef26ed4f16eb2b87485eff7..dcc19cd96b445807a4abba75527bde279189c3ca 100644 --- a/lib/std/os/linux/hexagon.zig +++ b/lib/std/os/linux/hexagon.zig @@ -251,8 +251,6 @@ pub const Stat = extern struct { pub const Elf_Symndx = u32; -pub const MMAP2_UNIT = 4096; - pub const VDSO = void; /// TODO diff --git a/lib/std/os/linux/m68k.zig b/lib/std/os/linux/m68k.zig index 95277223c9a562096fa5dc98476bbb8ed6a45208..0b89c329a8f5f68837911959f7ae2c06ba00b6ee 100644 --- a/lib/std/os/linux/m68k.zig +++ b/lib/std/os/linux/m68k.zig @@ -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; diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index b31d5e4fede0e654f908afedc50996255bfe0cc8..ed87b4f734641a70b4561ae89da5112605fd55a9 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -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"; diff --git a/lib/std/os/linux/mips64.zig b/lib/std/os/linux/mips64.zig index 393d71dffe3edefe14a1eaa2cfaa003cdd8633c1..11148fd5c9e7ece4f9bca2f7e1f45dcbd5cad69f 100644 --- a/lib/std/os/linux/mips64.zig +++ b/lib/std/os/linux/mips64.zig @@ -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"; diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index 200744ce2d2d46d10f639965a6d949657dfd43e4..443a32769ab59b39942378f938720b1c087d6272 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -348,7 +348,5 @@ pub const ucontext_t = extern struct { pub const Elf_Symndx = u32; -pub const MMAP2_UNIT = 4096; - /// TODO pub const getcontext = {}; diff --git a/lib/std/os/linux/riscv32.zig b/lib/std/os/linux/riscv32.zig index f9240ceafc44922453f9ecb410f9fa55436fd4ea..c37b0ee76cd1a9b7a2638a75b146b95a8555b16d 100644 --- a/lib/std/os/linux/riscv32.zig +++ b/lib/std/os/linux/riscv32.zig @@ -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"; diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index fdaac29e5dab78308527c24e0dedca22674841cb..3587512e6579a6f7b6691626c5f97cf32a3cf17e 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -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, }); } } diff --git a/lib/std/os/linux/x86.zig b/lib/std/os/linux/x86.zig index 4b4c76a4cab3819a59590c9c119f4f1bd6b655e7..cef038820616799bbb5dde7083c6530cfcf0fc83 100644 --- a/lib/std/os/linux/x86.zig +++ b/lib/std/os/linux/x86.zig @@ -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"; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 2399fbc9c8e629f37d18a908c660385badf51e68..c693393ae24f161042eef612f09c7d86ecce54c3 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -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;