led_driver_free() leaves no driver behind, so nothing can reach a
freed one before the next led_driver_init(). The init log names the
driver actually chosen, by its ident, and stays quiet for the null
driver, an unknown name included. A compile-time check keeps MAX_LEDS
within the output store's slots.
samples/frontend/led_driver checks that a freed driver is not
called and what the init logs.
Pack a 16-bit rumble strength or boolean LED state with its pending bit in one 32-bit mailbox. Taking a slot atomically consumes its value, so a concurrent post cannot replace a taken value and be delivered twice.
Keep repeated-value refreshes and zero-strength stops. Normalize LED states at the boolean libretro boundary. Add a forced take/post race and shared-slot producer coverage.
A core calls set_rumble_state and set_led_state from inside
retro_run(), and both went straight to the driver: an ioctl or a
transfer for a motor; for an LED a sysfs open, write and close, an X11
round trip, or an injected key press. As many times a frame as the
core called, on the core's own stack. A core that reports its rumble
level every frame paid for a device write every frame, and one that
sets it several times a frame paid for each.
The calls now store what was asked for (input/input_output_store.h),
and the frame loop writes it once the core has run: one driver call
for each motor or LED that was set, with the frame's last value.
- An output set to the value it already had is still written once
that frame. Drivers whose effects run out rely on a core repeating
itself, so the store remembers that a slot was set, not only what
to.
- The write happens after the cheats, which can rumble too, and so
after run-ahead and netplay replays: several runs of the core in
one iterate are one write.
- What a core sets while loading or unloading is written when that
call returns. No frame follows an unload to write an LED it turned
off.
- CMD_EVENT_RUMBLE_STOP writes its zeros at once, as before, and
drops whatever was waiting so it cannot restart a motor.
- Posting is safe from any thread, since some cores call from one of
their own; the driver is now only ever called from the main thread.
What a core can notice:
- A motor or LED changes up to a frame later than it did: at the end
of the frame in which the core asked, not in the middle of it.
- set_rumble_state returns what the driver answered the last time
that motor was written, and before the first write whether a driver
with motors is loaded, where it used to return the answer to this
very call. The port and effect are now checked: a port past
MAX_USERS indexed the joypad-index setting out of bounds.
This is the first part of the output scheduler in the input plan
(WP-09). The write is still on the main thread; moving it to the
device's own thread comes with per-device sessions.
Tests:
- samples/input/output_store builds the store on a host: a post
writes nothing, many posts in a frame are one write with the last
value, a repeat is still written, a drop forgets, and with three
threads posting against a taker every output ends on its last
value. Run under ASan + UBSan and under TSan.
- samples/runloop/frontend_overhead gains a lane in which the
harness core makes six rumble calls a frame and the joypad driver's
set_rumble is counted. Before: 1800 calls, 1800 driver writes inside
retro_run(). After: none inside, one per motor after it, each with
the last strength; a stop writes zeros and leaves nothing behind.
The frame costs 2.9 us in the harness before and after. Compiled
through the Android unity build; the menu harnesses pass.
A pack names the image that shows an LED with overlayN_descM_led = K
(1-based, as ledN_map counts): under led_driver = "overlay" that image
shows while the core has LED K lit, and a pack that names any LED image
is not mapped at all. For a pack that names none, ledN_map still picks
slots of the page, but only the image of a "nul" button answers to it:
a desc that does something when pressed is never an LED, so a config
made for an LED overlay leaves a gamepad pack's controls where they are.
The LED driver reports the core's LEDs (input_overlay_set_led) and
input/input_overlay_leds.c decides what they hide. The per-slot
visibility array, its enum and the parameter threaded through the
alpha and poll paths are gone.
overlay_visibility_bounds_test now builds input_overlay_leds.c with
the LED driver and pins the map/named/off cases and the page bound;
overlay_led_hidden_test runs a mapped pack and a named pack under Xvfb
with Up held.
keyboard_led() runs on the main thread: led_driver_init from
retroarch.c and led_driver_set_led wired into the core LED interface in
runloop.c. Under video_threaded the main window and its message pump
belong to the video thread, so the main thread's synchronous key table
is never advanced and GetKeyState reports every lock as clear.
That made keyboard_init() record all three locks as off, and every
subsequent set saw status 0 and fired keybd_event to toggle a lock that
was already lit. keyboard_free() then "restored" all of them to off.
Take the lock state from the mask win32_update_keyboard_mods()
publishes from the owning thread, which is correct in both video
threading configurations.
The mask advances when the window procedure sees a key event, so a lock
changed while RetroArch is not focused is still not observed until the
next key reaches the window. That is a smaller window than before and
matches what the rest of the Win32 input path already assumes.
keyboard_led() tested the whole GetKeyState return for truth. A lock key
that is physically held reads as 0xFF80 or 0xFF81, which is truthy even
when the lock itself is off, so the initial state captured at
keyboard_init() could be recorded as lit for a key whose LED was dark -
and then "restored" to on at deinit. The same conflation misfires on
every subsequent set, since state and status are compared as booleans.
Mask to bit 0, which is the documented toggle bit.
strlcpy() begins with strlen() of its source. It lives in another
translation unit, so with no LTO that scan happens at runtime even when
the source is a literal whose length the compiler already measured, and
the call itself cannot be folded away either.
strlcpy_lit() passes the length over as sizeof(). When the destination
size is also a constant -- sizeof(buf), the usual case -- nothing is
left but the stores memcpy() compiles to:
strlcpy "core_options" sizeof(buf) 7.01 ns
strlcpy_lit "core_options" sizeof(buf) 0.42 ns
strlcpy 41-char literal sizeof(buf) 7.74 ns
strlcpy_lit 41-char literal sizeof(buf) 0.71 ns
strlcpy "core_options" runtime len 7.11 ns
strlcpy_lit "core_options" runtime len 0.70 ns
The destination bound is kept. When the literal does not fit it defers
to strlcpy(), so the copy truncates as before rather than overrunning;
a form that took only the literal would have turned every one of these
sites into an overflow waiting for a small buffer. The literal is
concatenated with "" so a non-literal source is a compile error rather
than a sizeof() that silently measures a pointer.
818 sites across 104 files were converted by parsing arguments rather
than by pattern-matching text: only a three-argument call whose second
argument is a bare string literal is rewritten, so a macro that happens
to expand to a literal is left alone. Line endings are preserved, so
the CRLF files carry only their own changed lines.
test/compat/test_strl.c compares the two against each other over every
destination size from 0 past the literal's length, for literals that
are empty, single-character, path-shaped, adjacently concatenated and
escape-bearing, checking the return, the terminator and the whole
buffer so an overrun past the terminator is caught. ASan+UBSan+LSan and
TSan both 4/4. The full menu_displaylist_build_list walk over every
displaylist type is byte-identical to before the change
(md5 a2a081bcac09cdc8d72d67efd14ac40e).
New driver for controlling system LEDs offered via /sys/class/leds.
Currently it handles led0, led1 etc. type of entries, which are
present on e.g. Raspberry Pi's.
Also fix white spaces in led drivers, make led drivers use standard driver format.
Begin work on translation driver.
Add salamander files to gitignore.