Skip to content

Keyboard: drain the Wayland connection before raising the panel - #1608

Open
tiper wants to merge 1 commit into
plxnative:mainfrom
tiper:keyboard-first-show
Open

tiper wants to merge 1 commit into
plxnative:mainfrom
tiper:keyboard-first-show

Conversation

@tiper

@tiper tiper commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

On webOS 4.10 the app can crash the first time it raises the TV keyboard (opening Search). It's rare and intermittent:

keyboard: start support=1 focus=1
*** SIGNAL 11 (SIGSEGV) addr=0x20747261 pc=0x96cf4878 lr=0x96eab3db
at: 96cf1000-96cf8000 r-xp 00000000 ... /usr/lib/libwayland-client.so.0.3.0
at: 96e39000-96ec3000 r-xp 00000000 ... /usr/lib/libSDL2-2.0.so.0.4.1

Cause

It's in LG's SDL. I disassembled libSDL2 and libwayland-client from the matching firmware (05.40.97, 4.10.2-29). On the first raise, WebOSShowScreenKeyboard mallocs its keyboard record without zeroing it and asks the compositor for its globals. It then does a single wl_display_dispatch instead of a round trip. The text_model_factory pointer is only filled in by the registry reply. If that reply isn't in the one batch the dispatch reads (for example, because other events were already queued), SDL uses leftover heap as a proxy. Here r0 is "art ", from our log line that had just been freed, and wl_proxy_marshal_constructor faults on it (called at 0x723d8, which matches lr).

Fix

WebosShell::show_keyboard now calls SDL_PumpEvents twice before SDL_StartTextInput. That drains both the queue and the socket, so SDL's own dispatch reads the compositor's reply. The pumped events stay queued for the next SDL_PollEvent. The workaround is limited to the webOS platform. plx_shell_sdl only gains a stock event::pump(), and desktop and Tizen don't change. SDL_PumpEvents is exported on all 14 firmware inventories. The trap is documented in docs/search.md.

Testing

  • New test the_webos_shell_drains_the_connection_before_raising_the_keyboard: it fails without the pumps and passes with them.
  • plx_shell_sdl 49/0, plx_platform_webos 70/0, make check-nodef and the ARM build are clean.
  • I couldn't verify it on a TV: I don't have a 4.10 set and the crash is intermittent. It narrows the window, but it can't fully close it from outside SDL.

On webOS 4.10 (LG's SDL .so.0.4.1, firmware 4.10.2-29) the first
WebOSShowScreenKeyboard of a process mallocs its keyboard record without
zeroing it, requests a new wl_registry and dispatches the display once
instead of making a round trip. Only the registry listener fills the
record's text_model_factory and wl_seat fields. When that one dispatch
does not read the compositor's reply (that libwayland only dispatches
what is already queued when the queue is not empty, and otherwise reads
one batch), SDL uses leftover heap as a proxy and the app dies with
SIGSEGV in wl_proxy_marshal_constructor. On the crash seen in the field,
r0 held bytes 12..16 of the event-log line freed just before the call.

The webOS shell now raises the keyboard itself: two SDL_PumpEvents, then
SDL_StartTextInput. The first pump empties the queue and the second
reads what waits on the socket, so the raise's own dispatch sends the
registry request with nothing in the way and reads the reply. The SDL
shell gains event::pump for it; desktop and Tizen are unchanged.
SDL_PumpEvents is exported by all 14 firmware inventories.

Signed-off-by: Tiago Pereira <1698241+tiper@users.noreply.github.com>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant