# std.os.linux: Fix syscall errno value handling for mips\. · gitcafe/zig

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

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

Visibility: public

Requested revision: d4973c992203ed6fb761d3f3b871dd9849541b5a

Requested commit: d4973c992203ed6fb761d3f3b871dd9849541b5a

Commit: d4973c992203ed6fb761d3f3b871dd9849541b5a

Tree: 8dc1a3f1b684ca5526ea78615fdd5f2c77a09ec5

Author: Alex Rønne Petersen

Committer: Alex Rønne Petersen

## Message

```
std.os.linux: Fix syscall errno value handling for mips.

The kernel sets r7 to 0 (success) or -1 (error), and stores the result in r2.
When r7 is -1 and the result is positive, it needs to be negated to get the
errno value that higher-level code, such as errnoFromSyscall(), expects to see.

The old code was missing the check that r2 is positive, but was also doing the
r7 check incorrectly; since it can only be set to 0 or -1, the blez instruction
would always branch.

In practice, this fix is necessary for e.g. the ENOSYS error to be interpreted
correctly. This manifested as hitting an unreachable branch when calling
process_vm_readv() in std.debug.MemoryAccessor.

```

## Parents

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

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