mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
std: Implement on-demand TLS allocation
This commit is contained in:
parent
d8ab301aa8
commit
cfcf02489d
@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const posix = std.posix;
|
||||
const posix = std.os.posix;
|
||||
const elf = std.elf;
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
@ -234,9 +234,18 @@ pub fn copyTLS(addr: usize) usize {
|
||||
return addr + tls_img.tcb_offset + tls_tp_offset;
|
||||
}
|
||||
|
||||
var main_thread_tls_buffer: [64]u8 align(32) = undefined;
|
||||
var main_thread_tls_buffer: [256]u8 align(32) = undefined;
|
||||
|
||||
pub fn allocateTLS(size: usize) usize {
|
||||
assert(size < main_thread_tls_buffer.len);
|
||||
return @ptrToInt(&main_thread_tls_buffer);
|
||||
// Small TLS allocation, use our local buffer
|
||||
if (size < main_thread_tls_buffer.len) {
|
||||
return @ptrToInt(&main_thread_tls_buffer);
|
||||
}
|
||||
|
||||
const addr = posix.mmap(null, size, posix.PROT_READ | posix.PROT_WRITE,
|
||||
posix.MAP_PRIVATE | posix.MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
if (posix.getErrno(addr) != 0) @panic("allocateTLS failed to allocate memory");
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user