| | @@ -78,6 +78,13 @@ |
| 78 | 78 | return give(p, c); |
| 79 | 79 | end; |
| 80 | 80 | |
| 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 | + |
| 81 | 88 | proc free(_a: ^Mem.Allocator; p: ^U8); |
| 82 | 89 | var h: ^Head; b: ^Block; c: INT; |
| 83 | 90 | begin |
| | @@ -90,7 +97,7 @@ |
| 90 | 97 | h^.mark := 0; |
| 91 | 98 | if h^.size < 0 then |
| 92 | 99 | 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); |
| 94 | 101 | else |
| 95 | 102 | c := h^.size; (* before next, which takes its place, is set *) |
| 96 | 103 | b := ^Block(h); |
| | @@ -110,6 +117,9 @@ |
| 110 | 117 | p[i] := Mem.alloc(heap, n, 8); |
| 111 | 118 | if (p[i] = nil) or (INT(p[i]) mod 8 # 0) then Rt.stop("Heap: alloc"); end; |
| 112 | 119 | 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"); |
| 113 | 123 | end; |
| 114 | 124 | for i := 0 to 39 do |
| 115 | 125 | n := (i * i * 37) mod 9000 + 1; |