Skip to content

feat(libSceLibreSsl): implement file and socket BIO adapters - #12928

Open
xdCloudy wants to merge 24 commits into
boykopovar:mainfrom
xdCloudy:feat/libSceLibreSsl-batch100
Open

xdCloudy wants to merge 24 commits into
boykopovar:mainfrom
xdCloudy:feat/libSceLibreSsl-batch100

Conversation

@xdCloudy

@xdCloudy xdCloudy commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement three previously stubbed libSceLibreSsl BIO exports:

  • BIO_s_file
  • BIO_new_fp
  • BIO_new_socket

This PR is now a focused follow-up to #9536, which implements the underlying memory BIO framework and guest-compatible BIO structures.

The previous 100-export implementation has been removed from this PR's proposed scope following maintainer review.

Implementation

File BIO

  • Expose the file BIO method descriptor.
  • Construct file BIOs around guest libc FileStream objects.
  • Route reads, writes, flushing, seeking and EOF queries through guest libc.
  • Support file-pointer retrieval through BIO control.
  • Respect caller-selected file ownership.
  • Close owned guest streams during BIO destruction.

Socket BIO

  • Construct BIOs around guest socket descriptors.
  • Use sceNetSend and sceNetRecv for socket I/O.
  • Use sceNetSocketClose for owned socket cleanup.
  • Preserve guest descriptor handling.
  • Support basic close-flag and lifecycle controls.

Integration

Both adapters use the LibreSsl::Bio and LibreSsl::BioMethod ABI defined by the prerequisite BIO implementation.

They use the existing BIO allocation, callback dispatch, reference handling and cleanup machinery.

No independent, incompatible BIO object representation is introduced.

Dependencies

Depends on: #9536

PR #9536 provides the underlying BIO implementation and itself builds on the earlier ERR work in #9535.

This branch is prepared against the #9536 implementation at:

07516032a788a3a3d294b00342ea7b51f502b9ff

Once the prerequisite PRs merge, this branch must be reconciled against the resulting main before merging.

Sources and implementation provenance

The three adapter implementations are original compatibility code based on:

The implementation does not copy LibreSSL or OpenSSL source code.

No proprietary firmware binaries, extracted code or decompiler output are included.

The original PS5 13.60 export identification remains the basis for selecting these three functions.

The adapter behaviour has not been independently verified through firmware execution or console testing.

Behaviour and limitations

  • Socket retry-state handling remains incomplete.
  • Socket pending-byte queries are not implemented.
  • Extended file and socket BIO controls remain incomplete.
  • Unsupported method-control commands return 0.
  • Console execution and full firmware equivalence remain unverified.

These limitations are documented in docs/dev/debt/libSceLibreSsl.md.

Tested

Static validation

  • GCC C++20 syntax validation passed.
  • -Wall -Wextra -Werror passed.
  • python3 tools/check_conventions.py --base HEAD passed.
  • git diff --check passed.

Regression tests added

  • File BIO method descriptor.
  • Null file rejection.
  • Guest file BIO construction.
  • File read/write behaviour.
  • File flushing and rewinding.
  • File-pointer retrieval.
  • Borrowed file ownership.
  • Owned file closure.
  • Invalid socket rejection.
  • Guest socket BIO construction.
  • Socket method identification.
  • Unowned socket cleanup.

The added tests passed syntax validation.

Not tested

  • Full CMake build.
  • Runtime CTest execution.
  • Socket send/receive against a live connection.
  • Console execution.

Runtime test results must be supplied before this PR is considered merge-ready.

Checklist

  • Base and overlap reviewed — intentionally stacked on feat(libSceLibreSsl): implement memory BIOs #9536 rather than current main; no other open PR implements these three new exports. Reconcile with main after feat(libSceLibreSsl): implement memory BIOs #9536 merges.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and permitted namespace endings
  • Unimplemented paths use NotImplemented_nid_no_patch; remaining BIO limitations are documented
  • No notes, investigation .md files or images added to the repository
  • No new third-party code added
  • Generic behaviour, not specific to one title
  • Depends on: feat(libSceLibreSsl): implement memory BIOs #9536
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Maintainer review follow-up

This revision addresses the scope and overlap concerns raised in the review of the original implementation.

The previously proposed BIGNUM, digest, HMAC, CMAC, EVP cipher, ERR, OBJ and PKEY implementations are no longer part of this PR's proposed changes.

