feat(libs): the sceImeOpen text and external-keyboard filters #8009

Merged
primesoul-web merged 5 commits from upstream-pr/8009 into main 2026-10-20 10:20:36 +00:00
primesoul-web commented 2026-10-19 17:34:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-19T17:34:25Z.


What

the sceImeOpen text and external-keyboard filters on their own, split from the earlier revision of #7658 per its review: libSceIme 13/57 -> 14/57 on main 3fd1cc393 (66.69%, 4241/6359 -> 66.71%, 4242/6359, +1, no regressions; the denominator grew with the firmware-database exports since the pull request was opened).

sceImeOpen accepts a text filter and an external keyboard filter instead of throwing for them. The text filter runs on the edits of host input - typing, backspace, forward delete and a multiline Enter - following KytyPS5: the filter is called with the edited text, a buffer of maxTextLength UTF-16 units and its length, and a nonzero return, an output longer than the capacity, an unpaired surrogate or, without the multiline option, a line break keeps the edit unfiltered. An accepted output replaces the text, the caret stays where the edit put it and is clamped to the text and normalized past a surrogate pair, and one UpdateText carries the minimal edit delta of the whole old and new text; an output equal to the previous text sends no event. The external keyboard filter is stored on the session and is called only for keyboard events that carry key data, which the host input path does not produce, so it is never called. The debt entry carries the full wording.

Lindamea1's #7852 adds other IME exports in the same file; the hunks do not meet, and whichever lands second rebases.

Tested

GuestImeOpen walks both filters: the accepted and refused outputs, the edit deltas, the caret normalization, a stripping filter, an open with both filters, the external-keyboard-filter session, a filter that calls ImeCapturesKeyboard inside itself - the title's filter now runs in sceImeUpdate with the IME mutex released, like the event handler, so the callback cannot deadlock - and filters that call sceImeSetText and sceImeSetCaret while they run: both bump a revision beside the session id and the filtered commit is dropped when it changed, as KytyPS5 drops the commit when its revision changed - with sceImeSetText the title's own text wins, and with only sceImeSetCaret the edit is discarded, the session's text going back to the pre-edit text so it does not come back with the next edit. The test filters are APS5_VABI and assigned the way a guest pointer arrives. Linux x86-64, GCC, -Wall -Wextra clean on head 4c849bcad (the caret discard on top of the rework in eb78be803, main 3fd1cc393 carried); GuestImeParameters and GuestImeKeyboard pass unchanged; tools/check_conventions.py --base upstream/main passes; git merge-tree against main is clean.

Checklist

  • AI-assisted: yes
  • Depends on: none
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4924875521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-19T17:34:25Z. --- ### What the sceImeOpen text and external-keyboard filters on their own, split from the earlier revision of #7658 per its review: [libSceIme](../../../core/libs/prx/libSceIme/Export.cpp) 13/57 -> 14/57 on main 3fd1cc393 (66.69%, 4241/6359 -> 66.71%, 4242/6359, +1, no regressions; the denominator grew with the firmware-database exports since the pull request was opened). `sceImeOpen` accepts a text filter and an external keyboard filter instead of throwing for them. The text filter runs on the edits of host input - typing, backspace, forward delete and a multiline Enter - following [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/main/src/libs/ime.cpp): the filter is called with the edited text, a buffer of maxTextLength UTF-16 units and its length, and a nonzero return, an output longer than the capacity, an unpaired surrogate or, without the multiline option, a line break keeps the edit unfiltered. An accepted output replaces the text, the caret stays where the edit put it and is clamped to the text and normalized past a surrogate pair, and one UpdateText carries the minimal edit delta of the whole old and new text; an output equal to the previous text sends no event. The external keyboard filter is stored on the session and is called only for keyboard events that carry key data, which the host input path does not produce, so it is never called. The debt entry carries the full wording. Lindamea1's #7852 adds other IME exports in the same file; the hunks do not meet, and whichever lands second rebases. ### Tested GuestImeOpen walks both filters: the accepted and refused outputs, the edit deltas, the caret normalization, a stripping filter, an open with both filters, the external-keyboard-filter session, a filter that calls `ImeCapturesKeyboard` inside itself - the title's filter now runs in `sceImeUpdate` with the IME mutex released, like the event handler, so the callback cannot deadlock - and filters that call `sceImeSetText` and `sceImeSetCaret` while they run: both bump a revision beside the session id and the filtered commit is dropped when it changed, as KytyPS5 drops the commit when its revision changed - with `sceImeSetText` the title's own text wins, and with only `sceImeSetCaret` the edit is discarded, the session's text going back to the pre-edit text so it does not come back with the next edit. The test filters are `APS5_VABI` and assigned the way a guest pointer arrives. Linux x86-64, GCC, `-Wall -Wextra` clean on head 4c849bcad (the caret discard on top of the rework in eb78be803, main 3fd1cc393 carried); `GuestImeParameters` and `GuestImeKeyboard` pass unchanged; `tools/check_conventions.py --base upstream/main` passes; `git merge-tree` against `main` is clean. ### Checklist - [x] AI-assisted: yes - [x] Depends on: none
github-actions[bot] commented 2026-10-19 17:35:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T17:35:15Z.


Progress report (8a7ba4b → 4c849bc)

