summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--src/wrap.c21
2 files changed, 32 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 3f7db7f..867b86c 100644
--- a/Makefile
+++ b/Makefile
@@ -6,9 +6,10 @@ OBJDIR=obj
SRCDIR=src
INCDIR=include
TESTDIR=test
-CFLAGS=-I$(INCDIR) -Wall -Wextra -Wpedantic -g
+CFLAGS=-I$(INCDIR) -Wall -Wextra -Wpedantic -g -fPIC
OBJECTS=$(OBJDIR)/mapalloc.o
+WRAPOBJECTS=$(OBJECTS) $(OBJDIR)/wrap.o
TESTS=$(BINDIR)/overflow \
$(BINDIR)/underflow \
$(BINDIR)/zero \
@@ -16,7 +17,7 @@ TESTS=$(BINDIR)/overflow \
$(BINDIR)/use-after-free \
$(BINDIR)/double-free
-all: $(LIBDIR)/libmapalloc.a
+all: $(LIBDIR)/libmapalloc.a $(LIBDIR)/libwrapalloc.so
#$(LIBDIR)/libmapalloc.so
@@ -26,6 +27,10 @@ $(OBJDIR)/mapalloc.o: $(SRCDIR)/mapalloc.c $(INCDIR)/mapalloc.h
@mkdir -p $(@D)
$(CC) -c -o $@ $(CFLAGS) $(SRCDIR)/$(*F).c
+$(OBJDIR)/wrap.o: $(SRCDIR)/wrap.c $(INCDIR)/mapalloc.h
+ @mkdir -p $(@D)
+ $(CC) -c -o $@ $(CFLAGS) $(SRCDIR)/$(*F).c
+
$(LIBDIR)/libmapalloc.a: $(OBJECTS)
@mkdir -p $(@D)
$(AR) $(ARFLAGS) $@ $<
@@ -34,6 +39,10 @@ $(LIBDIR)/libmapalloc.so: $(OBJECTS)
@mkdir -p $(@D)
$(CC) -o $@ -shared $(OBJECTS)
+$(LIBDIR)/libwrapalloc.so: $(WRAPOBJECTS)
+ @mkdir -p $(@D)
+ $(CC) -o $@ -shared $(WRAPOBJECTS)
+
$(TESTS): $(LIBDIR)/libmapalloc.a
$(BINDIR)/overflow: $(TESTDIR)/overflow.c
$(BINDIR)/underflow: $(TESTDIR)/underflow.c
diff --git a/src/wrap.c b/src/wrap.c
new file mode 100644
index 0000000..524d6d2
--- /dev/null
+++ b/src/wrap.c
@@ -0,0 +1,21 @@
+#include "mapalloc.h"
+
+void *malloc(size_t n)
+{
+ return map_malloc(n);
+}
+
+void *calloc(size_t n, size_t e)
+{
+ return map_calloc(n, e);
+}
+
+void *realloc(void *p, size_t n)
+{
+ return map_realloc(p, n);
+}
+
+void free(void *p)
+{
+ map_free(p);
+}