libretro: don't treat optional environment calls as fatal - #2980
Open
wescopeland wants to merge 1 commit into
Open
libretro: don't treat optional environment calls as fatal#2980wescopeland wants to merge 1 commit into
wescopeland wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I am a RetroAchievements administrator, and I am interested in seeing if achievement development for TIC-80 is viable.
Currently, the TIC-80 libretro core does not load in minimal frontends. This is a major blocking issue, as this is currently blocking the use of the RetroAchievements toolkit (RALibretro), which needs the core to load and to expose memory so that one can make achievements for TIC-80 carts.
RetroArch hides both problems below, because it implements the optional calls that the core assumes are always available.
What is wrong
1. An optional environment call is fatal.
retro_load_game()returnsfalsewhen the frontend does not implementRETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK. That call is optional. A frontend returnsfalseto say it does not implement it, and the core must continue. The check is also abovetic80_create(), soretro_get_memory_data()then gives no memory. This looks like a memory problem, but it is actually a load problem.2. The core frees itself inside
retro_run().When a cart calls
exit(), the core callsretro_deinit(). This frees the buffer that the frontend received earlier fromretro_get_memory_data(). Frontends keep that pointer and keep reading through it. This is a use-after-free. The frontend now reads memory that has been returned to the allocator and may already hold something else. It does not crash cleanly, which is what makes it hard to notice.RETRO_ENVIRONMENT_SHUTDOWNis only a request. A frontend that does not implement it keeps callingretro_run(), so this block runs again on every frame.The fix
This PR makes two remediations:
retro_unload_game()andretro_deinit(), where the libretro API puts it.Frontends that implement both calls see no change in behavior.
Testing
These changes were tested with a minimal libretro host that returns
falsefor every environment call exceptSET_PIXEL_FORMAT, and with a build that accepts them.I also tested this with ~20 carts and saw no regressions.
2999ms is 180 frames x 16666µs, so the fallback clock is confirmed to be running at the correct rate.
Before

After