Consequently, the reported CBC padding, EVP cipher layout, CFB8 identifier, PKEY and HMAC issues are outside the revised scope.

The memory BIO implementation is inherited from #9536 rather than independently reimplemented.

The remaining work is limited to the three file/socket BIO exports above.

The prerequisite dependency and outstanding runtime validation are explicitly disclosed.

@xdCloudy

Copy link
Copy Markdown
Contributor Author

FYI: Making Changes

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Progress report (029463c → a36ec48)

📈 System libraries: 26.06% (+0.08%, +29 implemented, +2 declared functions)

✅ 29 implemented
Library Name
libSceLibreSsl BIO_ctrl_nid_postfix
libSceLibreSsl BIO_new_fp_nid_postfix
libSceLibreSsl BIO_new_mem_buf_nid_postfix
libSceLibreSsl BIO_new_nid_postfix
libSceLibreSsl BIO_new_socket_nid_postfix
libSceLibreSsl BIO_puts_nid_postfix
libSceLibreSsl BIO_s_file_nid_postfix
libSceLibreSsl BIO_s_mem_nid_postfix
libSceLibreSsl BIO_write_nid_postfix
libSceLibreSsl ERR_error_string_nid_postfix
libSceLibreSsl ERR_free_strings_nid_postfix
libSceLibreSsl FileControl
libSceLibreSsl FileDestroy
libSceLibreSsl FileGets
libSceLibreSsl FilePuts
libSceLibreSsl FileRead
libSceLibreSsl FileWrite
libSceLibreSsl SocketControl
libSceLibreSsl SocketDestroy
libSceLibreSsl SocketPuts
libSceLibreSsl SocketRead
libSceLibreSsl SocketWrite
libSceLibreSsl controlMemory
libSceLibreSsl createMemory
libSceLibreSsl destroyMemory
libSceLibreSsl getsMemory
libSceLibreSsl readMemory
libSceLibreSsl3 ERR_load_crypto_strings_nid_postfix
libSceLibreSsl3 ERR_peek_last_error_nid_postfix
⚪ 2 behaviourally empty (constant return or throw)
Library Name
libSceLibreSsl ERR_free_strings_nid_postfix
libSceLibreSsl3 ERR_load_crypto_strings_nid_postfix
🆕 2 declared as stubs
Library Name
libSceLibreSsl putsMemory
libSceLibreSsl writeMemory

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl 99/401 (24.69%) 126/419 (30.07%) +5.38%
libSceLibreSsl3 12/270 (4.44%) 14/270 (5.19%) +0.74%

@xdCloudy

Copy link
Copy Markdown
Contributor Author

Review follow-up — interoperability fixes

Pushed follow-up commit 9b55867 addressing the five issues identified during the pre-merge review.

Changes made:

  1. BIO file handling: Replaced native FILE* assumptions with AnyPS5's guest FileStream interfaces, including writes, controls and cleanup.

  2. BIO socket handling: Routed socket writes and closure through libSceNet, preserving guest descriptor translation and ownership.

  3. EVP context lifecycle: Added caller-owned context support using a host-side registry, including initialization, cleanup and release handling.

  4. EVP staged initialization: Corrected separate cipher/key/IV initialization, GCM IV-length configuration and authentication-tag availability.

  5. Memory BIO controls: Corrected data-pointer retrieval and reset semantics.

Regression coverage added:

  • Guest file and socket BIO operations.
  • File/socket ownership and cleanup.
  • Memory BIO data access and reset.
  • Caller-owned cipher contexts.
  • Staged AES-CBC initialization.
  • Staged AES-GCM initialization with a non-default IV length.
  • GCM tag retrieval before finalization.

Validation:

  • GCC 13 C++20 syntax checks: PASS
  • -Wall -Wextra -Werror: PASS
  • Repository convention checks: PASS
  • git diff --check: PASS
  • Windows CI: running at the time of this update

The original 100-export scope is unchanged.

No new dependencies, proprietary firmware artifacts or additional NID implementations were introduced.

Remaining firmware-equivalence limitations are documented in docs/dev/debt/libSceLibreSsl.md.

