在SIGILL处理程序中,如何跳过违规指令?

Ale*_*lex 4 linux jit code-generation signals

我要进行JIT代码生成,并且我想在流中插入无效的操作码以执行一些元调试.一切都很好,直到它达到指令,此时东西进入无限循环的非法指令信号处理程序和返回.

有什么方法可以设置简单地跳过错误的指令吗?

Joh*_*iss 10

这非常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;
}
Run Code Online (Sandbox Code Playgroud)

安装sighandler如下:

struct sigaction sa, osa;
sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = sighandler;
sigaction(SIGILL, &sa, &osa);
Run Code Online (Sandbox Code Playgroud)

如果你知道跳过多远(这是英特尔的proc),这可能会有效:-)

  • 它会工作,但我建议您发出JMP指令以避免JIT中的元数据,因为您的元数据有时可能是有效的(但是顽皮的)机器代码,并且因为捕获SGILL可能会大大减慢JIT的执行速度 - 编码... (2认同)