feat(libSceNKWebKit): implement WebCore::parseCacheControlDirectives #16643

Merged
AlexWhitehouse merged 1 commit from upstream-pr/16643 into main 2026-11-09 08:16:32 +00:00
AlexWhitehouse commented 2026-11-07 12:13:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T12:13:41Z.


What

Implements libSceNKWebKit WebCore::parseCacheControlDirectives(const WebCore::HTTPHeaderMap&) (_ZN7WebCore27parseCacheControlDirectivesERKNS_13HTTPHeaderMapE, NID kB7iRn6G2NQ), which threw through NotImplemented_nid_no_patch. ResourceResponseBase calls it for a response's cache-policy queries (ResourceResponseBase.cpp). It reads the HTTPHeaderMap that #15326 implemented.

Source: Source/WebCore/platform/network/CacheValidation.cpp lines 176–349 and CacheValidation.h lines 62–79, at the PS5 WebKit revision the NKWebKit debt file and earlier ports use (80f77e94). src/CacheControl.cpp starts with that file's notice, copied byte for byte. It follows upstream:

  • Clean-up: the Cache-Control value has every character at or below ' ' and DEL removed.
  • Splitting (parseCacheHeader): directives are split on commas. Quoted values run to the next quote, and an unterminated quote ends parsing. Names and unquoted values stop at the first cache-header separator.
  • Directives:
    • names are compared ignoring ASCII case;
    • no-cache counts only without a value;
    • max-age, max-stale and stale-while-revalidate keep their first valid value;
    • a bare max-stale is infinity;
    • numbers go through StringView::toDouble, so fractions and negatives are kept and trailing junk is rejected. This uses the existing WTF::charactersToDouble exports for both character widths, which toDouble calls upstream.
  • Pragma fallback: when no-cache is still unset, it is set if Pragma contains no-cache, ignoring ASCII case.

ABI, from CacheValidation.h, Markable.h (lines 86–155) and Seconds.h (lines 223–240):

  • Layout: CacheControlDirectives holds three Markable<Seconds>, each a single double with NaN meaning "unset" and no separate flag, at offsets 0, 8 and 16. The bit-fields noCache, noStore, mustRevalidate and immutable are bits 0–3 of byte 24. The struct is 32 bytes, aligned to 8 and trivially copyable.
  • Return: under the x86-64 SysV ABI a struct this size is returned through a hidden pointer, so the export takes the destination in RDI and the header map in RSI (APS5_VABI). GCC 15's assembly for the export confirms this.
  • Checks: src/CacheControlAbi.hpp checks size, alignment, offsets and triviality with static_asserts.
  • Debt: a new entry records that the console's ABI is not measured. The inventory count drops from 6324 to 6323, and the export's row leaves the inventory table (recounted after rebasing onto main b66ca0e85a).

Tested

  • New test tests/CacheControl.cpp (nkwebkit_cachecontrol, registered by the NKWebKit tests glob). It builds header maps through the existing HTTPHeaderMap exports and checks every field and flag bit. Each of 36 cases runs with 8-bit and 16-bit header values, and there is an empty-map case. The cases cover:
    • each directive alone, and mixed case;
    • quoted and unterminated quoted values;
    • duplicate numeric directives (first value wins);
    • fractional, negative, out-of-range and malformed numbers;
    • no-cache with and without a value;
    • bare and valued max-stale;
    • control characters and spaces inside the header;
    • Pragma: no-cache with and without Cache-Control.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release), the NKWebKit group:
    • on main, 39/40 pass; the new test fails with _ZN7WebCore27parseCacheControlDirectivesERKNS_13HTTPHeaderMapE not implemented;
    • with this PR (63006f2064), 40/40 pass, and public_headers passes.
  • Mutation check: swapping the max-age and max-stale destinations fails with got 34 12 56 for inputs 12, 34 and 56.
  • Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): the NKWebKit group passes 40/40 at 63006f2064, including nkwebkit_cachecontrol, with no warnings in the new files.
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed.
  • python3 tools/pr_overlap.py --branch feat/libscenkwebkit-parse-cache-control-directives: no open PR implements this export or works in CacheValidation. #15213 implemented a different function from that file and is merged.
    • The tool flagged 86 PRs that share files with this branch, and all 86 were trial-merged, including #15686 and the URL PRs #14926–#14930 and #15867. None gains a conflict in code, ABI or tests.
    • #14212 (debt spacing) gains a conflict on the count line, and #13515 and #15246's existing conflicts in the umbrella header already cover the new include.
    • The NKWebKit count line is shared with about 50 open PRs (#14138–#16524), and with my #16642 (CookieUtil::defaultPathForURL). Whichever merges second recounts.

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:5201502673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16643). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T12:13:41Z. --- ### What Implements libSceNKWebKit `WebCore::parseCacheControlDirectives(const WebCore::HTTPHeaderMap&)` (`_ZN7WebCore27parseCacheControlDirectivesERKNS_13HTTPHeaderMapE`, NID `kB7iRn6G2NQ`), which threw through `NotImplemented_nid_no_patch`. `ResourceResponseBase` calls it for a response's cache-policy queries ([`ResourceResponseBase.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/ResourceResponseBase.cpp#L665-L720)). It reads the `HTTPHeaderMap` that #15326 implemented. **Source:** [`Source/WebCore/platform/network/CacheValidation.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/CacheValidation.cpp#L176-L349) lines 176–349 and [`CacheValidation.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/CacheValidation.h#L62-L79) lines 62–79, at the PS5 WebKit revision the NKWebKit debt file and earlier ports use (80f77e94). `src/CacheControl.cpp` starts with that file's notice, copied byte for byte. It follows upstream: - **Clean-up:** the `Cache-Control` value has every character at or below `' '` and DEL removed. - **Splitting** (`parseCacheHeader`): directives are split on commas. Quoted values run to the next quote, and an unterminated quote ends parsing. Names and unquoted values stop at the first cache-header separator. - **Directives:** - names are compared ignoring ASCII case; - `no-cache` counts only without a value; - `max-age`, `max-stale` and `stale-while-revalidate` keep their first valid value; - a bare `max-stale` is infinity; - numbers go through `StringView::toDouble`, so fractions and negatives are kept and trailing junk is rejected. This uses the existing `WTF::charactersToDouble` exports for both character widths, which `toDouble` calls upstream. - **`Pragma` fallback:** when `no-cache` is still unset, it is set if `Pragma` contains `no-cache`, ignoring ASCII case. **ABI**, from `CacheValidation.h`, [`Markable.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/Markable.h#L86-L155) (lines 86–155) and [`Seconds.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/Seconds.h#L223-L240) (lines 223–240): - **Layout:** `CacheControlDirectives` holds three `Markable<Seconds>`, each a single `double` with NaN meaning "unset" and no separate flag, at offsets 0, 8 and 16. The bit-fields `noCache`, `noStore`, `mustRevalidate` and `immutable` are bits 0–3 of byte 24. The struct is 32 bytes, aligned to 8 and trivially copyable. - **Return:** under the x86-64 SysV ABI a struct this size is returned through a hidden pointer, so the export takes the destination in RDI and the header map in RSI (`APS5_VABI`). GCC 15's assembly for the export confirms this. - **Checks:** `src/CacheControlAbi.hpp` checks size, alignment, offsets and triviality with `static_assert`s. - **Debt:** a new entry records that the console's ABI is not measured. The inventory count drops from 6324 to 6323, and the export's row leaves the inventory table (recounted after rebasing onto main b66ca0e85a). ### Tested - **New test `tests/CacheControl.cpp`** (`nkwebkit_cachecontrol`, registered by the NKWebKit tests glob). It builds header maps through the existing `HTTPHeaderMap` exports and checks every field and flag bit. Each of 36 cases runs with 8-bit and 16-bit header values, and there is an empty-map case. The cases cover: - each directive alone, and mixed case; - quoted and unterminated quoted values; - duplicate numeric directives (first value wins); - fractional, negative, out-of-range and malformed numbers; - `no-cache` with and without a value; - bare and valued `max-stale`; - control characters and spaces inside the header; - `Pragma: no-cache` with and without `Cache-Control`. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release), the NKWebKit group: - on `main`, 39/40 pass; the new test fails with `_ZN7WebCore27parseCacheControlDirectivesERKNS_13HTTPHeaderMapE not implemented`; - with this PR (63006f2064), 40/40 pass, and `public_headers` passes. - **Mutation check:** swapping the `max-age` and `max-stale` destinations fails with `got 34 12 56` for inputs 12, 34 and 56. - **Windows 11** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): the NKWebKit group passes 40/40 at 63006f2064, including `nkwebkit_cachecontrol`, with no warnings in the new files. - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. - **`python3 tools/pr_overlap.py --branch feat/libscenkwebkit-parse-cache-control-directives`:** no open PR implements this export or works in `CacheValidation`. #15213 implemented a different function from that file and is merged. - The tool flagged 86 PRs that share files with this branch, and all 86 were trial-merged, including #15686 and the URL PRs #14926–#14930 and #15867. None gains a conflict in code, ABI or tests. - #14212 (debt spacing) gains a conflict on the count line, and #13515 and #15246's existing conflicts in the umbrella header already cover the new include. - The NKWebKit count line is shared with about 50 open PRs (#14138–#16524), and with my #16642 (`CookieUtil::defaultPathForURL`). Whichever merges second recounts. ### 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!16643
No description provided.