feat(libSceNKWebKitRequirements): implement the SQLite exports #15186

Merged
Noxy-HNR merged 4 commits from upstream-pr/15186 into main 2026-11-05 23:16:39 +00:00
Noxy-HNR commented 2026-11-02 20:23:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-02T20:23:29Z.


What

The 50 sqlite3_* exports of libSceNKWebKitRequirements now run SQLite instead of throwing. SQLite is a new submodule, 3rdparty/sqlite (sqlite/sqlite at version-3.54.1). cmake/Sqlite.cmake builds it from source. It first builds SQLite's own host tools (autosetup/jimsh0.c as the Tcl interpreter, lemon, mkkeywordhash and mksourceid), and uses them to generate sqlite3.h, the parser, the opcode tables, keywordhash.h, pragma.h and ctime.c, the same way SQLite's main.mk does. No tclsh or system SQLite is needed, and no SQLite code is copied into core/.

src/Sqlite.cpp holds only thin guest adapters:

  • Each export forwards to the matching SQLite call with the public C prototype.
  • Guest callbacks (busy handler, authorizer, WAL hook, collation compare and destroy, scalar and aggregate functions) are called through SysV trampolines. The per-connection hook state lives in sqlite3_set_clientdata, so it is freed when the connection closes. sqlite3_user_data returns the guest's own pointer.
  • A guest destructor passed to sqlite3_bind_blob or sqlite3_bind_text16 is called right after SQLite copies the value, because SQLite cannot call a SysV function itself.
  • sqlite3_open_v2 maps ordinary file names through the guest path resolver. :memory:, empty names and non-URI names opened with SQLITE_OPEN_MEMORY pass through unchanged. With SQLITE_OPEN_URI, a file: URI passes through only when it has no % and either its path is exactly :memory: or its last mode parameter is memory; other file URIs throw through NotImplemented_nid_no_patch. The guest VFS name is ignored. Read-write opens record the database and its -wal, -shm and -journal paths for sceKernelSync.
  • Each successfully opened connection installs a host authorizer that refuses ATTACH DATABASE with a non-empty name, including the attachment performed by VACUUM INTO, with SQLITE_AUTH. The guest authorizer cannot disable this restriction. ATTACH '' and plain VACUUM remain supported; guest-path resolution for file-producing attachments is unimplemented and recorded in debt.

The prototypes are inferred from the export names, which hash to the inventory NIDs. Nothing was checked on a console, and the debt file records this along with the adapter limits. No title unblock is claimed.

Tested

New guest_nk_req_sqlite test, which calls only the guest exports:

  • Statements and results: prepare, bind, step, reset and clear for every bound type, plus every column and value accessor. It checks UTF-16 text and the blob round trip, that guest destructors run once (including when a bind fails), sqlite3_sql, sqlite3_next_stmt, last rowid, total changes and autocommit.
  • Callbacks: a scalar function with user_data and result_error, an aggregate that is created and then deleted, sqlite3_interrupt from inside a function, a collation in both encodings with its destroy calls on close, an authorizer denying DELETE (SQLITE_AUTH), and extended result codes.
  • File database through a guest path (/wal.db): WAL mode, the WAL hook (including the default autocheckpoint argument it replaces), sqlite3_wal_checkpoint_v2, a busy handler hit by a second connection behind BEGIN EXCLUSIVE, and sqlite3_busy_timeout replacing it.
  • File-path protections: misleading mode=memory text in paths, duplicate mode parameters, percent-encoded parameters and SQLITE_OPEN_MEMORY combined with file URIs must create no host file. Accepted memory URIs remain usable. ATTACH and VACUUM INTO are refused on memory and file connections, including after installing and clearing a permissive guest authorizer; plain VACUUM and empty-name attachment still work.

Current-head result:

  • At ec49a4f03fb635775909e285a408243dcebd4339, the hosted Windows build built and ran guest_nk_req_sqlite, which passed in 0.08 seconds. Applicable hosted checks pass. No fresh Linux runtime result for the URI/authorizer follow-up is recorded here.

Historical results from before the URI/authorizer follow-up:

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream b28bb77217: ctest -R "guest_nk_req_sqlite|public_headers" 66/66 passed.
  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: the host tools build and run under MinGW with no extra definitions. ctest -R guest_nk_req_sqlite passed 3 of 3 runs. A checkout with core.autocrlf=true adds SQLite's alt1 suffix to SQLITE_SOURCE_ID. That id is not exported and nothing depends on it.
  • python tools/check_conventions.py --base origin/main and python core/libs/tests/test_public_headers.py --audit-only (399 libraries, 27,365 exports): passed.
  • python tools/pr_overlap.py (1,690 open PRs): no other PR implements a sqlite3_* export. #14374 (zlib) and #14421 (libjpeg, libxml2, libpsl) are older and also create libSceNKWebKitRequirements/CMakeLists.txt. They also remove neighbouring stubs from Export.cpp and Identified.hpp, and edit the same debt lines (#14421 also touches .gitmodules). This PR goes after them, and I'll rebase it onto their build file as they land. #14435 and #14448 only touch the end of .gitmodules.

