# std.Thread: stop clobbering syscall args · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/0cbaaa5eb9434eb9484bae95949a4086eb472c6a)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 0cbaaa5eb9434eb9484bae95949a4086eb472c6a

Requested commit: 0cbaaa5eb9434eb9484bae95949a4086eb472c6a

Commit: 0cbaaa5eb9434eb9484bae95949a4086eb472c6a

Tree: 9906a8175864cf8f36657cb78706c3b6cd79440f

Author: Matthew Lugg

Committer: mlugg

## Message

```
std.Thread: stop clobbering syscall args

TL;DR: "r" considered harmful.

If LLVM chose registers badly, the inline asm which cleans up a thread
on Linux could, on all architectures other than x86_64, clobber either
`munmap` argument with the other argument *or* with the syscall number.
This would cause munmap to return EINVAL, and we would literally *never*
free the thread memory, which isn't ideal.

As it turns out, this was happening on MIPS, and was the cause of the
failures we've recently been seeing for that target: QEMU genuinely was
running out of memory (or at least, the virtualized address space was
getting too fragmented to map many contiguous pages). I've therefore
re-enabled a test which was disabled due to that flakiness.

This bug was accidentally fixed for x86_64 back in 2022 (see 59e33b447),
which probably helped it to go unnoticed for as long as it did!

Resolves: https://codeberg.org/ziglang/zig/issues/30216

```

## Parents

- [a0a982f0ea617fa6c74695976b5cfdfd6f9f8b33](https://git.cafe/gitcafe/zig/commit/a0a982f0ea617fa6c74695976b5cfdfd6f9f8b33?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/0cbaaa5eb9434eb9484bae95949a4086eb472c6a?format=markdown)
