DoxigAlpha

initStatic

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.

Function parameters

Parameters

#
phdrs:[]elf.Phdr

Functions in this namespace

Functions

#
prepareArea
Initializes all the fields of the static TLS area and returns the computed architecture-specific
initStatic
Computes the layout of the static TLS area, allocates the area, initializes all of its fields,

Constants and values in this namespace

Values

#

Source

Implementation

#
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_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);

        // 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);
}