--- /dev/null
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <ucontext.h>
+
+static void handle_sigsegv(int signal, siginfo_t *info, void *_context)
+{
+ (void)(signal); // it's unused, stfu gcc
+
+ struct ucontext *context = (struct ucontext *) _context;
+ fprintf(stderr, "Caught SIGSEGV for address %p\n", info->si_addr);
+ fprintf(stderr, "Code address: %p\n", (void*)context->uc_mcontext.gregs[REG_RIP]);
+
+ context->uc_mcontext.gregs[REG_RIP]++;
+}
+
+__attribute__((constructor))
+static void setup_signals()
+{
+ fprintf(stderr, "Set up signals\n");
+ sigset_t mask;
+ sigemptyset(&mask);
+ struct sigaction action = {
+ .sa_sigaction = handle_sigsegv,
+ .sa_mask = mask,
+ .sa_flags = SA_SIGINFO,
+ };
+ sigaction(SIGSEGV, &action, NULL);
+}