TASEmulators / TASEmulators/BizHawk

MelonDS on_bus_exec hook doesn't respect ARM/THUMB switching bit

Open
#4,649 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Core: melonDS re: APIHawk re: Lua API/scripting
Dominant language
C#
Stars
2.8k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

It should be possible to read a pointer to code from memory and use the address with lua's event.on_bux_exec. ARM processors such as the ARM9 in melonDS use the least-significant bit (in the address used for a jump) for handling switches between ARM mode and THUMB mode. Thus there are pointers to code in a game's memory that are not 2-byte aligned. Giving such a value to on_bus_exec will result in the hook never being triggered.

As a result:

local address = memory.read_u32_le(code_pointer_address)
event.on_bus_exec(function() print("exec") end, address)

may result in no output even when the game loads the value at code_pointer_address then does a branch to that code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Lua event.on_bux_exec entry point and trace how the supplied address is matched against ARM9 execution. Reproduce the shown memory.read_u32_le example with an address whose least-significant bit selects THUMB mode, then verify hooks fire for both THUMB and aligned ARM addresses.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.