Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.os.linux.tls: Refactor, improve documentation, fix a bug, and port to more architectures #20857

Merged
merged 8 commits into from
Aug 1, 2024
8 changes: 4 additions & 4 deletions lib/std/Thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,9 @@ const LinuxThreadImpl = struct {
bytes = std.mem.alignForward(usize, bytes, page_size);
stack_offset = bytes;

bytes = std.mem.alignForward(usize, bytes, linux.tls.tls_image.alloc_align);
bytes = std.mem.alignForward(usize, bytes, linux.tls.area_desc.alignment);
tls_offset = bytes;
bytes += linux.tls.tls_image.alloc_size;
bytes += linux.tls.area_desc.size;

bytes = std.mem.alignForward(usize, bytes, @alignOf(Instance));
instance_offset = bytes;
Expand Down Expand Up @@ -1304,12 +1304,12 @@ const LinuxThreadImpl = struct {
};

// Prepare the TLS segment and prepare a user_desc struct when needed on x86
var tls_ptr = linux.tls.prepareTLS(mapped[tls_offset..]);
var tls_ptr = linux.tls.prepareArea(mapped[tls_offset..]);
var user_desc: if (target.cpu.arch == .x86) linux.user_desc else void = undefined;
if (target.cpu.arch == .x86) {
defer tls_ptr = @intFromPtr(&user_desc);
user_desc = .{
.entry_number = linux.tls.tls_image.gdt_entry_number,
.entry_number = linux.tls.area_desc.gdt_entry_number,
.base_addr = tls_ptr,
.limit = 0xfffff,
.flags = .{
Expand Down
Loading