From 4afe06a0e9009923b5890e48443506348afb2657 Mon Sep 17 00:00:00 2001 From: Chris Jefferson Date: Tue, 21 May 2019 23:45:37 +0100 Subject: [PATCH] Revert addition of padding at the start of BagHeader There was a bug in this code -- when we shrink a bag with ResizeBag, the new space may only be a single word, so the type and flags members of BagHeader must be in the first word. --- src/gasman.c | 8 ++------ src/gasman.h | 7 +------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/gasman.c b/src/gasman.c index 2981279b98..f2d27128b5 100644 --- a/src/gasman.c +++ b/src/gasman.c @@ -472,9 +472,7 @@ static void CANARY_ALLOW_ACCESS_BAG(Bag bag) BagHeader * header = BAG_HEADER(bag); VALGRIND_MAKE_MEM_DEFINED( - (char *)header + sizeof(header->memory_canary_padding1), - sizeof(*header) - sizeof(header->memory_canary_padding1) - - sizeof(header->memory_canary_padding2)); + header, sizeof(*header) - sizeof(header->memory_canary_padding)); } // Reverse CANARY_ALL_ACCESS_BAG, making the masterpointer, bag contents and @@ -488,9 +486,7 @@ static void CANARY_FORBID_ACCESS_BAG(Bag bag) BagHeader * header = BAG_HEADER(bag); VALGRIND_MAKE_MEM_NOACCESS( - (char *)header + sizeof(header->memory_canary_padding1), - sizeof(*header) - sizeof(header->memory_canary_padding1) - - sizeof(header->memory_canary_padding2)); + header, sizeof(*header) - sizeof(header->memory_canary_padding)); } // Mark all bags as accessible diff --git a/src/gasman.h b/src/gasman.h index a60ce4d4ac..6e44eb0de5 100644 --- a/src/gasman.h +++ b/src/gasman.h @@ -77,11 +77,6 @@ typedef UInt * * Bag; ** */ typedef struct { -#if defined(GAP_MEMORY_CANARY) - // The following variable is marked as not readable or writable - // in valgrind, to check for code reading before the start of the header. - uint64_t memory_canary_padding1[8]; -#endif uint8_t type : 8; uint8_t flags : 8; // the following unnamed field ensures that on 32 bit systems, @@ -94,7 +89,7 @@ typedef struct { #if defined(GAP_MEMORY_CANARY) // The following variable is marked as not readable or writable // in valgrind, to check for code reading before the start of a Bag. - uint64_t memory_canary_padding2[8]; + uint64_t memory_canary_padding[8]; #endif } BagHeader;