add header for configuration

pull/50/head
Daniel Micay 2018-09-07 00:17:22 -04:00
parent 99d68238d2
commit d398384b90
3 changed files with 12 additions and 7 deletions

View File

@ -7,7 +7,7 @@ hardened_malloc.so: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@
chacha.o: chacha.c chacha.h
malloc.o: malloc.c malloc.h memory.h pages.h random.h util.h
malloc.o: malloc.c malloc.h config.h memory.h pages.h random.h util.h
memory.o: memory.c memory.h util.h
pages.o: pages.c pages.h memory.h util.h
random.o: random.c random.h chacha.h util.h

7
config.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef CONFIG_H
#define CONFIG_H
#define GUARD_SLABS true
#define WRITE_AFTER_FREE_CHECK true
#endif

View File

@ -11,6 +11,7 @@
#include "third_party/libdivide.h"
#include "config.h"
#include "malloc.h"
#include "memory.h"
#include "pages.h"
@ -19,9 +20,6 @@
static_assert(sizeof(void *) == 8, "64-bit only");
static const bool guard_slabs = true;
static const bool enable_write_after_free_check = true;
// either sizeof(uint64_t) or 0
static const size_t canary_size = sizeof(uint64_t);
@ -165,7 +163,7 @@ static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_si
return NULL;
}
c->metadata_count++;
if (guard_slabs) {
if (GUARD_SLABS) {
c->metadata_count++;
}
return metadata;
@ -245,13 +243,13 @@ static void *slot_pointer(size_t size, void *slab, size_t slot) {
}
static void write_after_free_check(char *p, size_t size) {
if (!enable_write_after_free_check) {
if (!WRITE_AFTER_FREE_CHECK) {
return;
}
for (size_t i = 0; i < size; i += sizeof(uint64_t)) {
if (*(uint64_t *)(p + i)) {
fatal_error("write after free");
fatal_error("detected write after free");
}
}
}