feat(libSceLibreSsl3): implement sk_new, sk_push and sk_free #13088

Merged
2Swagger merged 2 commits from upstream-pr/13088 into main 2026-10-30 10:47:11 +00:00
2Swagger commented 2026-10-30 01:02:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 2Swagger on 2026-10-30T01:02:03Z.


What

Implements sk_new, sk_push and sk_free in libSceLibreSsl3, replacing their throwing placeholders from #12369's export inventory. They follow LibreSSL 4.0.0 stack.c, the version libSceLibreSsl3's existing debt entries cite, and reuse libSceLibreSsl's 32-byte _STACK layout (LibreSslStack), which stack_local.h keeps unchanged in 4.0.0.

  • sk_new(compare): allocates the stack and a 4-entry element array (MIN_NODES) from the guest heap, clears the entries and stores the compare function. It returns null, releasing anything already allocated, if either allocation fails.
  • sk_push(stack, element): appends the element and returns the new count, clearing sorted. Like LibreSSL it keeps one spare slot, so the array doubles when pushing the 4th, 8th, 16th... element, and an allocation failure returns 0 and leaves the stack as it was.
  • sk_free(stack): releases the element array and the stack; null does nothing.

Stacks come from the guest malloc/reallocarray and are released with the guest free, the same heap the merged sk_pop_free (#10373, forwarded to libSceLibreSsl3) uses, so a stack from sk_new can be inspected with sk_num/sk_value and released with sk_pop_free. Where LibreSSL would fault or overflow, sk_push throws: a null stack, a negative element count, a null element array it does not regrow, or an array that cannot double without overflowing int. These are listed in the debt entry, and the declarations in include/Api.hpp now carry the real signatures. Nothing is checked on the console.

Tested

  • New guest_libressl3_stack, with a tracking guest heap: a new stack's layout and initial fields; push, sk_num, sk_value and sk_pop on it (including a null element and sorted being cleared); growth from 4 to 8 to 16 entries at the 4th and 8th pushes with every element kept; sk_pop_free on a grown stack calling the free function once per element and releasing both blocks; sk_free releasing both blocks and sk_free(NULL) releasing nothing; a failed stack or element-array allocation in sk_new returning null without leaking, and a failed growth in sk_push returning 0 with the stack unchanged. Under 0.1 s.
  • Head f79734a34 on main 673fa865f. Windows 11 (WinLibs GCC 15.2.0, Release): guest_libressl3_stack, guest_libressl3_asn1, guest_libressl3_digest, guest_libressl3_key_reference, guest_crypto_memcmp and public_headers with its compile batches pass, 70 of 70. Linux (Ubuntu 24.04 under WSL2, GCC 13.3.0, Release): the same set, 70 of 70.
  • guest_libressl3_stack passed 20 consecutive runs on both platforms (ctest --repeat until-fail:20).
  • Conventions and test registration pass. git merge-tree against the 15 open libSceLibreSsl3 PRs: the 4 that merge cleanly with main (#10461, #10557, #10631, #10960) also merge cleanly with this one; the other 11 already conflict with main in the inventory block #12369 added, and this PR adds no new conflict to them. Not tested on a console or a title.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5077832634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13088). Originally posted by [2Swagger](https://github.com/2Swagger) on 2026-10-30T01:02:03Z. --- ### What Implements `sk_new`, `sk_push` and `sk_free` in libSceLibreSsl3, replacing their throwing placeholders from #12369's export inventory. They follow [LibreSSL 4.0.0 `stack.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/stack/stack.c), the version libSceLibreSsl3's existing debt entries cite, and reuse libSceLibreSsl's 32-byte `_STACK` layout (`LibreSslStack`), which `stack_local.h` keeps unchanged in 4.0.0. - **`sk_new(compare)`:** allocates the stack and a 4-entry element array (`MIN_NODES`) from the guest heap, clears the entries and stores the compare function. It returns null, releasing anything already allocated, if either allocation fails. - **`sk_push(stack, element)`:** appends the element and returns the new count, clearing `sorted`. Like LibreSSL it keeps one spare slot, so the array doubles when pushing the 4th, 8th, 16th... element, and an allocation failure returns 0 and leaves the stack as it was. - **`sk_free(stack)`:** releases the element array and the stack; null does nothing. Stacks come from the guest `malloc`/`reallocarray` and are released with the guest `free`, the same heap the merged `sk_pop_free` (#10373, forwarded to libSceLibreSsl3) uses, so a stack from `sk_new` can be inspected with `sk_num`/`sk_value` and released with `sk_pop_free`. Where LibreSSL would fault or overflow, `sk_push` throws: a null stack, a negative element count, a null element array it does not regrow, or an array that cannot double without overflowing `int`. These are listed in the debt entry, and the declarations in `include/Api.hpp` now carry the real signatures. Nothing is checked on the console. ### Tested - New `guest_libressl3_stack`, with a tracking guest heap: a new stack's layout and initial fields; push, `sk_num`, `sk_value` and `sk_pop` on it (including a null element and `sorted` being cleared); growth from 4 to 8 to 16 entries at the 4th and 8th pushes with every element kept; `sk_pop_free` on a grown stack calling the free function once per element and releasing both blocks; `sk_free` releasing both blocks and `sk_free(NULL)` releasing nothing; a failed stack or element-array allocation in `sk_new` returning null without leaking, and a failed growth in `sk_push` returning 0 with the stack unchanged. Under 0.1 s. - Head f79734a34 on `main` 673fa865f. Windows 11 (WinLibs GCC 15.2.0, Release): `guest_libressl3_stack`, `guest_libressl3_asn1`, `guest_libressl3_digest`, `guest_libressl3_key_reference`, `guest_crypto_memcmp` and `public_headers` with its compile batches pass, 70 of 70. Linux (Ubuntu 24.04 under WSL2, GCC 13.3.0, Release): the same set, 70 of 70. - `guest_libressl3_stack` passed 20 consecutive runs on both platforms (`ctest --repeat until-fail:20`). - Conventions and test registration pass. `git merge-tree` against the 15 open libSceLibreSsl3 PRs: the 4 that merge cleanly with `main` (#10461, #10557, #10631, #10960) also merge cleanly with this one; the other 11 already conflict with `main` in the inventory block #12369 added, and this PR adds no new conflict to them. Not tested on a console or a title. ### 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 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!13088
No description provided.