I'm going JIT code generation, and I want to insert invalid opcodes into the stream in order to perform some meta-debugging. Everything is fine and good until it hits the instruction, at which point the thing goes into an infinite loop of illegal instruction to signal handler and back.
Is there any way I can set the thing to simply skip the bad instruction?
It's very hacky and UNPORTABLE but:
void sighandler (int signo, siginfo_t si, void *data) {
ucontext_t *uc = (ucontext_t *)data;
int instruction_length = /* the length of the "instruction" to skip */
uc->uc_mcontext.gregs[REG_RIP] += instruction_length;
}
install the sighandler
like that:
struct sigaction sa, osa;
sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = sighandler;
sigaction(SIGILL, &sa, &osa);
That could work if you know how far to skip (and it's a Intel proc) :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With