📈 System libraries: 65.19% (+0.02%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceIme sceImeOpen_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273308527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6273308527). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T17:35:15Z. --- <!-- progress-report --> ### Progress report (8a7ba4b → 4c849bc) 📈 **System libraries**: 65.19% (+0.02%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceIme | `sceImeOpen_nid_postfix` | </details>
github-actions[bot] commented 2026-10-19 17:45:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T17:45:06Z.


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 8036 docs/dev/debt/libSceIme.md L11

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 5965 core/libs/SceTypes.hpp
PR 6044 core/libs/tests/GuestImeOpen.cpp
PR 6977 core/libs/SceTypes.hpp
PR 7081 core/libs/SceTypes.hpp
PR 7412 core/libs/SceTypes.hpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273499640 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6273499640). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T17:45:06Z. --- <!-- pr-overlap --> 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 8036](https://www.github.com/boykopovar/AnyPS5/pull/8036) | `docs/dev/debt/libSceIme.md` [L11](https://github.com/boykopovar/AnyPS5/blob/8a7ba4beb4f439aaf52297d86ec9174d9531b442/docs/dev/debt/libSceIme.md#L11) | | | 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 5965](https://www.github.com/boykopovar/AnyPS5/pull/5965) | `core/libs/SceTypes.hpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestImeOpen.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/SceTypes.hpp` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/SceTypes.hpp` | | [PR 7412](https://www.github.com/boykopovar/AnyPS5/pull/7412) | `core/libs/SceTypes.hpp` |
primesoul-web commented 2026-10-19 18:04:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-19T18:04:28Z.


Manual check of the shared file flagged above (#6044 could not be auto-compared because it conflicts with the base branch itself):

  • #6044 reorganizes the test tree only: core/libs/tests/GuestImeOpen.cpp is renamed to core/libs/tests/input/GuestImeOpen.cpp with zero content changes (0 additions / 0 deletions), alongside the matching libSceIme/CMakeLists.txt path and CTest-label updates. It touches no library sources.
  • This PR changes the content of core/libs/tests/GuestImeOpen.cpp (+156/-9, the filter tests) and libSceIme/Export.cpp + the debt entry; the file's path is untouched.

The two are orthogonal — rename vs. content — with no shared hunks and no overlapping exports, so nothing needs coordinating beyond ordering: if #6044 lands first, this branch rebases with the same hunks applied at the new path (rename + modify merges cleanly), and if this lands first, #6044's rename simply carries the new content along. Depends on: none stays accurate, including for #7852 (different exports in the same Export.cpp, same agreement: whichever lands second rebases).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273858307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6273858307). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-19T18:04:28Z. --- Manual check of the shared file flagged above (#6044 could not be auto-compared because it conflicts with the base branch itself): - #6044 reorganizes the test tree only: `core/libs/tests/GuestImeOpen.cpp` is **renamed** to `core/libs/tests/input/GuestImeOpen.cpp` with zero content changes (0 additions / 0 deletions), alongside the matching `libSceIme/CMakeLists.txt` path and CTest-label updates. It touches no library sources. - This PR changes the **content** of `core/libs/tests/GuestImeOpen.cpp` (+156/-9, the filter tests) and `libSceIme/Export.cpp` + the debt entry; the file's path is untouched. The two are orthogonal — rename vs. content — with no shared hunks and no overlapping exports, so nothing needs coordinating beyond ordering: if #6044 lands first, this branch rebases with the same hunks applied at the new path (rename + modify merges cleanly), and if this lands first, #6044's rename simply carries the new content along. `Depends on: none` stays accurate, including for #7852 (different exports in the same `Export.cpp`, same agreement: whichever lands second rebases).
primesoul-web commented 2026-10-19 18:45:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-19T18:45:07Z.


Manual check of the two new entries above (both ymatrix1):

  • #8019 declares 43 firmware Ime interfaces with unknown signatures as NotImplemented_nid_no_patch (the sceImeVsh* / keyboard family, appended after sceImeUpdate at the tail of Export.cpp) plus their Unknown-function-info debt entries. #8036 implements sceImeFilterText from the firmware 13.60 disassembly, adds a sceImeCheckFilterText marker, and brings its own headers and GuestImeFilterText test. Neither touches sceImeOpen's session, text-filter or extended-keyboard path — the same-exports column above is empty and the hunks agree with it: their Export.cpp additions sit after sceImeKeyboardSetMode / at the file tail, this PR's are inside sceImeOpen's body.
  • The shared spot is the debt file's L10 region, where all three PRs insert adjacent bullets — a text-level conflict only, resolved by whichever lands second. Depends on: none stays accurate for both: ordering, not a build-on. If either lands first this branch rebases with the sceImeOpen hunks unchanged, and the reverse holds too.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274648421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6274648421). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-19T18:45:07Z. --- Manual check of the two new entries above (both ymatrix1): - **#8019** declares 43 firmware Ime interfaces with unknown signatures as `NotImplemented_nid_no_patch` (the `sceImeVsh*` / keyboard family, appended after `sceImeUpdate` at the tail of `Export.cpp`) plus their Unknown-function-info debt entries. **#8036** implements `sceImeFilterText` from the firmware 13.60 disassembly, adds a `sceImeCheckFilterText` marker, and brings its own headers and `GuestImeFilterText` test. Neither touches `sceImeOpen`'s session, text-filter or extended-keyboard path — the same-exports column above is empty and the hunks agree with it: their `Export.cpp` additions sit after `sceImeKeyboardSetMode` / at the file tail, this PR's are inside `sceImeOpen`'s body. - The shared spot is the debt file's L10 region, where all three PRs insert adjacent bullets — a text-level conflict only, resolved by whichever lands second. `Depends on: none` stays accurate for both: ordering, not a build-on. If either lands first this branch rebases with the `sceImeOpen` hunks unchanged, and the reverse holds too.
wachi35676 commented 2026-10-20 00:15:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T00:15:50Z.


Windows 11, Ryzen 5 9600X, WinLibs GCC 15.2.0 (UCRT), Release, BUILD_TESTING=ON. Head 845467718 merged onto main eb7500680. On Windows, guest_ime_open passes, and so do the other guest_ime_* tests. Linux: WSL Ubuntu 24.04, GCC 13.3, Release: builds, and the test passes. Negative control: with Export.cpp without this PR's hunks, guest_ime_open aborts with sceImeOpen: text filter not implemented.

I compared the logic with KytyPS5 imeCommon.cpp and ime.cpp CommitFilteredText. RunTextFilter, ComputeEditDelta, the caret normalization, and keeping the unfiltered edit on a rejected output all match. The debt links KytyPS5 main; a pinned commit would keep the link stable.

Defect on Windows: the filter is called with the wrong calling convention. This PR is the first code that calls Param::filter, and the type is declared without APS5_VABI (SceTypes.hpp:1158):

using ImeTextFilter = std::int32_t (*)(char16_t*, std::uint32_t*, const char16_t*, std::uint32_t);

The event handler in the same struct is using EventHandler = void (APS5_VABI *)(...) (line 1241). A converted title's filter is SysV code, so on Windows the host passes the four arguments in rcx/rdx/r8/r9 while the guest reads rdi/rsi/rdx/rcx. The test's filters are ordinary host functions (MS ABI), so they cannot catch this.

Probe: I changed only UpperFilter in GuestImeOpen.cpp to int32_t APS5_VABI UpperFilter(...) and set param.filter = reinterpret_cast<ImeTextFilter>(&UpperFilter), the way a guest pointer arrives. Result:

1/1 Test #1166: guest_ime_open ...***Exception: SegFault
FATAL: unhandled exception 0xc0000005 ... write of 0x000000b13ca00000
  #0 libSceIme.prx+0x5382

On Linux, APS5_VABI is empty and both conventions are the same, so only Windows is affected. Fix: declare ImeTextFilter (and ImeExtKeyboardFilter, stored here but not called yet) as (APS5_VABI *), and declare the test filters APS5_VABI so the test covers the guest convention.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6280245460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6280245460). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T00:15:50Z. --- Windows 11, Ryzen 5 9600X, WinLibs GCC 15.2.0 (UCRT), Release, `BUILD_TESTING=ON`. Head `845467718` merged onto `main` eb7500680. On Windows, `guest_ime_open` passes, and so do the other `guest_ime_*` tests. Linux: WSL Ubuntu 24.04, GCC 13.3, Release: builds, and the test passes. Negative control: with `Export.cpp` without this PR's hunks, `guest_ime_open` aborts with `sceImeOpen: text filter not implemented`. I compared the logic with KytyPS5 [`imeCommon.cpp`](https://github.com/KytyPS5/KytyPS5/blob/1211958b4eb38256cc0c5c7ba92d668820c05389/src/libs/imeCommon.cpp) and [`ime.cpp`](https://github.com/KytyPS5/KytyPS5/blob/1211958b4eb38256cc0c5c7ba92d668820c05389/src/libs/ime.cpp) `CommitFilteredText`. `RunTextFilter`, `ComputeEditDelta`, the caret normalization, and keeping the unfiltered edit on a rejected output all match. The debt links KytyPS5 `main`; a pinned commit would keep the link stable. **Defect on Windows: the filter is called with the wrong calling convention.** This PR is the first code that calls `Param::filter`, and the type is declared without `APS5_VABI` (`SceTypes.hpp:1158`): ```cpp using ImeTextFilter = std::int32_t (*)(char16_t*, std::uint32_t*, const char16_t*, std::uint32_t); ``` The event handler in the same struct is `using EventHandler = void (APS5_VABI *)(...)` (line 1241). A converted title's filter is SysV code, so on Windows the host passes the four arguments in rcx/rdx/r8/r9 while the guest reads rdi/rsi/rdx/rcx. The test's filters are ordinary host functions (MS ABI), so they cannot catch this. Probe: I changed only `UpperFilter` in `GuestImeOpen.cpp` to `int32_t APS5_VABI UpperFilter(...)` and set `param.filter = reinterpret_cast<ImeTextFilter>(&UpperFilter)`, the way a guest pointer arrives. Result: ``` 1/1 Test #1166: guest_ime_open ...***Exception: SegFault FATAL: unhandled exception 0xc0000005 ... write of 0x000000b13ca00000 #0 libSceIme.prx+0x5382 ``` On Linux, `APS5_VABI` is empty and both conventions are the same, so only Windows is affected. Fix: declare `ImeTextFilter` (and `ImeExtKeyboardFilter`, stored here but not called yet) as `(APS5_VABI *)`, and declare the test filters `APS5_VABI` so the test covers the guest convention. AI-assisted: yes (Claude Code); results above were run on this machine.
oneandonlydean commented 2026-10-20 04:30:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T04:30:47Z.


@primesoul-web thanks, the edit-delta and caret handling look right. Two things before this can go in, both about calling the title's filter:

  1. ImeTextFilter and ImeExtKeyboardFilter in SceTypes.hpp are declared without APS5_VABI, unlike EventHandler. On Windows APS5_VABI is sysv_abi, so calling a title's filter through these types uses the wrong calling convention there. Main never called them (it threw), so this PR is the first caller. The test filters in GuestImeOpen.cpp are plain host functions, so they match the current typedef and Windows CI passes anyway. Could you add APS5_VABI to both typedefs and to the test filters?
  2. The filter runs inside Apply, which ImePublishInput_nid_postfix calls with g_imeMutex held, on the host input path (ImeTextInput::HandleEvent in VideoOut). So title code runs on a host thread under the IME lock, and a filter that calls any sceIme* function would deadlock. The event handler is only called from sceImeUpdate, on the title's thread, after the lock is released. Could the filter run there too, e.g. by queueing the host edit and applying and filtering it in sceImeUpdate?
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6283417525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6283417525). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T04:30:47Z. --- @primesoul-web thanks, the edit-delta and caret handling look right. Two things before this can go in, both about calling the title's filter: 1. `ImeTextFilter` and `ImeExtKeyboardFilter` in `SceTypes.hpp` are declared without `APS5_VABI`, unlike `EventHandler`. On Windows `APS5_VABI` is `sysv_abi`, so calling a title's filter through these types uses the wrong calling convention there. Main never called them (it threw), so this PR is the first caller. The test filters in `GuestImeOpen.cpp` are plain host functions, so they match the current typedef and Windows CI passes anyway. Could you add `APS5_VABI` to both typedefs and to the test filters? 2. The filter runs inside `Apply`, which `ImePublishInput_nid_postfix` calls with `g_imeMutex` held, on the host input path (`ImeTextInput::HandleEvent` in VideoOut). So title code runs on a host thread under the IME lock, and a filter that calls any `sceIme*` function would deadlock. The event handler is only called from `sceImeUpdate`, on the title's thread, after the lock is released. Could the filter run there too, e.g. by queueing the host edit and applying and filtering it in `sceImeUpdate`?
primesoul-web commented 2026-10-20 05:45:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-20T05:45:24Z.