Full runtime validation of the follow-up remains pending the Windows CI result.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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 9571 core/libs/CMakeLists.txt L301
core/libs/prx/libSceLibreSsl/ErrorQueue.cmake
core/libs/prx/libSceLibreSsl/Export.cpp L10, L40-44, L50-74, L80-162, L452-466
core/libs/prx/libSceLibreSsl/MemoryBio.cmake
core/libs/prx/libSceLibreSsl/include/Api.hpp L2-3, L262, L264-268, L270-286, L344-350
core/libs/tests/GuestLibreSslBio.cpp
docs/dev/debt/libSceLibreSsl.md L17, L31
PR 10557 docs/dev/debt/libSceLibreSsl3.md L2
PR 10834 core/libs/prx/libSceLibreSsl/Export.cpp L452-496
PR 10878 docs/dev/debt/libSceLibreSsl.md L17
PR 12730 docs/dev/debt/libSceLibreSsl.md L17

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 1835 .gitmodules
PR 5021 .gitmodules
core/libs/CMakeLists.txt
PR 7275 core/libs/CMakeLists.txt
PR 8650 core/libs/CMakeLists.txt
PR 9156 core/libs/CMakeLists.txt
PR 9162 core/libs/CMakeLists.txt
PR 9293 core/libs/CMakeLists.txt
PR 9297 core/libs/CMakeLists.txt
PR 9302 core/libs/CMakeLists.txt
PR 9383 core/libs/CMakeLists.txt
PR 9446 core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9855 .gitmodules
PR 9970 core/libs/prx/libSceLibreSsl3/Export.cpp
docs/dev/debt/libSceLibreSsl3.md
PR 10418 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10452 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10461 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10490 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10491 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10493 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10508 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10570 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10631 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 11003 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11128 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11129 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11138 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11143 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11146 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
docs/dev/debt/libSceLibreSsl3.md
PR 11151 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11174 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11175 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11176 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11359 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11466 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11662 core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 12642 core/libs/CMakeLists.txt
PR 12729 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 12754 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 13253 core/libs/CMakeLists.txt
PR 13256 core/libs/CMakeLists.txt
PR 13266 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13285 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13546 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13547 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13578 .gitmodules
PR 13860 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/tests/GuestLibreSslError.cpp
docs/dev/debt/libSceLibreSsl.md
PR 13877 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14212 docs/dev/debt/libSceLibreSsl.md
docs/dev/debt/libSceLibreSsl3.md

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@xdCloudy thanks for this, and for building on the mbedTLS and SHA code already in the tree. Reviewed at 53d00fe. There are a few correctness problems, and a large overlap with open PRs that decides how this can land.

Correctness

  1. Invalid CBC padding reports success. In EvpCipher.cpp Final() (l.128-133), mbedtls_cipher_finish_padded reports bad padding through invalidPadding while still returning 0 (cipher.h at the pinned commit), but the value is never checked, so a decrypt with corrupted padding returns 1 and an output length. Please reject it, and add padded-decrypt tests with corrupted and truncated padding next to valid controls.
  2. EvpCmac.cpp doesn't compile on Linux. EvpCipher has an unsigned long flags, so it is 88 bytes on Linux (8-byte unsigned long) and 80 on Windows, and static_assert(sizeof(EvpCipher) == 80) fails on Linux. The guest (FreeBSD amd64) also has an 8-byte unsigned long, so 80 isn't the guest size either. Please define every guest-visible layout with fixed-width types and checked offsets taken from LibreSSL 2.5.4's EVP_CIPHER (its field order differs from this struct too), rather than adjusting the assertion. While there: the CFB8 NIDs should be 653/654/655 as in LibreSSL 2.5.4 (not 421/425/429), and CFB/CTR report a block size of 1, not 16.
  3. BIO control and reset. For a writable memory BIO holding abc, BIO_CTRL_INFO returns 3 but leaves the char** unset, and BIO_reset leaves the 3 bytes pending. LibreSSL 2.5.4's bss_mem.c sets the pointer and clears writable data. Please fix both and assert them in the BIO test.
  4. PKEY and lifecycle. EVP_PKEY_id rejects an object whose type is at offset 0 instead of returning it, the EC accessor always returns null without the error/retention LibreSSL has, a staged EVP_CipherInit_ex with a method and null key/IV returns 0, and the HMAC path with a null key lacks LibreSSL's guard. Please follow LibreSSL's layouts and ownership/error behaviour here, or leave these exports as explicit unsupported paths for now.

