raz / commit d41d69ad

commit
d41d69adf6fc696722be236db55b6646d55b0546
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
ac3c464a
Heap: round a block down to its page with a mask, not mod

patch · log

1 file changed, +11 -1

lib/Heap.raz (history) modified +11 -1

@@ -78,6 +78,13 @@
7878 return give(p, c);
7979 end;
8080
81+(* The start of the page holding address a; a mask, so it holds for the
82+ top half of the address space, where an INT is negative *)
83+proc pageOf(a: INT): INT;
84+begin
85+ return a - a & (Mem.Page - 1);
86+end;
87+
8188 proc free(_a: ^Mem.Allocator; p: ^U8);
8289 var h: ^Head; b: ^Block; c: INT;
8390 begin
@@ -90,7 +97,7 @@
9097 h^.mark := 0;
9198 if h^.size < 0 then
9299 Lock.give(lock);
93- Mem.unmap(^U8(INT(h) - INT(h) mod Mem.Page), -h^.size);
100+ Mem.unmap(^U8(pageOf(INT(h))), -h^.size);
94101 else
95102 c := h^.size; (* before next, which takes its place, is set *)
96103 b := ^Block(h);
@@ -110,6 +117,9 @@
110117 p[i] := Mem.alloc(heap, n, 8);
111118 if (p[i] = nil) or (INT(p[i]) mod 8 # 0) then Rt.stop("Heap: alloc"); end;
112119 for j := 0 to n - 1 do p[i][j] := U8(i); end;
120+ end;
121+ if (pageOf(-4095) # -4096) or (pageOf(-4096) # -4096) or (pageOf(4097) # 4096) then
122+ Rt.stop("Heap: pageOf");
113123 end;
114124 for i := 0 to 39 do
115125 n := (i * i * 37) mod 9000 + 1;