Thank you for the Windows and WSL runs and for the probe - that is a real defect and it is fixed, together with the Kyty link pinning you suggested.

ImeTextFilter and ImeExtKeyboardFilter in SceTypes.hpp are now declared APS5_VABI (5b2f82913), matching EventHandler two sections below them. The test filters in GuestImeOpen.cpp are APS5_VABI functions assigned through reinterpret_cast, exactly your probe pattern, so the test now exercises the guest-callback convention instead of matching the host typedef. The debt entry pins KytyPS5 at the commit you linked, so the reference stays stable.

With the typedef fixed, GuestImeOpen still passes and GuestImeParameters / GuestImeKeyboard are unchanged; one new session is in the test, described in the reply to the review below.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284315139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6284315139). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-20T05:45:24Z. --- Thank you for the Windows and WSL runs and for the probe - that is a real defect and it is fixed, together with the Kyty link pinning you suggested. `ImeTextFilter` and `ImeExtKeyboardFilter` in `SceTypes.hpp` are now declared `APS5_VABI` (5b2f82913), matching `EventHandler` two sections below them. The test filters in `GuestImeOpen.cpp` are `APS5_VABI` functions assigned through `reinterpret_cast`, exactly your probe pattern, so the test now exercises the guest-callback convention instead of matching the host typedef. The debt entry pins [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/1211958b4eb38256cc0c5c7ba92d668820c05389/src/libs/ime.cpp) at the commit you linked, so the reference stays stable. With the typedef fixed, `GuestImeOpen` still passes and `GuestImeParameters` / `GuestImeKeyboard` are unchanged; one new session is in the test, described in the reply to the review below.
primesoul-web commented 2026-10-20 05:45:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-20T05:45:25Z.


