| ... | @@ -1147,6 +1147,11 @@ const LinuxThreadImpl = struct { | ... | @@ -1147,6 +1147,11 @@ const LinuxThreadImpl = struct { |
| 1147 | /// Ported over from musl libc's pthread detached implementation: | 1147 | /// Ported over from musl libc's pthread detached implementation: |
| 1148 | /// https://github.com/ifduyue/musl/search?q=__unmapself | 1148 | /// https://github.com/ifduyue/musl/search?q=__unmapself |
| 1149 | fn freeAndExit(self: *ThreadCompletion) noreturn { | 1149 | fn freeAndExit(self: *ThreadCompletion) noreturn { |
| | 1150 | // If we do not reset the child_tidptr to null here, the kernel would later write the |
| | 1151 | // value zero to that address, which is inside the block we're unmapping below, after |
| | 1152 | // our thread exits. This can sometimes corrupt memory in other mmap blocks from |
| | 1153 | // unrelated concurrent threads. |
| | 1154 | _ = linux.set_tid_address(null); |
| 1150 | // If a signal were delivered between SYS_munmap and SYS_exit, any installed signal | 1155 | // If a signal were delivered between SYS_munmap and SYS_exit, any installed signal |
| 1151 | // handler would immediately segfault due to the stack being unmapped. To avoid this, | 1156 | // handler would immediately segfault due to the stack being unmapped. To avoid this, |
| 1152 | // we need to mask all signals before entering the inline asm. | 1157 | // we need to mask all signals before entering the inline asm. |
| ... | @@ -1484,7 +1489,7 @@ const LinuxThreadImpl = struct { | ... | @@ -1484,7 +1489,7 @@ const LinuxThreadImpl = struct { |
| 1484 | } | 1489 | } |
| 1485 | | 1490 | |
| 1486 | // Prepare the TLS segment and prepare a user_desc struct when needed on x86 | 1491 | // Prepare the TLS segment and prepare a user_desc struct when needed on x86 |
| 1487 | var tls_ptr = linux.tls.prepareArea(mapped[tls_offset..]); | 1492 | var tls_ptr = linux.tls.prepareArea(mapped[tls_offset..][0..linux.tls.area_desc.size]); |
| 1488 | var user_desc: if (target.cpu.arch == .x86) linux.user_desc else void = undefined; | 1493 | var user_desc: if (target.cpu.arch == .x86) linux.user_desc else void = undefined; |
| 1489 | if (target.cpu.arch == .x86) { | 1494 | if (target.cpu.arch == .x86) { |
| 1490 | defer tls_ptr = @intFromPtr(&user_desc); | 1495 | defer tls_ptr = @intFromPtr(&user_desc); |