Overlap and size

  1. The description says there's no overlap, but 61 of the 101 exports here are also implemented by open PRs: feat(libSceLibreSsl): implement CMAC with AES-CBC methods #9571 (33: CMAC, BIGNUM, BIO, ERR), feat(libSceLibreSsl): implement the EVP message digest and HMAC functions #9448 (20: digest/HMAC), feat(libSceLibreSsl): implement memory BIOs #9536 (10: memory BIO/ERR), feat(libSceLibreSsl): implement numeric ERR formatting and newest peeking #9535 (3), feat(libSceLibreSsl): implement EVP_PKEY_new and EVP_PKEY_free #10570 (2), feat(libSceLibreSsl): implement OBJ_nid2sn and OBJ_sn2nid #10508 (2), feat(libSceLibreSsl): implement EVP_PKEY_id #10418, feat(libSceLibreSsl): implement EVP_CIPHER_block_size #10450, feat(libSceLibreSsl): implement six sourced LibreSSL 2.5.4 exports #12601 and feat(libSceLibreSsl): retain EC keys returned by EVP_PKEY_get1_EC_KEY #12844 (1 each). Several of those have already been reviewed and are waiting to land, so they go first. Please drop what they implement, build on them, and send the genuinely new exports split by family (BIGNUM/BN_CTX; digest/HMAC; AES/cipher/CMAC; BIO; OBJ; ERR/init; PKEY/RSA). At 101 exports a single PR can't get a proper correctness review.

Count, sources and tests

  1. The debt entry says 195 stubs remain, but this branch's Export.cpp has 199 NotImplemented_nid_no_patch(__func__) calls (299 on main). feat(libSceLibreSsl): retain EC keys returned by EVP_PKEY_get1_EC_KEY #12844 and feat(libSceLibreSsl): release OCSP response ownership #12850 edit the same sentence, so please recount on top of them after the split. The description says 100 exports; the diff has 101.
  2. For each new body, please say whether it was written from the ABI and observed behaviour, adapted from LibreSSL/OpenSSL source (then the original notices have to come with it), or taken from another patch. For AES-GCM, CMAC and HMAC, please cite where the expected values come from (for example NIST SP 800-38B/38D, RFC 4231), and post the registered tests' output on the new heads.

@oneandonlydean oneandonlydean self-assigned this Oct 29, 2026
@xdCloudy xdCloudy changed the title feat(libSceLibreSsl): implement 100 cryptographic exports feat(libSceLibreSsl): implement file and socket BIO adapters Oct 29, 2026
@xdCloudy
xdCloudy force-pushed the feat/libSceLibreSsl-batch100 branch from 9b55867 to 1e6c1f6 Compare October 29, 2026 16:18
@xdCloudy

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Thanks for the detailed review.

I've re-scoped #12928 in response to the correctness, overlap and review-size concerns.

Changes made

The original broad cryptographic implementation has been replaced with a focused BIO follow-up containing only three new exports:

  • BIO_s_file
  • BIO_new_fp
  • BIO_new_socket

This now builds on the guest-compatible BIO implementation from #9536 rather than maintaining a separate BIO object representation.

The file adapter uses AnyPS5's guest FileStream interfaces, while the socket adapter uses libSceNet.

File/socket ownership and cleanup follow the caller's close flag.

Overlap resolution

The previously proposed BIGNUM, digest, HMAC, CMAC, EVP cipher, ERR, OBJ and PKEY implementations have been removed from this PR's scope.

This also removes the CBC padding, EVP cipher layout, CFB8 identifier, PKEY lifecycle and HMAC paths identified in your review.

The existing memory BIO implementation is inherited from #9536.

Dependency: #9536, with #9535 as its prerequisite.

Tests

Added regression coverage for:

  • File BIO construction and operations.
  • File ownership and cleanup.
  • File-pointer retrieval.
  • Socket BIO construction and ownership.

Validation completed:

  • GCC C++20 syntax checks: PASS
  • -Wall -Wextra -Werror: PASS
  • Repository convention checks: PASS
  • Whitespace checks: PASS

Full compilation and runtime CTest execution remain outstanding and are not claimed as passing.

Documentation

The PR description now separates implementation provenance, dependencies, validation and known limitations.

The technical-debt entry documents unsupported socket retry behaviour, pending-byte queries and extended BIO controls.

Thanks again for identifying these issues. The revised scope is intended to preserve the genuinely new functionality while respecting the older reviewed implementations.

@JJenkx