Thank you for the review - both points are addressed in 5b2f82913.

Calling convention. ImeTextFilter and ImeExtKeyboardFilter are declared APS5_VABI in SceTypes.hpp, and the test filters are APS5_VABI functions assigned through reinterpret_cast the way a guest pointer arrives, so a Windows build now type-checks the guest-callback path the title actually uses.

Threading. The filter no longer runs on the host input path. ImePublishInput_nid_postfix only queues the edit under the IME mutex; sceImeUpdate pops one edit at a time on the title's thread, applies the structural change under the mutex, then runs the title's filter with the mutex released - the same contract as the event handler below it - and commits the filtered text and the UpdateText event under the mutex again. A filter that calls any sceIme* export can no longer deadlock, and GuestImeOpen now proves it: a LockingFilter session calls ImeCapturesKeyboard_nid_postfix inside the filter, which takes the IME mutex, and the run completes. The commit is dropped if the session was closed or reopened while the filter ran (a session id guards it), and queued edits keep their ordering: each sceImeUpdate loop drains the edit queue before delivering events, so an edit's UpdateText always precedes the caret events of the edits after it. The debt entry states the whole model: queue under the mutex, apply and filter on the title's thread, serialized commits.

The branch also carries main a98590dec (the #8019 / #7852 wave re-touched Export.cpp and the debt file; the 43 unknown-signature Ime declarations and their debt entries are carried, the sceImeOpen hunks sit unchanged inside their own region), and the metric line is re-measured on it: 13/57 -> 14/57, +1, no regressions.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284315359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6284315359). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-20T05:45:25Z. --- Thank you for the review - both points are addressed in 5b2f82913. **Calling convention.** `ImeTextFilter` and `ImeExtKeyboardFilter` are declared `APS5_VABI` in `SceTypes.hpp`, and the test filters are `APS5_VABI` functions assigned through `reinterpret_cast` the way a guest pointer arrives, so a Windows build now type-checks the guest-callback path the title actually uses. **Threading.** The filter no longer runs on the host input path. `ImePublishInput_nid_postfix` only queues the edit under the IME mutex; `sceImeUpdate` pops one edit at a time on the title's thread, applies the structural change under the mutex, then runs the title's filter with the mutex released - the same contract as the event handler below it - and commits the filtered text and the UpdateText event under the mutex again. A filter that calls any `sceIme*` export can no longer deadlock, and `GuestImeOpen` now proves it: a `LockingFilter` session calls `ImeCapturesKeyboard_nid_postfix` inside the filter, which takes the IME mutex, and the run completes. The commit is dropped if the session was closed or reopened while the filter ran (a session id guards it), and queued edits keep their ordering: each `sceImeUpdate` loop drains the edit queue before delivering events, so an edit's UpdateText always precedes the caret events of the edits after it. The debt entry states the whole model: queue under the mutex, apply and filter on the title's thread, serialized commits. The branch also carries main a98590dec (the #8019 / #7852 wave re-touched `Export.cpp` and the debt file; the 43 unknown-signature Ime declarations and their debt entries are carried, the `sceImeOpen` hunks sit unchanged inside their own region), and the metric line is re-measured on it: 13/57 -> 14/57, +1, no regressions.
wachi35676 commented 2026-10-20 06:08:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T06:08:24Z.


I re-tested 5b2f82913 merged onto main 1ed63f63c. The calling convention is fixed, and the filter now runs on the title's thread. One ordering gap remains, compared with KytyPS5.

  • Windows (11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release): guest_ime_parameters, guest_ime_keyboard, guest_ime_open and guest_ime_dialog pass 4/4 in three runs.
  • Negative control: I reverted only the SceTypes.hpp hunk. guest_ime_open then fails with ***Exception: SegFault, FATAL: unhandled exception 0xc0000005 ... write of 0x00007ff948adb6cc, and the other three still pass. The test now covers the guest SysV convention.
  • WSL (Ubuntu 24.04, GCC 13.3, Release): the same merge passes 4/4 in three runs.
  • check_conventions.py --base 1ed63f63c: 0 errors. There are 2 debt-length warnings, for lines 11 and 61 of libSceIme.md.

Threading: the new model matches KytyPS5 at the pinned commit. Kyty's HostQueueExternalInput only queues the input, and ImeUpdate → ApplyExternalInputs runs the filter on the caller's thread with g_mutex released. The source and output buffers are a host copy and a host std::vector that live in the sceImeUpdate frame, so nothing guest-owned is touched after close. A close or reopen during the filter is caught by the session id.

Remaining gap: a sceImeSetText made while the filter runs is overwritten. Apply writes the unfiltered edit into session.text before the mutex is released. CommitFilteredEdit then checks only the session id and assigns the filter output unconditionally. Kyty does not change the live text until it commits: CommitFilteredText drops the commit when g_state.revision changed (ImeSetText and ImeSetCaret call UpdateRevisionLocked) or when the text is no longer old_text.

Probe (8009_settext_probe.diff): a filter that calls sceImeSetText(u"zz", 2) and then returns its source. Start text ab, then type c:

PROBE setText-in-filter rc=0 events=1 buffer=abc [id=1 idx=2 len=1 caret=2]

(the same in 3 of 3 runs)

sceImeSetText returned 0, but the title's text is lost. The buffer is back to abc, an UpdateText is sent, and the caret is left at 2, which is the clamp from SetText, not 3. Under Kyty's rule the result would be zz with no event.

A second title thread that calls sceImeSetText or sceImeSetCaret while the filter runs goes through the same code. I did not run that case. A revision counter that sceImeSetText and sceImeSetCaret bump, checked together with the id before the commit, would match Kyty.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284611161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6284611161). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T06:08:24Z. --- I re-tested `5b2f82913` merged onto `main` 1ed63f63c. The calling convention is fixed, and the filter now runs on the title's thread. One ordering gap remains, compared with KytyPS5. - **Windows** (11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release): `guest_ime_parameters`, `guest_ime_keyboard`, `guest_ime_open` and `guest_ime_dialog` pass 4/4 in three runs. - **Negative control:** I reverted only the `SceTypes.hpp` hunk. `guest_ime_open` then fails with `***Exception: SegFault`, `FATAL: unhandled exception 0xc0000005 ... write of 0x00007ff948adb6cc`, and the other three still pass. The test now covers the guest SysV convention. - **WSL** (Ubuntu 24.04, GCC 13.3, Release): the same merge passes 4/4 in three runs. - `check_conventions.py --base 1ed63f63c`: 0 errors. There are 2 `debt-length` warnings, for lines 11 and 61 of `libSceIme.md`. **Threading:** the new model matches KytyPS5 at the pinned commit. Kyty's `HostQueueExternalInput` only queues the input, and `ImeUpdate` → `ApplyExternalInputs` runs the filter on the caller's thread with `g_mutex` released. The source and output buffers are a host copy and a host `std::vector` that live in the `sceImeUpdate` frame, so nothing guest-owned is touched after close. A close or reopen during the filter is caught by the session id. **Remaining gap: a `sceImeSetText` made while the filter runs is overwritten.** `Apply` writes the unfiltered edit into `session.text` before the mutex is released. `CommitFilteredEdit` then checks only the session id and assigns the filter output unconditionally. Kyty does not change the live text until it commits: `CommitFilteredText` drops the commit when `g_state.revision` changed (`ImeSetText` and `ImeSetCaret` call `UpdateRevisionLocked`) or when the text is no longer `old_text`. Probe (`8009_settext_probe.diff`): a filter that calls `sceImeSetText(u"zz", 2)` and then returns its source. Start text `ab`, then type `c`: ``` PROBE setText-in-filter rc=0 events=1 buffer=abc [id=1 idx=2 len=1 caret=2] ``` (the same in 3 of 3 runs) `sceImeSetText` returned 0, but the title's text is lost. The buffer is back to `abc`, an UpdateText is sent, and the caret is left at 2, which is the clamp from `SetText`, not 3. Under Kyty's rule the result would be `zz` with no event. A second title thread that calls `sceImeSetText` or `sceImeSetCaret` while the filter runs goes through the same code. I did not run that case. A revision counter that `sceImeSetText` and `sceImeSetCaret` bump, checked together with the id before the commit, would match Kyty. AI-assisted: yes (Claude Code); results above were run on this machine.
oneandonlydean commented 2026-10-20 06:32:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T06:32:12Z.


