zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 1226bb9268f20740a69afd3097d40b4d3e371647 (tree)
parent 614cd66e7e9b7323dd67bf208fda9abf296721b4
Author: Brandon Black <bblack@wikimedia.org>
Date:   Mon, 30 Mar 2026 07:01:40 -0500

LinuxThreadImpl: be precise in tls.prepareArea arg

This isn't causing any functional problem today, but technically
`mapped[tls_offset..]` runs past the tls part of `mapped` and into
the `Instance` storage, and currently `prepareArea()` memsets its
entire argument to zero.  It is only the current layout and
initialization order of `mapped` that prevents this from being a
problem.  Being more precise here avoids future footguns if any of
that changes.

Diffstat:
Mlib/std/Thread.zig | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig @@ -1489,7 +1489,7 @@ const LinuxThreadImpl = struct { } // Prepare the TLS segment and prepare a user_desc struct when needed on x86 - var tls_ptr = linux.tls.prepareArea(mapped[tls_offset..]); + var tls_ptr = linux.tls.prepareArea(mapped[tls_offset..][0..linux.tls.area_desc.size]); 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);