xnetworking: add RAII guards for CryptoAPI handles, document unsafe invariants, and split tests #338

Closed
pawelsicinski wants to merge 2 commits from upstream-pr/342 into main
pawelsicinski commented 2026-11-23 23:59:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by pawelsicinski on 2026-11-23T23:59:26Z.


Follow up on docs/xnetworking-rust-review.md for crates/xcl/src/hle/xgameruntime/networking.rs: wrap owned Windows CryptoAPI certificate/chain handles in RAII guards, document FFI # Safety preconditions and // SAFETY: justifications, and move unit tests into a dedicated test file.

What is in it

  • Add CertContextGuard and CertChainGuard<'a> RAII wrappers in crates/xcl/src/hle/xgameruntime/networking.rs and refactor XNetworkingVerifyServerCertificate to release CERT_CHAIN_CONTEXT and CERT_CONTEXT automatically on every return path.
  • Add # Safety doc sections to exported pub unsafe functions and // SAFETY: comments to unsafe FFI/pointer operations in networking.rs.
  • Move the inline #[cfg(test)] mod tests block into crates/xcl/src/hle/xgameruntime/networking_tests.rs (via #[path = "networking_tests.rs"]), matching adapter_tests.rs / agility_tests.rs.
  • Add unit test raii_guards_drop_chain_before_context covering null-pointer handling and reverse drop order (chain freed before context).

Tested

  • Manual static review of networking.rs and networking_tests.rs (no local Rust toolchain on the authoring machine yet; pending CI / Windows cargo test run).

Regression run
main:
(pending — not run yet; requires scripts/smoke.ps1 on a Windows machine with Rust and a title)

PR:
(pending — not run yet)

Not tested

  • Local cargo build --workspace and cargo test --workspace (no cargo/rustc installed on this machine).
  • Live WinHTTP/CryptoAPI TLS verification and scripts/smoke.ps1 regression run on a real title.

AI use

  • Antigravity (Gemini 4 Neon): drafted the RAII guards, # Safety / // SAFETY: comments, test file split, and new unit test.
<!-- greyfinch-sync:ivall/xcl:issue:6571411969 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/342). Originally posted by [pawelsicinski](https://github.com/pawelsicinski) on 2026-11-23T23:59:26Z. --- Follow up on `docs/xnetworking-rust-review.md` for `crates/xcl/src/hle/xgameruntime/networking.rs`: wrap owned Windows CryptoAPI certificate/chain handles in RAII guards, document FFI `# Safety` preconditions and `// SAFETY:` justifications, and move unit tests into a dedicated test file. **What is in it** - Add `CertContextGuard` and `CertChainGuard<'a>` RAII wrappers in `crates/xcl/src/hle/xgameruntime/networking.rs` and refactor `XNetworkingVerifyServerCertificate` to release `CERT_CHAIN_CONTEXT` and `CERT_CONTEXT` automatically on every return path. - Add `# Safety` doc sections to exported `pub unsafe` functions and `// SAFETY:` comments to unsafe FFI/pointer operations in `networking.rs`. - Move the inline `#[cfg(test)] mod tests` block into `crates/xcl/src/hle/xgameruntime/networking_tests.rs` (via `#[path = "networking_tests.rs"]`), matching `adapter_tests.rs` / `agility_tests.rs`. - Add unit test `raii_guards_drop_chain_before_context` covering null-pointer handling and reverse drop order (`chain` freed before `context`). **Tested** - Manual static review of `networking.rs` and `networking_tests.rs` (no local Rust toolchain on the authoring machine yet; pending CI / Windows `cargo test` run). **Regression run** main: (pending — not run yet; requires `scripts/smoke.ps1` on a Windows machine with Rust and a title) PR: (pending — not run yet) **Not tested** - Local `cargo build --workspace` and `cargo test --workspace` (no `cargo`/`rustc` installed on this machine). - Live WinHTTP/CryptoAPI TLS verification and `scripts/smoke.ps1` regression run on a real title. **AI use** - Antigravity (Gemini 4 Neon): drafted the RAII guards, `# Safety` / `// SAFETY:` comments, test file split, and new unit test.
futurepro62 commented 2026-11-24 07:06:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T03:47:57Z.


Tested exact head 045751d (on its base 21b8723).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 656 passed, 0 failed, 40 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

Not tested

  • A retail title or scripts/smoke.ps1 (no title on this machine), AMD, a release build. I did not review the diff.

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7121432192 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/342#issuecomment-7121432192). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T03:47:57Z. --- Tested exact head `045751d` (on its base `21b8723`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **656 passed, 0 failed, 40 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. **Not tested** - A retail title or `scripts/smoke.ps1` (no title on this machine), AMD, a release build. I did not review the diff. **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
upipibi commented 2026-11-24 07:06:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T06:00:52Z.


Full-suite run on this PR's head 045751d, since the description says the authoring machine had no Rust toolchain yet:

Tested

  • NVIDIA GeForce RTX 3070 (driver 616.56, wave32), Ryzen 9 5950X, Windows 11 Pro 26100, rustc 1.100.0 MSVC, debug
  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4: 656 passed, 0 failed, 40 ignored (17 test binaries, the e2e title included). It builds and every test passes on this head; the networking tests in networking_tests.rs are among them.
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested: AMD / wave64; no retail title. This PR changes runtime files (networking.rs, present.rs), so it still needs the xcl-smoke pair.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ivall/xcl:comment:7123488032 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/342#issuecomment-7123488032). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T06:00:52Z. --- Full-suite run on this PR's head `045751d`, since the description says the authoring machine had no Rust toolchain yet: **Tested** - NVIDIA GeForce RTX 3070 (driver 616.56, wave32), Ryzen 9 5950X, Windows 11 Pro 26100, rustc 1.100.0 MSVC, debug - `cargo build --workspace` then `cargo test --workspace --no-fail-fast -- --test-threads=4`: **656 passed, 0 failed, 40 ignored** (17 test binaries, the e2e title included). It builds and every test passes on this head; the networking tests in `networking_tests.rs` are among them. - SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64) **Not tested:** AMD / wave64; no retail title. This PR changes runtime files (`networking.rs`, `present.rs`), so it still needs the `xcl-smoke` pair. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 11:04:42 +00:00
raylitebull commented 2026-11-24 11:05:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-24T10:42:02Z.


Closing because this diff adds ~8,678 lines of duplicated source files at the repository root instead of editing crates/xcl/src/. Feel free to reopen a clean PR modifying the files under crates/xcl/src/.

<!-- greyfinch-sync:ivall/xcl:comment:7129128141 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/342#issuecomment-7129128141). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-24T10:42:02Z. --- Closing because this diff adds ~8,678 lines of duplicated source files at the repository root instead of editing `crates/xcl/src/`. Feel free to reopen a clean PR modifying the files under `crates/xcl/src/`.

Pull request closed

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
xcl-dev/xcl!338
No description provided.