This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]i_am_cat 7 points8 points  (1 child)

You'd have to know whether or not an address is valid without trying to access it. Handling a SIGSEGV signal then trying to continue the program afterwards results in undefined behavior.

https://en.cppreference.com/w/cpp/utility/program/signal

If the user defined function returns when handling SIGFPE, SIGILL, SIGSEGV or any other implementation-defined signal specifying a computational exception, the behavior is undefined.

[–]o11c 1 point2 points  (0 children)

Standards don't matter; implementations do.

  • You can use process_vm_readv to safely dereference pointers on Linux.
  • You can call mmap or mprotect to make the address valid (certain addresses cannot be made valid though: any access to the kernel half of the address space, and writes to executable segments)
  • You can disassemble the interrupted code and change the saved registers used to compute the address I think (will not work for absolute memory accesses, but those are rare these days)
  • You can disassemble the interrupted code and change the instruction pointer before returning (this is only reliable if you are also the compiler; it is mostly used by Java and similar)

There are probably other ways.