@@ -508,14 +508,7 @@ pub fn initStatic(phdrs: []elf.Phdr) void {
508
508
break :blk main_thread_area_buffer [0.. area_desc .size ];
509
509
}
510
510
511
- const begin_addr = mmap (
512
- null ,
513
- area_desc .size + area_desc .alignment - 1 ,
514
- posix .PROT .READ | posix .PROT .WRITE ,
515
- .{ .TYPE = .PRIVATE , .ANONYMOUS = true },
516
- -1 ,
517
- 0 ,
518
- );
511
+ const begin_addr = mmap_tls (area_desc .size + area_desc .alignment - 1 );
519
512
if (@call (.always_inline , linux .E .init , .{begin_addr }) != .SUCCESS ) @trap ();
520
513
521
514
const area_ptr : [* ]align (page_size_min ) u8 = @ptrFromInt (begin_addr );
@@ -530,38 +523,41 @@ pub fn initStatic(phdrs: []elf.Phdr) void {
530
523
setThreadPointer (tp_value );
531
524
}
532
525
533
- inline fn mmap (address : ? [* ]u8 , length : usize , prot : usize , flags : linux.MAP , fd : i32 , offset : i64 ) usize {
526
+ inline fn mmap_tls (length : usize ) usize {
527
+ const prot = posix .PROT .READ | posix .PROT .WRITE ;
528
+ const flags : linux.MAP = .{ .TYPE = .PRIVATE , .ANONYMOUS = true };
529
+
534
530
if (@hasField (linux .SYS , "mmap2" )) {
535
531
return @call (.always_inline , linux .syscall6 , .{
536
532
.mmap2 ,
537
- @intFromPtr ( address ) ,
533
+ 0 ,
538
534
length ,
539
535
prot ,
540
536
@as (u32 , @bitCast (flags )),
541
- @as (usize , @bitCast (@as (isize , fd ))),
542
- @as ( usize , @truncate ( @as ( u64 , @bitCast ( offset )) / linux . MMAP2_UNIT )) ,
537
+ @as (usize , @bitCast (@as (isize , -1 ))),
538
+ 0 ,
543
539
});
544
540
} else {
545
541
// The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so
546
542
// it takes a single pointer to an array of arguments instead.
547
543
return if (native_arch == .s390x ) @call (.always_inline , linux .syscall1 , .{
548
544
.mmap ,
549
545
@intFromPtr (&[_ ]usize {
550
- @intFromPtr ( address ) ,
546
+ 0 ,
551
547
length ,
552
548
prot ,
553
549
@as (u32 , @bitCast (flags )),
554
- @as (usize , @bitCast (@as (isize , fd ))),
555
- @as ( u64 , @bitCast ( offset )) ,
550
+ @as (usize , @bitCast (@as (isize , -1 ))),
551
+ 0 ,
556
552
}),
557
553
}) else @call (.always_inline , linux .syscall6 , .{
558
554
.mmap ,
559
- @intFromPtr ( address ) ,
555
+ 0 ,
560
556
length ,
561
557
prot ,
562
558
@as (u32 , @bitCast (flags )),
563
- @as (usize , @bitCast (@as (isize , fd ))),
564
- @as ( u64 , @bitCast ( offset )) ,
559
+ @as (usize , @bitCast (@as (isize , -1 ))),
560
+ 0 ,
565
561
});
566
562
}
567
563
}
0 commit comments