Thanks, both points are fixed: the filter types and the test filters are APS5_VABI now, and the filter runs from sceImeUpdate outside the lock (the LockingFilter test deadlocks against the previous version and passes on this one).

Two small things before this can merge:

  1. A sceImeSetText or sceImeSetCaret call made while the filter runs is overwritten. Apply puts the unfiltered edit into session.text before the lock is released, and CommitFilteredEdit then checks only the session id before assigning the filter's output, syncing the buffers and queuing an UpdateText. So if the filter calls sceImeSetText, or another title thread does while the filter runs, the title's text is replaced with the filtered edit even though sceImeSetText returned 0 (wachi35676's probe above: start ab, type c, filter sets zz, buffer ends as abc). KytyPS5 avoids this by bumping a revision in ImeSetText/ImeSetCaret and dropping the filtered commit when the revision changed or the text is no longer the old text. Could you add the same check (a revision counter beside id, checked before the commit) and a test where the filter calls sceImeSetText?
  2. Debt doc: sceImeOpen used to throw for an external keyboard filter, and now it stores the filter but never calls it. That's fine, since libSceIme doesn't produce keycode events yet, but the debt entry dropped the "throws" sentence without replacing it. Please add a sentence saying the external keyboard filter is accepted and never called because no keycode events are produced. While you're there, pinning the KytyPS5 link to a commit (as in wachi35676's comment) would keep it stable.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284923675 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6284923675). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T06:32:12Z. --- Thanks, both points are fixed: the filter types and the test filters are `APS5_VABI` now, and the filter runs from `sceImeUpdate` outside the lock (the `LockingFilter` test deadlocks against the previous version and passes on this one). Two small things before this can merge: 1. **A `sceImeSetText` or `sceImeSetCaret` call made while the filter runs is overwritten.** `Apply` puts the unfiltered edit into `session.text` before the lock is released, and `CommitFilteredEdit` then checks only the session id before assigning the filter's output, syncing the buffers and queuing an UpdateText. So if the filter calls `sceImeSetText`, or another title thread does while the filter runs, the title's text is replaced with the filtered edit even though `sceImeSetText` returned 0 (wachi35676's probe above: start `ab`, type `c`, filter sets `zz`, buffer ends as `abc`). KytyPS5 avoids this by bumping a revision in `ImeSetText`/`ImeSetCaret` and dropping the filtered commit when the revision changed or the text is no longer the old text. Could you add the same check (a revision counter beside `id`, checked before the commit) and a test where the filter calls `sceImeSetText`? 2. **Debt doc:** `sceImeOpen` used to throw for an external keyboard filter, and now it stores the filter but never calls it. That's fine, since libSceIme doesn't produce keycode events yet, but the debt entry dropped the "throws" sentence without replacing it. Please add a sentence saying the external keyboard filter is accepted and never called because no keycode events are produced. While you're there, pinning the KytyPS5 link to a commit (as in wachi35676's comment) would keep it stable.
primesoul-web commented 2026-10-20 07:27:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-20T07:27:16Z.


Thank you for the re-test and for the probe - the ordering gap reproduced exactly as you described it, and it is fixed the way you suggested, in eb78be803.

The session now carries a revision beside its id. sceImeSetText and sceImeSetCaret bump it under the IME mutex, and sceImeUpdate records the revision together with the session id when it defers the filter; the filtered commit is dropped when either changed while the filter ran, which is KytyPS5's CommitFilteredText rule at the pinned commit. Your probe now answers what you predicted: sceImeSetText returns 0 inside the filter, the run sends no UpdateText, and the buffer ends as zz with the caret at 2 - the title's own text wins and the edit is dropped. A second title thread that calls sceImeSetText or sceImeSetCaret during the filter goes through the same mutex path, so the same guard covers it; GuestImeOpen walks it with a SetInsideFilter session built on your probe pattern, and GuestImeParameters / GuestImeKeyboard still pass unchanged.

On the two debt-length warnings: they are the known advisory class for the two long Ime entries and the check passes; the text-filter entry grew by one sentence for the revision rule, and I have kept the wording the model needs rather than splitting it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285726968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6285726968). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-20T07:27:16Z. --- Thank you for the re-test and for the probe - the ordering gap reproduced exactly as you described it, and it is fixed the way you suggested, in eb78be803. The session now carries a `revision` beside its id. `sceImeSetText` and `sceImeSetCaret` bump it under the IME mutex, and `sceImeUpdate` records the revision together with the session id when it defers the filter; the filtered commit is dropped when either changed while the filter ran, which is KytyPS5's `CommitFilteredText` rule at the pinned commit. Your probe now answers what you predicted: `sceImeSetText` returns 0 inside the filter, the run sends no UpdateText, and the buffer ends as `zz` with the caret at 2 - the title's own text wins and the edit is dropped. A second title thread that calls `sceImeSetText` or `sceImeSetCaret` during the filter goes through the same mutex path, so the same guard covers it; `GuestImeOpen` walks it with a `SetInsideFilter` session built on your probe pattern, and `GuestImeParameters` / `GuestImeKeyboard` still pass unchanged. On the two `debt-length` warnings: they are the known advisory class for the two long Ime entries and the check passes; the text-filter entry grew by one sentence for the revision rule, and I have kept the wording the model needs rather than splitting it.
primesoul-web commented 2026-10-20 07:27:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-20T07:27:17Z.


Thank you for the re-review - both points are addressed in eb78be803, and the branch now carries main 3fd1cc393 (head a0356d0cd).

The revision guard. The session carries a revision beside its id. sceImeSetText and sceImeSetCaret bump it under the IME mutex, and sceImeUpdate records the revision together with the session id when it defers the filter; the filtered commit is dropped when either changed while the filter ran, as KytyPS5 drops the commit when its revision changed. The unfiltered edit no longer overwrites the title's own setting: in the test you asked for, a filter calls sceImeSetText(u"zz", 2) and then returns its source; with start text ab and a typed c, sceImeSetText returns 0, the run sends no UpdateText, and the buffer ends as zz instead of the abc of wachi35676's probe above. A second title thread that calls sceImeSetText or sceImeSetCaret while the filter runs goes through the same mutex path, so the same guard covers it; GuestImeOpen walks the session (SetInsideFilter, built on the probe), GuestImeParameters / GuestImeKeyboard still pass unchanged, and the debt entry states the rule beside the session-id drop.

The debt doc. The Silent-stubs sceImeOpen entry now ends with the sentence you asked for: the external keyboard filter is accepted and never called because no keycode events are produced. The sceImeKeyboardOpen / sceImeKeyboardClose entry's Kyty link is pinned to the same commit as the text-filter entry (1211958b), so no reference in the file floats on main, and the Functional text-filter entry now states the revision rule as well.

The metric line is re-measured on the carried main: 13/57 -> 14/57 on 3fd1cc393, +1, no regressions.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285727262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6285727262). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-20T07:27:17Z. --- Thank you for the re-review - both points are addressed in eb78be803, and the branch now carries main 3fd1cc393 (head a0356d0cd). **The revision guard.** The session carries a `revision` beside its id. `sceImeSetText` and `sceImeSetCaret` bump it under the IME mutex, and `sceImeUpdate` records the revision together with the session id when it defers the filter; the filtered commit is dropped when either changed while the filter ran, as KytyPS5 drops the commit when its revision changed. The unfiltered edit no longer overwrites the title's own setting: in the test you asked for, a filter calls `sceImeSetText(u"zz", 2)` and then returns its source; with start text `ab` and a typed `c`, `sceImeSetText` returns 0, the run sends no UpdateText, and the buffer ends as `zz` instead of the `abc` of wachi35676's probe above. A second title thread that calls `sceImeSetText` or `sceImeSetCaret` while the filter runs goes through the same mutex path, so the same guard covers it; `GuestImeOpen` walks the session (`SetInsideFilter`, built on the probe), `GuestImeParameters` / `GuestImeKeyboard` still pass unchanged, and the debt entry states the rule beside the session-id drop. **The debt doc.** The Silent-stubs `sceImeOpen` entry now ends with the sentence you asked for: the external keyboard filter is accepted and never called because no keycode events are produced. The `sceImeKeyboardOpen` / `sceImeKeyboardClose` entry's Kyty link is pinned to the same commit as the text-filter entry (`1211958b`), so no reference in the file floats on `main`, and the Functional text-filter entry now states the revision rule as well. The metric line is re-measured on the carried main: 13/57 -> 14/57 on 3fd1cc393, +1, no regressions.
oneandonlydean commented 2026-10-20 07:43:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T07:43:49Z.