JJenkx commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Windows run of this head (bb735ca894), merged onto main bb04a4f1ea (clean merge, 3rdparty/libressl-openbsd submodule initialized, local only). Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, no Vulkan driver visible.

  • guest_libressl_bio, guest_libressl_error_string and guest_libressl_error (5 ctest entries) pass 3 of 3 (ctest --repeat until-fail:3), none skipped.
  • guest_libressl_digest (unchanged by this head, but it aborted with 0xc0000409 at the earlier head 9b55867b6f) passes here too.
  • I couldn't build a negative control: with the 11 changed sources reverted and the 5 new ones removed, the tests no longer build.

AI-assisted: yes (Claude Code).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@xdCloudy Reviewed at bb735ca. Thanks for narrowing this to the three BIO adapters and building on #9536/#9535; that removes the earlier crypto-family blockers. Two file BIO result mappings still need fixing in core/libs/prx/libSceLibreSsl/src/BioFileSocket.cpp:

  1. FileRead (lines 18–20) returns fread’s zero count for both EOF and an I/O error. LibreSSL 2.5.4 crypto/bio/bss_file.c:file_read checks ferror after a zero read and returns -1 on error (also records the error). Please use the guest stream error state here, retaining 0 for clean EOF. Add controls for valid data, EOF and a stream read error; the error case must not be accepted as clean EOF.
  2. FileControl BIO_CTRL_RESET (lines 46–47) converts fseek’s status to a success boolean. The file BIO contract returns fseek’s status: 0 on success, negative on failure. Please preserve that convention and test a successful reset plus a failed seek (for example a non-seekable stream). The memory BIO reset convention is different and should stay separate.

The adapter path uses the existing guest file/socket interfaces and the narrower scope is welcome. Please retain the prerequisite landing/reconciliation note and post the focused adapter tests on the revised head. No request to restore the removed crypto batch.

@xdCloudy

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Thanks for the follow-up review. I've pushed the requested corrections to #12928.

Updated head: 62c2b20

Changes made

  1. FileRead — EOF vs I/O errors

    • Uses the guest ferror_nid_postfix interface after a zero-byte read.
    • Preserves 0 for clean EOF.
    • Returns -1 when the guest stream reports an I/O error.
    • Records the corresponding system and BIO errors in the LibreSSL error queue.
  2. FileControl — BIO_CTRL_RESET

    • Returns the underlying fseek_nid_postfix status directly.
    • Returns 0 on successful reset and -1 on failure.
    • Keeps file BIO reset semantics separate from memory BIO reset behaviour.

Regression coverage

Extended GuestLibreSslBio.cpp to cover:

  • Successful file reads and data integrity.
  • Clean EOF returning 0 without queuing errors.
  • Successful reset returning 0, followed by another valid read.
  • Failed reads on a write-only pipe returning -1.
  • Stream error indicators and LibreSSL error-queue entries.
  • Failed reset on a non-seekable pipe returning -1.
  • Existing file/socket BIO ownership and lifecycle tests.

The existing file reset assertion was also updated to match the corrected return convention.

Validation

The latest GitHub Build workflow is queued:

https://github.com/boykopovar/AnyPS5/actions/runs/40944881454

Full compilation and runtime CTest results are therefore still pending. I'm not claiming those tests have passed.

Scope and dependencies

The PR remains limited to the original three BIO exports:

  • BIO_s_file
  • BIO_new_fp
  • BIO_new_socket

Depends on: #9536 (which depends on #9535).

The prerequisite landing/reconciliation requirement remains unchanged. This branch must be reconciled with main once those dependencies land.

No removed cryptographic implementations have been restored, and no additional exports or third-party dependencies have been introduced.

@xdCloudy

Copy link
Copy Markdown
Contributor Author

Validation and dependency update

The latest Build workflow for head 62c2b20 completed successfully, including the Windows configuration, eligibility and host-only linking checks.

The change-selected runtime CTest stage was skipped, so this is not a fresh runtime pass for the latest head.

The previously reported Windows BIO tests were run against an earlier revision; the subsequent file-read and reset regression tests still require runtime confirmation.

Dependency order

  1. feat(libSceLibreSsl): implement numeric ERR formatting and newest peeking #9535 — ERR prerequisite
  2. feat(libSceLibreSsl): implement memory BIOs #9536 — memory BIO implementation
  3. feat(libSceLibreSsl): implement file and socket BIO adapters #12928 — file and socket BIO adapters

The PR remains scoped to BIO_s_file, BIO_new_fp and BIO_new_socket.

The stacked branch must be reconciled against the final merged prerequisite implementations before this PR can land. No unsupported claim of independent merge readiness is being made.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants