From ad7d76de4077ffde66f9c0966ac87ff10800f9e8 Mon Sep 17 00:00:00 2001
From: Matt Mullins <mmullins@mmlx.us>
Date: Sat, 17 May 2014 17:13:10 -0700
Subject: [PATCH] Initial commit.

---
 fuckit.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 fuckit.c

diff --git a/fuckit.c b/fuckit.c
new file mode 100644
index 0000000..b6e6a0b
--- /dev/null
+++ b/fuckit.c
@@ -0,0 +1,29 @@
+#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);
+}
-- 
2.11.0