Fix page calculation in checksums
authorIvan Maidanski <ivmai@mail.ru>
Fri, 23 Sep 2016 06:39:18 +0000 (09:39 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 23 Sep 2016 06:41:45 +0000 (09:41 +0300)
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

index f0f902a..c0ecebe 100644 (file)
@@ -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;