feat(libc): implement qsort_s #6707

Merged
karimibrahim07 merged 2 commits from upstream-pr/6707 into main 2026-10-19 09:47:04 +00:00
karimibrahim07 commented 2026-10-16 05:41:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T05:41:38Z.


What

qsort_s (C11 Annex K, G7yOZJObV+4) was missing. The Quake homebrew's libOSMesa.so.8 imports it (#6698), and with #6697 and #6702 it is that title's last unresolved import.

qsort_s(base, n, es, cmp, context) follows FreeBSD 13's qsort_s. FreeBSD 11, which the rest of libc follows, has none.

  • It sorts with the same algorithm as the existing qsort (FreeBSD's Bentley–McIlroy quicksort) and passes context as the comparator's third argument (CMP(t, x, y) is cmp(x, y, t), L76-L77). The sort helpers now take any comparator, so both functions share the code; qsort is unchanged.
  • It returns EINVAL after calling the constraint handler with FreeBSD's message when n or es exceeds RSIZE_MAX, or when n is not 0 and base or cmp is null (L111-L127). Otherwise it returns 0.
  • An element size of 0 sorts nothing, where FreeBSD loops over the same address.

The handler is the one SonyCrt.hpp keeps per source file. A handler set with set_constraint_handler_s (in WideConversion.cpp) is therefore not the one called here, as for the other _s functions outside that file; the debt entry says so.

Tested

Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON, on main 5d9dcc42d:

  • guest_qsort passes. The new cases check that qsort_s:

    • gives the same order of equal elements as qsort in the insertion-sort and median-of-three cases
    • sorts 50 elements in descending order when the context says so, which checks that the context reaches the comparator
    • returns 0 for n == 0 with a null base and a null comparator
    • leaves zero-size elements untouched

    On main the test does not link (qsort_s_nid_postfix is undefined).

  • The full suite passes, 1300 tests. One conventions_function_bodies shard timed out while the machine was busy and passed alone. python tools/check_conventions.py --base origin/main passes.

  • Merges cleanly with the open PRs that touch FileAndHeap.cpp, docs/dev/debt/libc.md or GuestQsort.cpp. The debt entry sits after set_constraint_handler_s because #6144 and #6322 edit the lines on both sides of the qsort entry.

The Quake homebrew (#6698), with #6697, #6702 and this PR, relinked with --windows --to-intel --trap-sdk-syscall-stubs --registry: no unresolved ELF import is left, and the title runs into its own code. It then stops with application heap: process metadata is missing; relink the executable, because a payload ELF has no PT_SCE_PROCPARAM segment and so no allocator table. That is a separate change.

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 under Silent stubs in their library's technical debt file
  • 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 for the change; the Quake evidence needs #6697 and #6702
  • Unblocks: Quake homebrew #6698
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4884050892 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-16T05:41:38Z. --- ### What `qsort_s` (C11 Annex K, `G7yOZJObV+4`) was missing. The Quake homebrew's `libOSMesa.so.8` imports it (#6698), and with #6697 and #6702 it is that title's last unresolved import. `qsort_s(base, n, es, cmp, context)` follows FreeBSD 13's [`qsort_s`](https://github.com/freebsd/freebsd-src/blob/release/13.0.0/lib/libc/stdlib/qsort.c#L97-L127). FreeBSD 11, which the rest of libc follows, has none. - It sorts with the same algorithm as the existing `qsort` (FreeBSD's Bentley–McIlroy quicksort) and passes `context` as the comparator's third argument (`CMP(t, x, y)` is `cmp(x, y, t)`, [L76-L77](https://github.com/freebsd/freebsd-src/blob/release/13.0.0/lib/libc/stdlib/qsort.c#L76-L77)). The sort helpers now take any comparator, so both functions share the code; `qsort` is unchanged. - It returns `EINVAL` after calling the constraint handler with FreeBSD's message when `n` or `es` exceeds `RSIZE_MAX`, or when `n` is not 0 and `base` or `cmp` is null ([L111-L127](https://github.com/freebsd/freebsd-src/blob/release/13.0.0/lib/libc/stdlib/qsort.c#L111-L127)). Otherwise it returns 0. - An element size of 0 sorts nothing, where FreeBSD loops over the same address. The handler is the one `SonyCrt.hpp` keeps per source file. A handler set with `set_constraint_handler_s` (in `WideConversion.cpp`) is therefore not the one called here, as for the other `_s` functions outside that file; the debt entry says so. ### Tested Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release, `BUILD_TESTING=ON`, on `main` `5d9dcc42d`: - `guest_qsort` passes. The new cases check that `qsort_s`: - gives the same order of equal elements as `qsort` in the insertion-sort and median-of-three cases - sorts 50 elements in descending order when the context says so, which checks that the context reaches the comparator - returns 0 for `n == 0` with a null base and a null comparator - leaves zero-size elements untouched On `main` the test does not link (`qsort_s_nid_postfix` is undefined). - The full suite passes, 1300 tests. One `conventions_function_bodies` shard timed out while the machine was busy and passed alone. `python tools/check_conventions.py --base origin/main` passes. - Merges cleanly with the open PRs that touch `FileAndHeap.cpp`, `docs/dev/debt/libc.md` or `GuestQsort.cpp`. The debt entry sits after `set_constraint_handler_s` because #6144 and #6322 edit the lines on both sides of the `qsort` entry. The Quake homebrew (#6698), with #6697, #6702 and this PR, relinked with `--windows --to-intel --trap-sdk-syscall-stubs --registry`: no `unresolved ELF import` is left, and the title runs into its own code. It then stops with `application heap: process metadata is missing; relink the executable`, because a payload ELF has no `PT_SCE_PROCPARAM` segment and so no allocator table. That is a separate change. ### Checklist - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 for the change; the Quake evidence needs #6697 and #6702 - [x] Unblocks: Quake homebrew #6698 - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-16 05:42:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T05:42:18Z.


Progress report (5d9dcc4 → ceec3da)

➖ System libraries: 88.83% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc qsort_s_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208943483 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6208943483). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T05:42:18Z. --- <!-- progress-report --> ### Progress report (5d9dcc4 → ceec3da) ➖ **System libraries**: 88.83% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `qsort_s_nid_postfix` | </details>
MarcZX10 commented 2026-10-16 05:58:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:58:43Z.


One contract issue to consider: SonyCrt.hpp puts SonyConstraintHandlerSlot() in an unnamed namespace, so FileAndHeap.cpp and WideConversion.cpp each get a separate handler slot. That means a handler installed through set_constraint_handler_s is not called for qsort_s runtime-constraint violations; this PR invokes the default handler instance from FileAndHeap.cpp instead. Annex K specifies that these violations call the currently installed constraint handler (C11 draft K.3.6.3.2). Could the handler state be shared across libc translation units, and could a regression test set an ignoring/counting handler then trigger a qsort_s violation? The debt note documents this current limitation, but for this new function it means callers cannot use the handler they registered.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6209140786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6209140786). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T05:58:43Z. --- One contract issue to consider: `SonyCrt.hpp` puts `SonyConstraintHandlerSlot()` in an unnamed namespace, so `FileAndHeap.cpp` and `WideConversion.cpp` each get a separate handler slot. That means a handler installed through `set_constraint_handler_s` is not called for `qsort_s` runtime-constraint violations; this PR invokes the default handler instance from `FileAndHeap.cpp` instead. Annex K specifies that these violations call the currently installed constraint handler ([C11 draft K.3.6.3.2](https://www.cs.hunter.cuny.edu/~sweiss/resources/c11standard.pdf)). Could the handler state be shared across libc translation units, and could a regression test set an ignoring/counting handler then trigger a `qsort_s` violation? The debt note documents this current limitation, but for this new function it means callers cannot use the handler they registered.
UmillD commented 2026-10-16 05:58:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UmillD on 2026-10-16T05:58:48Z.


Independent focused Windows validation on exact head edf4efe360e530f7f3d023889851a2b7124fe798, WinLibs GCC 15.2.0 r7, Ninja Release:

  • The existing guest_qsort CTest passed 10 consecutive runs.
  • A separate harness calling the real guest libc exports with APS5_VABI passed 1,728 combinations of element size/count, unaligned starting offsets, input distributions and ascending/descending context. It checked complete-record preservation, surrounding sentinels, callback addresses/context, and comparison counts/traces.
  • The candidate's qsort matched the main-production-libc control; qsort_s matched the candidate's qsort for every input and trace. The control build includes test-only fixture changes, with no changes in core/libs/prx/libc. Zero-count/null arguments, zero element size and the one-element/no-callback case also passed.

I also reproduced the already documented constraint-handler limitation. With a returning handler installed through set_constraint_handler_s, wcscpy_s(nullptr, 1, nullptr) returned 22 and invoked it once. The four invalid qsort_s cases (count/size above RSIZE_MAX, null base or null comparator with nonzero count) instead reached SIGABRT. The harness intercepted the signal in child processes. This confirms the limitation noted in the PR; it is not a new finding, and I am not claiming those EINVAL-return paths pass.

No additional regression was found within this scope. I did not run Quake, Linux/macOS or the full suite, and this does not verify the console's qsort_s contract. Standalone harness sources and logs are retained locally and can be shared if useful.

AI-assisted: yes, investigated with Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6209141765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6209141765). Originally posted by [UmillD](https://github.com/UmillD) on 2026-10-16T05:58:48Z. --- Independent focused Windows validation on exact head `edf4efe360e530f7f3d023889851a2b7124fe798`, WinLibs GCC 15.2.0 r7, Ninja Release: - The existing `guest_qsort` CTest passed 10 consecutive runs. - A separate harness calling the real guest libc exports with `APS5_VABI` passed 1,728 combinations of element size/count, unaligned starting offsets, input distributions and ascending/descending context. It checked complete-record preservation, surrounding sentinels, callback addresses/context, and comparison counts/traces. - The candidate's `qsort` matched the main-production-libc control; `qsort_s` matched the candidate's `qsort` for every input and trace. The control build includes test-only fixture changes, with no changes in `core/libs/prx/libc`. Zero-count/null arguments, zero element size and the one-element/no-callback case also passed. I also reproduced the already documented constraint-handler limitation. With a returning handler installed through `set_constraint_handler_s`, `wcscpy_s(nullptr, 1, nullptr)` returned 22 and invoked it once. The four invalid `qsort_s` cases (count/size above RSIZE_MAX, null base or null comparator with nonzero count) instead reached SIGABRT. The harness intercepted the signal in child processes. This confirms the limitation noted in the PR; it is not a new finding, and I am not claiming those EINVAL-return paths pass. No additional regression was found within this scope. I did not run Quake, Linux/macOS or the full suite, and this does not verify the console's qsort_s contract. Standalone harness sources and logs are retained locally and can be shared if useful. AI-assisted: yes, investigated with Codex.
jotitadev commented 2026-10-16 06:44:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T06:44:36Z.

Review: COMMENTED


Native Linux run on exact head edf4efe360e530f7f3d023889851a2b7124fe798, applied on main 5d9dcc42d.

Machine: Intel i7-8700 (6C/12T), Ubuntu 26.04, GCC 15.2, Ninja Release, BUILD_TESTING=ON, full build.

  • guest_qsort passes, and 10/10 with --repeat until-fail:10.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 648/650, same as main. The two failures (file_writer_binary, file_writer_text) also fail on main on this machine.
  • With only the test applied to main, guest_qsort_tests does not link (undefined reference to qsort_s_nid_postfix), as the description says.
  • python3 tools/check_conventions.py --base main: passed.

I checked the semantics against the sources:

  • C11 Annex K (N1570 K.3.6.3.2): comparator (x, y, context), no sort and a nonzero return on a violation, and the same four constraints (nmemb/size > RSIZE_MAX, null base or compar when nmemb != 0). They match.
  • The violation messages, their order, EINVAL and RSIZE_MAX = SIZE_MAX >> 1 match FreeBSD 13.0's qsort_s.
  • The importer expects this argument order. Mesa's src/util/u_qsort.h calls qsort_s(base, nmemb, size, compar, arg) with the context last outside _WIN32 ("C11 added qsort_s"). It uses an adapter only for the MSVC/MinGW order, where the context comes first. A non-Windows build that imports qsort_s, and so found no GNU or BSD qsort_r, takes that C11 branch. It passes compar unchanged, so the comparator is called as cmp(x, y, context), which is what this PR does. I have not looked at the binary itself.

I have nothing to add on the constraint-handler point. It is already raised above and recorded in the debt entry.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5543972660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#pullrequestreview-5543972660). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-16T06:44:36Z. **Review:** COMMENTED --- Native Linux run on exact head `edf4efe360e530f7f3d023889851a2b7124fe798`, applied on `main` `5d9dcc42d`. Machine: Intel i7-8700 (6C/12T), Ubuntu 26.04, GCC 15.2, Ninja Release, `BUILD_TESTING=ON`, full build. - `guest_qsort` passes, and 10/10 with `--repeat until-fail:10`. - Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 648/650, same as `main`. The two failures (`file_writer_binary`, `file_writer_text`) also fail on `main` on this machine. - With only the test applied to `main`, `guest_qsort_tests` does not link (`undefined reference to qsort_s_nid_postfix`), as the description says. - `python3 tools/check_conventions.py --base main`: passed. I checked the semantics against the sources: - C11 Annex K ([N1570 K.3.6.3.2](http://port70.net/~nsz/c/c11/n1570.html#K.3.6.3.2)): comparator `(x, y, context)`, no sort and a nonzero return on a violation, and the same four constraints (`nmemb`/`size` > `RSIZE_MAX`, null `base` or `compar` when `nmemb != 0`). They match. - The violation messages, their order, `EINVAL` and `RSIZE_MAX = SIZE_MAX >> 1` match FreeBSD 13.0's `qsort_s`. - The importer expects this argument order. Mesa's `src/util/u_qsort.h` calls `qsort_s(base, nmemb, size, compar, arg)` with the context last outside `_WIN32` ("C11 added qsort_s"). It uses an adapter only for the MSVC/MinGW order, where the context comes first. A non-Windows build that imports `qsort_s`, and so found no GNU or BSD `qsort_r`, takes that C11 branch. It passes `compar` unchanged, so the comparator is called as `cmp(x, y, context)`, which is what this PR does. I have not looked at the binary itself. I have nothing to add on the constraint-handler point. It is already raised above and recorded in the debt entry. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
github-actions[bot] commented 2026-10-16 06:49:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T06:49:08Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6853 core/libs/prx/libc/include/SonyCrt.hpp L23-25

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3987 docs/dev/debt/libc.md
PR 5021 docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestQsort.cpp
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 6916 docs/dev/debt/libc.md
PR 6975 docs/dev/debt/libc.md
PR 7039 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/include/SonyCrt.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/src/FileAndHeap.cpp
PR 7332 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 7417 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6209824364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6209824364). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T06:49:08Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6853](https://www.github.com/boykopovar/AnyPS5/pull/6853) | `core/libs/prx/libc/include/SonyCrt.hpp` [L23-25](https://github.com/boykopovar/AnyPS5/blob/959cfdd1c5fb1087d8ffb570b36f5a7e93a5e28c/core/libs/prx/libc/include/SonyCrt.hpp#L23-L25) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3987](https://www.github.com/boykopovar/AnyPS5/pull/3987) | `docs/dev/debt/libc.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestQsort.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 6916](https://www.github.com/boykopovar/AnyPS5/pull/6916) | `docs/dev/debt/libc.md` | | [PR 6975](https://www.github.com/boykopovar/AnyPS5/pull/6975) | `docs/dev/debt/libc.md` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/include/SonyCrt.hpp`<br>`core/libs/prx/libc/src/FileAndHeap.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/FileAndHeap.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/src/FileAndHeap.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` |
karimibrahim07 commented 2026-10-16 06:52:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T06:52:08Z.


@MarcZX100 Fixed in ceec3da0a. SonyConstraintHandlerSlot() and its mutex are no longer in the unnamed namespace, so libc has one handler for all its source files. The handler type is now APS5_VABI: the handler a title installs, and the default one it gets back from set_constraint_handler_s, are guest functions. They were called with the host calling convention before. Each module still keeps its own state, as the set_constraint_handler_s debt entry says; that sentence now also says every _s function in a module calls the installed handler.

guest_qsort now installs a counting handler through set_constraint_handler_s. It checks that the four qsort_s violations return 22 and call it with FreeBSD's messages, and that the handler comes back when the previous one is restored. With SonyCrt.hpp from the previous head the test aborts, as @UmillD saw. The full suite passes, 1300 tests (one conventions_function_bodies shard timed out on the busy machine and passed alone). Thanks to both of you for the review and the testing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6209865761 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6209865761). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-16T06:52:08Z. --- @MarcZX100 Fixed in ceec3da0a. `SonyConstraintHandlerSlot()` and its mutex are no longer in the unnamed namespace, so libc has one handler for all its source files. The handler type is now `APS5_VABI`: the handler a title installs, and the default one it gets back from `set_constraint_handler_s`, are guest functions. They were called with the host calling convention before. Each module still keeps its own state, as the `set_constraint_handler_s` debt entry says; that sentence now also says every `_s` function in a module calls the installed handler. `guest_qsort` now installs a counting handler through `set_constraint_handler_s`. It checks that the four `qsort_s` violations return 22 and call it with FreeBSD's messages, and that the handler comes back when the previous one is restored. With `SonyCrt.hpp` from the previous head the test aborts, as @UmillD saw. The full suite passes, 1300 tests (one `conventions_function_bodies` shard timed out on the busy machine and passed alone). Thanks to both of you for the review and the testing.
MarcZX10 commented 2026-10-16 08:48:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T08:48:23Z.


Thanks, that addresses both points I raised: libc source files now share one handler slot, and the handler uses the guest ABI. The new test exercises registration, restoration, and the qsort_s violations. I have no further request on this review; the latest CI checks pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6211744028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6211744028). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T08:48:23Z. --- Thanks, that addresses both points I raised: libc source files now share one handler slot, and the handler uses the guest ABI. The new test exercises registration, restoration, and the `qsort_s` violations. I have no further request on this review; the latest CI checks pass.
adriadam10 commented 2026-10-19 09:48:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T09:48:47Z.


Checked qsort_s against FreeBSD 13 (qsort.c L97-L127): shared sort helpers, context passed as the comparator's third argument, EINVAL plus constraint handler on the four violations. The handler slot is now shared across libc source files with the guest ABI, and guest_qsort covers order, context, n == 0, es == 0 and each violation through an installed handler (it does not link on main). Independent Windows and Linux runs in the thread agree. Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6264408017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6707#issuecomment-6264408017). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T09:48:47Z. --- Checked `qsort_s` against FreeBSD 13 (`qsort.c` L97-L127): shared sort helpers, context passed as the comparator's third argument, `EINVAL` plus constraint handler on the four violations. The handler slot is now shared across libc source files with the guest ABI, and `guest_qsort` covers order, context, `n == 0`, `es == 0` and each violation through an installed handler (it does not link on `main`). Independent Windows and Linux runs in the thread agree. Merged.
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!6707
No description provided.