-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicorn Engine Breaks GDB Memory Access Inside Callback #476
Comments
Unicorn callbacks execute on a different OS thread IIRC, which could be related if GDB cares about that. |
This appears to be the reason. Of course, now the issue is whether it's possible to have Unicorn issue callbacks on the same thread, and to find out why GDB is plenty happy to do almost everything except fetch memory.
|
Unicorn runs the CPU in a separate thread. Callbacks are issued synchronously from the CPU thread. You'd need to rewrite parts of Unicorn to move the CPU emulation to the main thread, which is technically possible but probably @aquynh's decision. Does the GDB memory read need to run synchronously with the callback? I could help you work around this in Python. |
Yes, it does unfortunately need to be synchronous. The intent is to emulate the current basic block, such that the next conditional jump (or series of conditional jumps) can be evaluated ahead of time, to provide better disassembly. This requires using Capstone to inspect the instruction to determine its type (jump vs. call vs. ret). While I can use
It appears that the page-mapping requests occur on the first thread, as I don't run into the same problems when using GDB's memory read operation. Using the emulator's memory state will also introduce lots of architectural problems, versus using GDB's memory state. |
this raises a very good question. yes, Unicorn does not need threading, which we inherited from Qemu, which has async threading for I/O, interrupts, etc. will be great if somebody can work on this to remove thread requirement in Unicorn. |
Removing the extra thread should also improve rapid stop/start performance. |
The fact that vCPUs run on their own threads is also troublesome for unit testing. cmocka wants to |
i put this into the TODO list: https://github.com/unicorn-engine/unicorn/wiki/TODO |
Will a single uc handle always only contain one CPU? Is CPU_FOREACH redundant now? If so, I have a patch planned out / in progress. |
@zachriggle my PR #481 (lunixbochs@f0af8f8) fixes ptrace in callbacks by moving CPU execution to the same thread as |
@zachriggle this is fixed in master by the no-thread merge right? |
Solved, thanks |
It is not possible to read inferior memory within GDB, inside a Unicorn callback.
Does Unicorn do anything that would explain breakage of GDB's functionality when inside of a callback?
I have a minimized PoC here. Just save it as
script.py
.You should see the following output, or something like it. It shows that the
read_memory
call fails while inside Unicorn. This was done with the most recentmaster
on Unicorn (86823f5).The text was updated successfully, but these errors were encountered: