From eb2d8890de7e8382ef23568dbe43e897c9fda7fe Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Thu, 2 May 2019 19:01:22 +0100 Subject: [PATCH] Additional provenance preservation --- src/mem/alloc.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 84c5460..c5732ce 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -363,7 +363,7 @@ namespace snmalloc Metaslab& meta = super->get_meta(slab); sizeclass_t sc = meta.sizeclass; - size_t slab_end = static_cast(address_cast(slab) + SLAB_SIZE); + void* slab_end = pointer_offset(slab, SLAB_SIZE); return external_pointer(p, sc, slab_end); } @@ -372,8 +372,7 @@ namespace snmalloc Mediumslab* slab = Mediumslab::get(p); sizeclass_t sc = slab->get_sizeclass(); - size_t slab_end = - static_cast(address_cast(slab) + SUPERSLAB_SIZE); + void* slab_end = pointer_offset(slab, SUPERSLAB_SIZE); return external_pointer(p, sc, slab_end); } @@ -755,16 +754,23 @@ namespace snmalloc template static uintptr_t - external_pointer(void* p, sizeclass_t sizeclass, size_t end_point) + external_pointer(void* p, sizeclass_t sizeclass, void* end_point) { size_t rsize = sizeclass_to_size(sizeclass); - size_t end_point_correction = location == End ? - (end_point - 1) : - (location == OnePastEnd ? end_point : (end_point - rsize)); - size_t offset_from_end = - (end_point - 1) - static_cast(address_cast(p)); - size_t end_to_end = round_by_sizeclass(rsize, offset_from_end); - return end_point_correction - end_to_end; + + void* end_point_correction = location == End ? + (static_cast(end_point) - 1) : + (location == OnePastEnd ? end_point : + (static_cast(end_point) - rsize)); + + ptrdiff_t offset_from_end = + (static_cast(end_point) - 1) - static_cast(p); + + size_t end_to_end = + round_by_sizeclass(rsize, static_cast(offset_from_end)); + + return address_cast( + static_cast(end_point_correction) - end_to_end); } void init_message_queue()