From 830a7d338d0a9a0617673aae2ce902a173b3714b Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 5 Dec 2018 09:23:05 -0500 Subject: [PATCH] make class_region_size configurable --- Android.bp | 3 ++- Makefile | 6 ++++-- README.md | 2 ++ h_malloc.c | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Android.bp b/Android.bp index 81b0546..2f5c631 100644 --- a/Android.bp +++ b/Android.bp @@ -23,8 +23,9 @@ common_cflags = [ "-DGUARD_SIZE_DIVISOR=2", "-DREGION_QUARANTINE_RANDOM_SIZE=128", "-DREGION_QUARANTINE_QUEUE_SIZE=1024", - "-DREGION_QUARANTINE_SKIP_THRESHOLD=33554432", + "-DREGION_QUARANTINE_SKIP_THRESHOLD=33554432", // 32MiB "-DFREE_SLABS_QUARANTINE_RANDOM_SIZE=32", + "-DCONFIG_CLASS_REGION_SIZE=1073741824", // 1GiB ] cc_defaults { diff --git a/Makefile b/Makefile index 99a24d1..8ebbf11 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,9 @@ CONFIG_GUARD_SLABS_INTERVAL := 1 CONFIG_GUARD_SIZE_DIVISOR := 2 CONFIG_REGION_QUARANTINE_RANDOM_SIZE := 128 CONFIG_REGION_QUARANTINE_QUEUE_SIZE := 1024 -CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD := 33554432 +CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD := 33554432 # 32MiB CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE := 32 +CONFIG_CLASS_REGION_SIZE := 137438953472 # 128GiB define safe_flag $(shell $(CC) -E $1 - /dev/null 2>&1 && echo $1) @@ -77,7 +78,8 @@ CPPFLAGS += \ -DREGION_QUARANTINE_RANDOM_SIZE=$(CONFIG_REGION_QUARANTINE_RANDOM_SIZE) \ -DREGION_QUARANTINE_QUEUE_SIZE=$(CONFIG_REGION_QUARANTINE_QUEUE_SIZE) \ -DREGION_QUARANTINE_SKIP_THRESHOLD=$(CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD) \ - -DFREE_SLABS_QUARANTINE_RANDOM_SIZE=$(CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE) + -DFREE_SLABS_QUARANTINE_RANDOM_SIZE=$(CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE) \ + -DCONFIG_CLASS_REGION_SIZE=$(CONFIG_CLASS_REGION_SIZE) libhardened_malloc.so: $(OBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ diff --git a/README.md b/README.md index fd36d9a..7a38953 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,8 @@ for the chosen values are not written yet, so use them at your own peril: the size threshold where large allocations will not be quarantined * `CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE`: `32` (default) to control the number of slots in the random array used to randomize free slab reuse +* `CONFIG_CLASS_REGION_SIZE`: `34359738368` (default) to control the size of + the size class regions There will be more control over enabled features in the future along with control over fairly arbitrarily chosen values like the size of empty slab diff --git a/h_malloc.c b/h_malloc.c index d065c71..7d659af 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -210,7 +210,7 @@ struct __attribute__((aligned(CACHELINE_SIZE))) size_class { size_t metadata_count_unguarded; }; -#define CLASS_REGION_SIZE (128ULL * 1024 * 1024 * 1024) +#define CLASS_REGION_SIZE (size_t)CONFIG_CLASS_REGION_SIZE #define REAL_CLASS_REGION_SIZE (CLASS_REGION_SIZE * 2) static const size_t slab_region_size = REAL_CLASS_REGION_SIZE * N_SIZE_CLASSES; static_assert(PAGE_SIZE == 4096, "bitmap handling will need adjustment for other page sizes");