Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <signal.h>
- #include <ucontext.h>
- #ifdef REG_EIP
- #define REG_PC REG_EIP
- #else
- #define REG_PC REG_RIP
- #endif
- void sigHandler(int signum, siginfo_t* siginfo, void* context_)
- {
- ucontext_t* context=static_cast<ucontext_t*>(context_);
- auto& pc=context->uc_mcontext.gregs[REG_PC];
- pc+=2; // skip the instruction leading to trap ("idiv reg" is 2 bytes long)
- }
- int main()
- {
- struct sigaction act={0};
- act.sa_sigaction=sigHandler;
- act.sa_flags=SA_SIGINFO;
- sigaction(SIGFPE, &act, NULL);
- std::cerr << "Dividing by zero...\n";
- int zero=0;
- __asm__ __volatile__("idiv %0"::"r"(zero));
- std::cerr << "Still alive\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement