Function initStatic [src]

Computes the layout of the static TLS area, allocates the area, initializes all of its fields, and assigns the architecture-specific value to the TP register.

Prototype

pub fn initStatic(phdrs: []elf.Phdr) void

Parameters

phdrs: []elf.Phdr

Source

pub fn initStatic(phdrs: []elf.Phdr) void { @setRuntimeSafety(false); @disableInstrumentation(); computeAreaDesc(phdrs); const area = blk: { // Fast path for the common case where the TLS data is really small, avoid an allocation and // use our local buffer. if (area_desc.alignment <= page_size_min and area_desc.size <= main_thread_area_buffer.len) { 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, ); if (@as(isize, @bitCast(begin_addr)) < 0) @trap(); const area_ptr: [*]align(page_size_min) u8 = @ptrFromInt(begin_addr); // Make sure the slice is correctly aligned. const begin_aligned_addr = alignForward(begin_addr, area_desc.alignment); const start = begin_aligned_addr - begin_addr; break :blk area_ptr[start..][0..area_desc.size]; }; const tp_value = prepareArea(area); setThreadPointer(tp_value); }