refactor(libressl): drop errno saves around guest copies #25937

Merged
LeandroLP23 merged 1 commit from upstream-pr/25937 into main 2026-11-22 23:39:29 +00:00
LeandroLP23 commented 2026-11-22 22:51:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-22T22:51:50Z.


What

Twelve LibreSSL source files each define small helpers that save errno, call GuestCopyIn_nid_no_patch, GuestCopyOut_nid_no_patch or GuestWritable_nid_no_patch, and restore errno. Since #21243, those three libc functions restore errno themselves: CopyGuestBytes, GuestCopyOut_nid_no_patch and GuestWritable_nid_no_patch each hold a RestoreErrno in libc/src/General.cpp. As noted when #21639 was closed, the save around them is now redundant.

  • The untyped helpers (pointer and size: CopyGuestInPreservingErrno, CopyGuestOutPreservingErrno, CopyGuestBytesInPreservingErrno, CopyInPreservingErrno, CopyOutPreservingErrno, WritablePreservingErrno) are removed. Their callers call the libc functions directly, which take the same arguments.
  • The typed helpers (CopyGuestInPreservingErrno(T&, const T*) and CopyGuestOutPreservingErrno(T*, const T&)) stay, because they take the size from the type. Each becomes one line over GuestPtr.
  • CopyGuestStringPreservingErrno in Bio.cpp and BioFileSocket.cpp still reads a guest string in chunks. Only its inner call changes.

Files: libSceLibreSsl/src/{Bio,BioFileSocket,ProtocolSelection}.cpp and libSceLibreSsl3/src/{KeyComponents,OcspFindStatus,RsaSetters,SignatureAlgorithms,X509,X509Algor,X509CmpTime,X509StoreContext,X509Validity}.cpp, 180 lines removed and 68 added. I left alone the LibreSSL files that open pull requests touch. If this shape is welcome, the same helpers in other libraries (FreeType, ICU and some others, about 90 definitions in all) can follow in separate pull requests.

No change in behaviour.

Tested

Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release. ctest -R 'ssl|x509|ocsp|rsa|bio|asn1', with its 183 build outputs from tools/select_tests.py targets: 213 of 213 on main 8affaf75a2 and 213 of 213 with this change applied to it. tools/check_conventions.py passes. tools/pr_overlap.py --branch finds no overlap with the 2476 open pull requests.

Not run: Linux and macOS.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5444264229 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25937). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-22T22:51:50Z. --- ### What Twelve LibreSSL source files each define small helpers that save `errno`, call `GuestCopyIn_nid_no_patch`, `GuestCopyOut_nid_no_patch` or `GuestWritable_nid_no_patch`, and restore `errno`. Since #21243, those three libc functions restore `errno` themselves: `CopyGuestBytes`, `GuestCopyOut_nid_no_patch` and `GuestWritable_nid_no_patch` each hold a `RestoreErrno` in `libc/src/General.cpp`. As noted when #21639 was closed, the save around them is now redundant. - The untyped helpers (pointer and size: `CopyGuestInPreservingErrno`, `CopyGuestOutPreservingErrno`, `CopyGuestBytesInPreservingErrno`, `CopyInPreservingErrno`, `CopyOutPreservingErrno`, `WritablePreservingErrno`) are removed. Their callers call the libc functions directly, which take the same arguments. - The typed helpers (`CopyGuestInPreservingErrno(T&, const T*)` and `CopyGuestOutPreservingErrno(T*, const T&)`) stay, because they take the size from the type. Each becomes one line over `GuestPtr`. - `CopyGuestStringPreservingErrno` in `Bio.cpp` and `BioFileSocket.cpp` still reads a guest string in chunks. Only its inner call changes. Files: `libSceLibreSsl/src/{Bio,BioFileSocket,ProtocolSelection}.cpp` and `libSceLibreSsl3/src/{KeyComponents,OcspFindStatus,RsaSetters,SignatureAlgorithms,X509,X509Algor,X509CmpTime,X509StoreContext,X509Validity}.cpp`, 180 lines removed and 68 added. I left alone the LibreSSL files that open pull requests touch. If this shape is welcome, the same helpers in other libraries (FreeType, ICU and some others, about 90 definitions in all) can follow in separate pull requests. No change in behaviour. ### Tested Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release. `ctest -R 'ssl|x509|ocsp|rsa|bio|asn1'`, with its 183 build outputs from `tools/select_tests.py targets`: 213 of 213 on `main` `8affaf75a2` and 213 of 213 with this change applied to it. `tools/check_conventions.py` passes. `tools/pr_overlap.py --branch` finds no overlap with the 2476 open pull requests. Not run: Linux and macOS. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
MarcZX10 commented 2026-11-22 23:06:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T23:06:25Z.

Review: APPROVED


Reviewed — looks good

The changed wrappers only duplicated errno restoration already provided by the libc guest-memory functions, and the replacements preserve the same copy operations.

What I ran

Reviewed head a29613840d2244a93cd0434d4f4634a799d29f1b. Read the prepared diff and all 12 changed files listed in the manifest; checked the relevant guest-copy implementations in General.cpp and GuestPtr.hpp. No commands or tests were run.

Results

Check Result Note
Diff and changed files passed All 12 changed files reviewed
Guest-copy errno handling passed The libc functions restore errno
Tests not run No local test run

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports Windows tests and convention checks in the PR description; these were not run as part of this review. Linux and macOS behavior was not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015012922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25937#pullrequestreview-6015012922). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T23:06:25Z. **Review:** APPROVED --- # Reviewed — looks good The changed wrappers only duplicated errno restoration already provided by the libc guest-memory functions, and the replacements preserve the same copy operations. ## What I ran Reviewed head `a29613840d2244a93cd0434d4f4634a799d29f1b`. Read the prepared diff and all 12 changed files listed in the manifest; checked the relevant guest-copy implementations in `General.cpp` and `GuestPtr.hpp`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All 12 changed files reviewed | | Guest-copy errno handling | passed | The libc functions restore errno | | Tests | not run | No local test run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports Windows tests and convention checks in the PR description; these were not run as part of this review. Linux and macOS behavior was not verified. ## To get this to a good state Nothing is required.
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!25937
No description provided.