Thanks. The revision check and the SetInsideFilter test do what we asked: with the revision check removed, the test fails at "an edit whose filter set the text sends no event". The debt sentence and the pinned KytyPS5 link look good too.

One case is still left over. With a filter set, CommitEdit returns early, so session.text already holds the unfiltered edit while the title's buffers still hold the old text. When the commit is dropped because sceImeSetText ran, that doesn't matter, since SetText replaced the text. When it's dropped because only sceImeSetCaret ran, the unfiltered edit stays in session.text: it is never synced and sends no event, and it comes back with the next edit. I checked this with your test file plus one extra check: a pass-through filter that calls sceImeSetCaret (index 0) on its first call, starting from ab, then typing c and d:

after 'c': events=0 buffer="ab"
after 'd': events=1 buffer="dabc"   (the dropped 'c' is back; the event reports a 1-unit insert)

Dropping the commit should also drop the edit, as in KytyPS5, where the edit only lands at commit. This passes your whole test file and gives dab for the case above:

if (g_session && g_session->id == sessionId) {
    if (g_session->revision == sessionRevision) {
        CommitFilteredEdit(*g_session, accepted ? &filtered : nullptr, filterOldText);
    } else if (g_session->text == filterText) {
        g_session->text = filterOldText;
        NormalizeCaret(*g_session);
    }
}