No console or retail-title test.

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: #14374, #14421
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5126877004 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15186). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-02T20:23:29Z. --- ### What The 50 `sqlite3_*` exports of libSceNKWebKitRequirements now run SQLite instead of throwing. SQLite is a new submodule, `3rdparty/sqlite` ([sqlite/sqlite](https://github.com/sqlite/sqlite) at `version-3.54.1`). `cmake/Sqlite.cmake` builds it from source. It first builds SQLite's own host tools (`autosetup/jimsh0.c` as the Tcl interpreter, `lemon`, `mkkeywordhash` and `mksourceid`), and uses them to generate `sqlite3.h`, the parser, the opcode tables, `keywordhash.h`, `pragma.h` and `ctime.c`, the same way SQLite's `main.mk` does. No tclsh or system SQLite is needed, and no SQLite code is copied into `core/`. `src/Sqlite.cpp` holds only thin guest adapters: - Each export forwards to the matching SQLite call with the public C prototype. - Guest callbacks (busy handler, authorizer, WAL hook, collation compare and destroy, scalar and aggregate functions) are called through SysV trampolines. The per-connection hook state lives in `sqlite3_set_clientdata`, so it is freed when the connection closes. `sqlite3_user_data` returns the guest's own pointer. - A guest destructor passed to `sqlite3_bind_blob` or `sqlite3_bind_text16` is called right after SQLite copies the value, because SQLite cannot call a SysV function itself. - `sqlite3_open_v2` maps ordinary file names through the guest path resolver. `:memory:`, empty names and non-URI names opened with `SQLITE_OPEN_MEMORY` pass through unchanged. With `SQLITE_OPEN_URI`, a `file:` URI passes through only when it has no `%` and either its path is exactly `:memory:` or its last `mode` parameter is `memory`; other file URIs throw through `NotImplemented_nid_no_patch`. The guest VFS name is ignored. Read-write opens record the database and its `-wal`, `-shm` and `-journal` paths for `sceKernelSync`. - Each successfully opened connection installs a host authorizer that refuses `ATTACH DATABASE` with a non-empty name, including the attachment performed by `VACUUM INTO`, with `SQLITE_AUTH`. The guest authorizer cannot disable this restriction. `ATTACH ''` and plain `VACUUM` remain supported; guest-path resolution for file-producing attachments is unimplemented and recorded in debt. The prototypes are inferred from the export names, which hash to the inventory NIDs. Nothing was checked on a console, and the debt file records this along with the adapter limits. No title unblock is claimed. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> New `guest_nk_req_sqlite` test, which calls only the guest exports: - Statements and results: prepare, bind, step, reset and clear for every bound type, plus every column and value accessor. It checks UTF-16 text and the blob round trip, that guest destructors run once (including when a bind fails), `sqlite3_sql`, `sqlite3_next_stmt`, last rowid, total changes and autocommit. - Callbacks: a scalar function with `user_data` and `result_error`, an aggregate that is created and then deleted, `sqlite3_interrupt` from inside a function, a collation in both encodings with its destroy calls on close, an authorizer denying `DELETE` (`SQLITE_AUTH`), and extended result codes. - File database through a guest path (`/wal.db`): WAL mode, the WAL hook (including the default autocheckpoint argument it replaces), `sqlite3_wal_checkpoint_v2`, a busy handler hit by a second connection behind `BEGIN EXCLUSIVE`, and `sqlite3_busy_timeout` replacing it. - File-path protections: misleading `mode=memory` text in paths, duplicate `mode` parameters, percent-encoded parameters and `SQLITE_OPEN_MEMORY` combined with file URIs must create no host file. Accepted memory URIs remain usable. `ATTACH` and `VACUUM INTO` are refused on memory and file connections, including after installing and clearing a permissive guest authorizer; plain `VACUUM` and empty-name attachment still work. Current-head result: - At `ec49a4f03fb635775909e285a408243dcebd4339`, the [hosted Windows build](https://github.com/boykopovar/AnyPS5/actions/runs/41987045319/job/127110170523) built and ran `guest_nk_req_sqlite`, which passed in 0.08 seconds. Applicable hosted checks pass. No fresh Linux runtime result for the URI/authorizer follow-up is recorded here. Historical results from before the URI/authorizer follow-up: - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream `b28bb77217`: `ctest -R "guest_nk_req_sqlite|public_headers"` **66/66 passed**. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: the host tools build and run under MinGW with no extra definitions. `ctest -R guest_nk_req_sqlite` **passed 3 of 3 runs**. A checkout with `core.autocrlf=true` adds SQLite's `alt1` suffix to `SQLITE_SOURCE_ID`. That id is not exported and nothing depends on it. - `python tools/check_conventions.py --base origin/main` and `python core/libs/tests/test_public_headers.py --audit-only` (399 libraries, 27,365 exports): passed. - `python tools/pr_overlap.py` (1,690 open PRs): no other PR implements a `sqlite3_*` export. #14374 (zlib) and #14421 (libjpeg, libxml2, libpsl) are older and also create `libSceNKWebKitRequirements/CMakeLists.txt`. They also remove neighbouring stubs from `Export.cpp` and `Identified.hpp`, and edit the same debt lines (#14421 also touches `.gitmodules`). This PR goes after them, and I'll rebase it onto their build file as they land. #14435 and #14448 only touch the end of `.gitmodules`. No console or retail-title test. ### 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: #14374, #14421 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
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!15186
No description provided.