# Fix illegal behavior from syscalls on powerpc64le · gitcafe/zig

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

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

Visibility: public

Requested revision: 79807468e747bac056cfea4340065e49a5d97120

Requested commit: 79807468e747bac056cfea4340065e49a5d97120

Commit: 79807468e747bac056cfea4340065e49a5d97120

Tree: 7e5e328c249d73527b425c3c45df20c542c876d3

Author: taylor.fish

Committer: taylor.fish

## Message

```
Fix illegal behavior from syscalls on powerpc64le

On powerpc64le Linux, the registers used for passing syscall parameters
(r4-r8, as well as r0 for the syscall number) are volatile, or
caller-saved. However, Zig's syscall wrappers for this architecture do
not include all such registers in the list of clobbers, leading the
compiler to assume these registers will maintain their values after the
syscall completes.

In practice, this resulted in a segfault when allocating memory with
`std.heap.SmpAllocator`, which calls `std.os.linux.sched_getaffinity`.
The third parameter to `sched_getaffinity` is a pointer to a `cpu_set_t`
and is stored in register r5. After the syscall, the code attempts to
access data in the `cpu_set_t`, but because the compiler doesn't realize
the value of r5 may have changed, it uses r5 as the memory address, which
in practice resulted in a memory access at address 0x8.

This commit adds all volatile registers to the list of clobbers.

```

## Parents

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

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