Could you add that, plus a test like the one above (a sceImeSetCaret inside the filter, then a second edit, then check the buffer)? In the debt entry, "the edit sends no event" could then read "the edit is discarded and sends no event".

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285998681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6285998681). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T07:43:49Z. --- Thanks. The revision check and the `SetInsideFilter` test do what we asked: with the revision check removed, the test fails at "an edit whose filter set the text sends no event". The debt sentence and the pinned KytyPS5 link look good too. One case is still left over. With a filter set, `CommitEdit` returns early, so `session.text` already holds the unfiltered edit while the title's buffers still hold the old text. When the commit is dropped because `sceImeSetText` ran, that doesn't matter, since `SetText` replaced the text. When it's dropped because only `sceImeSetCaret` ran, the unfiltered edit stays in `session.text`: it is never synced and sends no event, and it comes back with the next edit. I checked this with your test file plus one extra check: a pass-through filter that calls `sceImeSetCaret` (index 0) on its first call, starting from `ab`, then typing `c` and `d`: ``` after 'c': events=0 buffer="ab" after 'd': events=1 buffer="dabc" (the dropped 'c' is back; the event reports a 1-unit insert) ``` Dropping the commit should also drop the edit, as in KytyPS5, where the edit only lands at commit. This passes your whole test file and gives `dab` for the case above: ```cpp if (g_session && g_session->id == sessionId) { if (g_session->revision == sessionRevision) { CommitFilteredEdit(*g_session, accepted ? &filtered : nullptr, filterOldText); } else if (g_session->text == filterText) { g_session->text = filterOldText; NormalizeCaret(*g_session); } } ``` Could you add that, plus a test like the one above (a `sceImeSetCaret` inside the filter, then a second edit, then check the buffer)? In the debt entry, "the edit sends no event" could then read "the edit is discarded and sends no event".
primesoul-web commented 2026-10-20 09:33:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-20T09:33:26Z.


