在SIGILL处理程序中,如何跳过有问题的指令? [英] In a SIGILL handler, how can I skip the offending instruction?

查看:118
本文介绍了在SIGILL处理程序中,如何跳过有问题的指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要生成JIT代码,并且我想在流中插入无效的操作码以执行一些元调试.一切都很好,直到碰到指令为止,这时事情会进入非法指令的无限循环,以向处理程序发出信号并返回.

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;
}

像这样安装sighandler:

struct sigaction sa, osa;
sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = sighandler;
sigaction(SIGILL, &sa, &osa);

如果您知道要跳过多远(这是Intel proc),则可以起作用:-)

That could work if you know how far to skip (and it's a Intel proc) :-)

这篇关于在SIGILL处理程序中,如何跳过有问题的指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