The story starts with Qiling Framework. When I ran tests for Qiling on native Windows someday, the whole python process exited silently. After some in

Unicorn Devblog: setjmp/longjmp on Windows

submited by
Style Pass
2025-01-20 12:30:05

The story starts with Qiling Framework. When I ran tests for Qiling on native Windows someday, the whole python process exited silently. After some investigating and debugging, I’m sure that the crash happens in unicorn, not Qiling. Thus, I submitted an issue to Unicorn. However, recently we’d like to make Qiling run on Windows so I decided to solve the issue.

But that is quite confusing since the crashed context is in a hook callback which never calls uc_version. The stacktrace above is not so helpful so a minimum reproduction code is required, as @aquynh also suggested.

The good news is that this bug also exists in real mode when I implement it for Qiling Framework. The crash often happens when a hook callback is called multiple times but the exact time when crash happens differs. Thus, I write a snippet of reproduction code in C:

The exact crash point is inside RtlUnwindEx function which is part of setjmp implementation. However, this code only reproduces the bug with SEH enabled and Debug build. If it is built in Release mode or the SEH is disabled, no crash would happen. At this time, I guess that it’s highly likely related to some undefined behavior so I turn to docs.

Leave a Comment