Thank you for the probe - the leftover case reproduced exactly as described (the dropped 'c' coming back as dabc), and it is fixed the way your patch does it, in 4c849bcad.

When the revision changed while the filter ran and the session's text still equals the text the filter saw - the caret-only case, where nothing replaced the edit - sceImeUpdate restores the pre-edit text and normalizes the caret instead of leaving the unfiltered edit in the session; a sceImeSetText still wins untouched, since it changed the text and the restore does not apply. GuestImeOpen now walks your scenario: a pass-through filter calls sceImeSetCaret(0) on its first call, the typed c is discarded and sends no event with the buffer staying ab, and the d typed after it builds on the old text - one UpdateText, buffer dab, a 1-unit insert at index 0. The whole test file passes on 4c849bcad and aborts on the previous head at exactly the new check, and the debt entry now reads "the edit is discarded and sends no event".

The branch carries main 3fd1cc393 (merge a0356d0cd) with the fix on top; GuestImeParameters and GuestImeKeyboard pass unchanged, check_conventions.py passes with the two known debt-length warnings, and git merge-tree against current main is clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287940621 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8009#issuecomment-6287940621). Originally posted by [primesoul-web](https://github.com/primesoul-web) on 2026-10-20T09:33:26Z. --- Thank you for the probe - the leftover case reproduced exactly as described (the dropped 'c' coming back as `dabc`), and it is fixed the way your patch does it, in 4c849bcad. When the revision changed while the filter ran and the session's text still equals the text the filter saw - the caret-only case, where nothing replaced the edit - `sceImeUpdate` restores the pre-edit text and normalizes the caret instead of leaving the unfiltered edit in the session; a `sceImeSetText` still wins untouched, since it changed the text and the restore does not apply. `GuestImeOpen` now walks your scenario: a pass-through filter calls `sceImeSetCaret(0)` on its first call, the typed `c` is discarded and sends no event with the buffer staying `ab`, and the `d` typed after it builds on the old text - one UpdateText, buffer `dab`, a 1-unit insert at index 0. The whole test file passes on 4c849bcad and aborts on the previous head at exactly the new check, and the debt entry now reads "the edit is discarded and sends no event". The branch carries main 3fd1cc393 (merge a0356d0cd) with the fix on top; `GuestImeParameters` and `GuestImeKeyboard` pass unchanged, `check_conventions.py` passes with the two known debt-length warnings, and `git merge-tree` against current `main` is clean.
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!8009
No description provided.