我要进行JIT代码生成,并且我想在流中插入无效的操作码以执行一些元调试.一切都很好,直到它达到指令,此时东西进入无限循环的非法指令信号处理程序和返回.
有什么方法可以设置简单地跳过错误的指令吗?
解决方法
这非常hacky和不可用但是:
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; }
像那样安装sighandler:
struct sigaction sa,osa; sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; sa.sa_sigaction = sighandler; sigaction(SIGILL,&sa,&osa);
如果你知道跳过多远(这是英特尔的proc),这可能会有效:-)