I want to use an exception/trap handler from assembly, but I don't know how to actually modify the context of the offending frame.
My code:
_TEXT segment para 'CODE'
MyHandler proc
call printout
ret
MyHandler endp
public SyntaxTest
SyntaxTest proc frame:MyHandler
.endprolog
ud2
.beginepilog
ret
SyntaxTest endp
_TEXT ends
Right now, when ud2 is executed, the code jumps to MyHandler, calls the printout function (implemented elsewhere), then resumes execution in the exact same spot, creating an infinite loop. How do I fix this?
MyHandler(function in FRAME :ehandler-address ) this is so called Language-specific handler . so it must have signature:if you want continue execution - you must return
ExceptionContinueExecutionand modifyContextRecord- theRip( sayRip += 2for skipud2). theprintoutprobably return 0, but you not fixRipas result theud2executed again. the absolute minimum, demo only codeof course in real code need analyze source of exeption, and select what need todo based on this. but not hardcode
rip += 2and continue.