From 6837b48ce6e0593cb84683cbb65f94648a6341b7 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 23 Sep 2016 09:39:18 +0300 Subject: [PATCH] Fix page calculation in checksums While consistent use of rounding mode for computing GC_faulted entries is ok, the proper way of getting page number of an address is just to clear the lowest bits of the latter. * checksums.c (GC_record_fault, GC_was_faulted): Do not round-up when computing page. * checksums.c (GC_record_fault): Add assertion that GC_page_size is initialized. --- checksums.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/checksums.c b/checksums.c index f0f902a3..c0ecebea 100644 --- a/checksums.c +++ b/checksums.c @@ -41,8 +41,9 @@ STATIC size_t GC_n_faulted = 0; void GC_record_fault(struct hblk * h) { - word page = ROUNDUP_PAGESIZE((word)h); + word page = (word)h & ~(GC_page_size - 1); + GC_ASSERT(GC_page_size != 0); if (GC_n_faulted >= NSUMS) ABORT("write fault log overflowed"); GC_faulted[GC_n_faulted++] = page; } @@ -50,7 +51,7 @@ void GC_record_fault(struct hblk * h) STATIC GC_bool GC_was_faulted(struct hblk *h) { size_t i; - word page = ROUNDUP_PAGESIZE((word)h); + word page = (word)h & ~(GC_page_size - 1); for (i = 0; i < GC_n_faulted; ++i) { if (GC_faulted[i] == page) return TRUE; -- 2.50.1