aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-10-13 17:19:01 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-10-13 17:19:01 +0200
commit1d50a146ea0c7a517564bf3ec2a79cd2bb3c8c79 (patch)
tree6be533ee2c82eba3de7619278e1e981473848e46
parent19e1ff660db8a6653d67884d10bc830babc1560d (diff)
parentcc7edda1871c89c7476c67eacf3e6aee56262e2d (diff)
downloadallocbench-1d50a146ea0c7a517564bf3ec2a79cd2bb3c8c79.tar.gz
allocbench-1d50a146ea0c7a517564bf3ec2a79cd2bb3c8c79.zip
Merge branch 'catch_abort'
-rw-r--r--src/Makefile6
-rw-r--r--src/benchmark.py3
-rw-r--r--src/exec.c1
-rw-r--r--src/sig_handlers.c37
4 files changed, 44 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index 2d94a9f..79d9f8c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,7 +13,7 @@ LDFLAGS ?= -pthread -static-libgcc
MEMSIZE_KB=$(shell free -t | tail -1 | tr -s ' ' | cut -d ' ' -f 2)
MEMSIZE=$(shell echo $(MEMSIZE_KB)"* 1024" | bc)
-TOOLS = print_status_on_exit.so exec
+TOOLS = print_status_on_exit.so exec sig_handlers.so
ALLOCS = chattymalloc.so bumpptr_alloc.so speedymalloc.so
TARGETS = $(addprefix $(OBJDIR)/allocators/,$(ALLOCS)) $(addprefix $(OBJDIR)/,$(TOOLS))
@@ -37,6 +37,10 @@ $(OBJDIR)/print_status_on_exit.so: print_status_on_exit.c Makefile
@if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
$(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $<
+$(OBJDIR)/sig_handlers.so: sig_handlers.c Makefile
+ @if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
+ $(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $<
+
$(OBJDIR)/exec: exec.c Makefile
@if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
diff --git a/src/benchmark.py b/src/benchmark.py
index 798cbd6..4dfaa78 100644
--- a/src/benchmark.py
+++ b/src/benchmark.py
@@ -345,6 +345,7 @@ class Benchmark:
env = dict(os.environ)
env["LD_PRELOAD"] = env.get("LD_PRELOAD", "")
env["LD_PRELOAD"] += " " + f"{src.globalvars.builddir}/print_status_on_exit.so"
+ env["LD_PRELOAD"] += " " + f"{src.globalvars.builddir}/sig_handlers.so"
env["LD_PRELOAD"] += " " + alloc["LD_PRELOAD"]
if "LD_LIBRARY_PATH" in alloc:
@@ -406,7 +407,7 @@ class Benchmark:
result = {}
- if res.returncode != 0 or "ERROR: ld.so" in res.stderr or "Segmentation fault" in res.stderr:
+ if res.returncode != 0 or "ERROR: ld.so" in res.stderr:
print()
print_debug("Stdout:\n" + res.stdout)
print_debug("Stderr:\n" + res.stderr)
diff --git a/src/exec.c b/src/exec.c
index 4397992..6985fb2 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -26,7 +26,6 @@ int main(int argc, char* argv[]) {
}
}
-
// Run cmd.
execvp(argv[i], &argv[i]);
diff --git a/src/sig_handlers.c b/src/sig_handlers.c
new file mode 100644
index 0000000..3274482
--- /dev/null
+++ b/src/sig_handlers.c
@@ -0,0 +1,37 @@
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void abnormal_termination_handler(int signo) {
+ psignal(signo, "");
+ exit(signo);
+}
+
+static void __attribute__((constructor)) register_handlers(void)
+{
+ struct sigaction sa, old_sa;
+ sa.sa_handler = abnormal_termination_handler;
+ sigemptyset(&sa.sa_mask);
+
+ sigaction(SIGABRT, NULL, &old_sa);
+ if (old_sa.sa_handler == SIG_DFL) {
+ if (sigaction(SIGABRT, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, "SIGABRT handler already set");
+ }
+
+ sigaction(SIGSEGV, NULL, &old_sa);
+ if (old_sa.sa_handler == SIG_DFL) {
+ if (sigaction(SIGSEGV, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, "SIGSEGV handler already set");
+ }
+}
+