test(libc): reset errno after the worker thread in guest_errors #1712

Merged
LuisBiceps merged 1 commit from upstream-pr/1712 into main 2026-10-09 08:03:24 +00:00
LuisBiceps commented 2026-10-08 17:21:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LuisBiceps on 2026-10-08T17:21:49Z.


What

guest_errors aborts on Ubuntu 26.04 under WSL2, at its last errno check. strerror_r is not the cause. Guest errno is the host's errno (__error returns &errno), and the test creates and joins a std::thread between setting errno to 13 and that check. Since glibc 2.42, pthread_create first tries madvise(MADV_GUARD_INSTALL) for the new thread's stack guard. Kernels before 6.13, including WSL2's 6.6, reject it, and glibc falls back to mprotect with errno left at EINVAL:

madvise(0x7679469ff000, 4096, MADV_GUARD_INSTALL) = -1 EINVAL (Invalid argument)
mprotect(0x7679469ff000, 4096, PROT_NONE) = 0

A program without any AnyPS5 code shows the same: errno is 22 after the first std::thread is joined; set back to 13, it stays 13 across a second one. POSIX leaves errno unspecified after a successful call, so the test relied on something no host guarantees. CI's ubuntu-latest runner (Ubuntu 24.04, glibc 2.39) does not hit it.

The test now checks errno right after the strerror calls, before the thread, and sets it to 13 again after the join, so every errno check covers only strerror and strerror_r.

Tested

  • Ubuntu 26.04.1 (WSL2, kernel 6.6.87.2), glibc 2.43, GCC 15.2.0, Release, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=ON: guest_errors aborts on main 4b005b22 and passes with this change (--repeat until-fail:3).
  • The changed test fails when strerror_r leaves EINVAL in errno for an unknown number, and when strerror(78) does.
  • Windows 10, MinGW-w64 GCC 15.2.0 (WinLibs 15.2.0posix-14.0.0-ucrt-r7), Release: guest_errors passes (--repeat until-fail:3).
  • python3 tools/check_conventions.py --base upstream/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4790420457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1712). Originally posted by [LuisBiceps](https://github.com/LuisBiceps) on 2026-10-08T17:21:49Z. --- ### What `guest_errors` aborts on Ubuntu 26.04 under WSL2, at its last errno check. `strerror_r` is not the cause. Guest errno is the host's errno (`__error` returns `&errno`), and the test creates and joins a `std::thread` between setting errno to 13 and that check. Since glibc 2.42, `pthread_create` first tries `madvise(MADV_GUARD_INSTALL)` for the new thread's stack guard. Kernels before 6.13, including WSL2's 6.6, reject it, and glibc falls back to `mprotect` with errno left at `EINVAL`: ``` madvise(0x7679469ff000, 4096, MADV_GUARD_INSTALL) = -1 EINVAL (Invalid argument) mprotect(0x7679469ff000, 4096, PROT_NONE) = 0 ``` A program without any AnyPS5 code shows the same: errno is 22 after the first `std::thread` is joined; set back to 13, it stays 13 across a second one. POSIX leaves errno unspecified after a successful call, so the test relied on something no host guarantees. CI's `ubuntu-latest` runner (Ubuntu 24.04, glibc 2.39) does not hit it. The test now checks errno right after the `strerror` calls, before the thread, and sets it to 13 again after the join, so every errno check covers only `strerror` and `strerror_r`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> - Ubuntu 26.04.1 (WSL2, kernel 6.6.87.2), glibc 2.43, GCC 15.2.0, Release, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`: `guest_errors` aborts on `main` 4b005b22 and passes with this change (`--repeat until-fail:3`). - The changed test fails when `strerror_r` leaves `EINVAL` in errno for an unknown number, and when `strerror(78)` does. - Windows 10, MinGW-w64 GCC 15.2.0 (WinLibs `15.2.0posix-14.0.0-ucrt-r7`), Release: `guest_errors` passes (`--repeat until-fail:3`). - `python3 tools/check_conventions.py --base upstream/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1712
No description provided.