Commit 9bfa19c
committed
retroarch: gate retroarch_fail longjmp on init-in-progress
flag
retroarch_fail unconditionally longjmps into
global->error_sjlj_context. The author's comment acknowledges
the constraint - 'we cannot longjmp unless we're in
retroarch_main_init()' - but the code longjmps regardless,
and the constraint is not enforced anywhere.
retroarch_fail's callers include drivers_init's per-driver
find_*_driver failure paths (find_audio_driver,
find_video_driver, find_input_driver, find_camera_driver, etc.
at retroarch.c:1668-1700) and the bluetooth/wifi
RARCH_*_CTL_INIT handlers reached from the same drivers_init
path. drivers_init runs not just from retroarch_main_init's
single CMD_EVENT_CORE_INIT (where the setjmp is live) but also
from command_event_reinit -> video_driver_reinit_context for
every CMD_EVENT_REINIT - fullscreen toggle, HDR mode change,
video driver swap, AV info change, etc.
When retroarch_fail fires from a reinit-time drivers_init, the
longjmp lands in error_sjlj_context, which points to stack
memory that was unwound when retroarch_main_init returned.
Behavior is undefined: typically a crash, sometimes silent
corruption.
This is a cold path - drivers don't usually vanish at runtime -
but the retroarch_fail calls in drivers_init exist precisely
because the code thinks they can fail, and the failure handling
assumes initialization-time semantics that no longer hold.
Add GLOB_FLG_INIT_IN_PROGRESS to global flags. Set it after the
setjmp succeeds in retroarch_main_init, clear it on every exit
(both success and the error: label). Gate retroarch_fail's
longjmp on the flag; if clear, log and return.
The non-longjmp return path means the caller (drivers_init)
sees the subsystem fail to init but isn't unwound. Driver init
code already NULL-checks its own driver pointers downstream of
find_*_driver calls (e.g. video_st->current_video gets NULL'd
on find_video_driver failure and downstream rendering checks
for it), so a 'driver missing' state is survivable - the user
ends up in a degraded but not-crashed state. Initialization-time
failures still propagate via the existing setjmp path.1 parent 0760c29 commit 9bfa19c
2 files changed
Lines changed: 39 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8081 | 8081 | | |
8082 | 8082 | | |
8083 | 8083 | | |
| 8084 | + | |
| 8085 | + | |
| 8086 | + | |
| 8087 | + | |
| 8088 | + | |
| 8089 | + | |
8084 | 8090 | | |
8085 | 8091 | | |
8086 | 8092 | | |
| |||
8425 | 8431 | | |
8426 | 8432 | | |
8427 | 8433 | | |
| 8434 | + | |
8428 | 8435 | | |
8429 | 8436 | | |
8430 | 8437 | | |
8431 | 8438 | | |
8432 | 8439 | | |
| 8440 | + | |
8433 | 8441 | | |
8434 | 8442 | | |
8435 | 8443 | | |
| |||
8840 | 8848 | | |
8841 | 8849 | | |
8842 | 8850 | | |
8843 | | - | |
8844 | | - | |
8845 | | - | |
8846 | 8851 | | |
8847 | 8852 | | |
8848 | | - | |
| 8853 | + | |
| 8854 | + | |
| 8855 | + | |
| 8856 | + | |
| 8857 | + | |
| 8858 | + | |
| 8859 | + | |
| 8860 | + | |
| 8861 | + | |
| 8862 | + | |
| 8863 | + | |
| 8864 | + | |
| 8865 | + | |
| 8866 | + | |
| 8867 | + | |
| 8868 | + | |
| 8869 | + | |
| 8870 | + | |
| 8871 | + | |
| 8872 | + | |
| 8873 | + | |
8849 | 8874 | | |
8850 | 8875 | | |
8851 | 8876 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
258 | 267 | | |
259 | 268 | | |
260 | 269 | | |
| |||
0 commit comments