hrydgard/ppsspp

Function alignment nuances

Nemoumbra opened this issue · 1 comments

Game or games this happens in

Not game-specific

What area of the game / PPSSPP

Our current API for managing the function symbols is inconsistent. Until recently, the methods that work with the function start addresses didn't validate the alignment, but 5260be6 added 3 checks to ForgetFunctions, RegisterFunction and ScanForFunctions (and also something in sceKernelModule.cpp, but I didn't pay much attention to these use-cases). The commit 7a93d0d reverted the check for ForgetFunctions.

  1. The websocket debugger methods hle.func.add, hle.func.remove, hle.func.removeRange, hle.func.rename, hle.func.scan (including the helper RemoveFuncSymbolsInRange) do not validate the alignment and just pass the address to the underlying methods.
  2. The SymbolMap methods don't care either.
  3. The MIPSAnalyst methods do care now, except for MIPSAnalyst::ForgetFunctions.

What should happen

I think we should find some common ground here: check what SymbolMap funcs do when the starting address is misaligned, document that behavior, maybe add asserts there if this behavior is undesirable; same for the rest of the API.

Logs

No response

Platform

Windows

Mobile device model or graphics card (GPU)

AMD Radeon(TM) Graphics

PPSSPP version affected

Self-built version (one of the lastest)

Last working version

No response

Graphics backend (3D API)

Vulkan

Checklist

  • Test in the latest git build in case it's already fixed.
  • Search for other reports of the same issue.
  • Try resetting settings or older versions and include if the issue is related.
  • Try without any cheats and without loading any save states.
  • Include logs or screenshots of issue.

There's basically no situation where it make sense that the address of a function is misaligned - it would be impossible to execute it, that's a hardware limitation.

However, of course, it's possible to execute a range scan between two unaligned addresses, as long as your actual check in between are aligned - but it will be the same as just aligning the addresses to begin with.

So I think it makes the most sense to put the asserts back, and either forcibly align the addresses or refuse and turn an error in the websocket debugger methods.

Or actually, maybe it's better to just make sure the functions work correctly with misaligned addresses..

There's a lot of funky math done in the websocket functions like

MIPSAnalyst::ForgetFunctions(funcBegin, funcBegin + funcSize - 1);

Really, that should probably subtract 4. Or not subtract at all, if it's an exclusive range....