| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | | const posix = std.posix; |
| 3 | const posix = std.os.posix; |
| 4 | 4 | const elf = std.elf; |
| 5 | 5 | const builtin = @import("builtin"); |
| 6 | 6 | const assert = std.debug.assert; |
| ... | ... | @@ -234,9 +234,18 @@ pub fn copyTLS(addr: usize) usize { |
| 234 | 234 | return addr + tls_img.tcb_offset + tls_tp_offset; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | | var main_thread_tls_buffer: [64]u8 align(32) = undefined; |
| 237 | var main_thread_tls_buffer: [256]u8 align(32) = undefined; |
| 238 | 238 | |
| 239 | 239 | pub fn allocateTLS(size: usize) usize { |
| 240 | | assert(size < main_thread_tls_buffer.len); |
| 241 | | return @ptrToInt(&main_thread_tls_buffer); |
| 240 | // Small TLS allocation, use our local buffer |
| 241 | if (size < main_thread_tls_buffer.len) { |
| 242 | return @ptrToInt(&main_thread_tls_buffer); |
| 243 | } |
| 244 | |
| 245 | const addr = posix.mmap(null, size, posix.PROT_READ | posix.PROT_WRITE, |
| 246 | posix.MAP_PRIVATE | posix.MAP_ANONYMOUS, -1, 0); |
| 247 | |
| 248 | if (posix.getErrno(addr) != 0) @panic("allocateTLS failed to allocate memory"); |
| 249 | |
| 250 | return addr; |
| 242 | 251 | } |