Skip to content

Commit

Permalink
Fix capability provenance in GC_prev_block on CHERI
Browse files Browse the repository at this point in the history
(fix of commit c29365b)

Issue #627 (bdwgc).

Use a capability (pointer) rather than a computed pointer value
in `GC_prev_block()`.

* allchblk.c (GC_split_block): Initialize `last_hdr->hb_block`.
* alloc.c (GC_add_to_heap): Initialize `hhdr->hb_block`.
* headers.c (GC_prev_block): Remove TODO item; return `hhdr->hb_block`
instead of `HBLK_ADDR(bi,j)`; add assertion that `HBLK_ADDR(bi,j)`
gives the same address as of `hhdr->hb_block`.
  • Loading branch information
ivmai committed Jan 17, 2025
1 parent 28ed64c commit 816a802
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions allchblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ GC_split_block(struct hblk *hbp, hdr *hhdr, struct hblk *last_hbp,
/* Replace hbp with last_hbp on its free list. */
last_hdr->hb_prev = prev;
last_hdr->hb_next = next;
last_hdr->hb_block = last_hbp;
last_hdr->hb_sz = hhdr->hb_sz - h_size;
last_hdr->hb_flags = 0;
if (prev /* != NULL */) { /* CPPCHECK */
Expand Down
1 change: 1 addition & 0 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ GC_add_to_heap(struct hblk *h, size_t sz)
GC_heap_sects[GC_n_heap_sects].hs_start = (ptr_t)h;
GC_heap_sects[GC_n_heap_sects].hs_bytes = sz;
GC_n_heap_sects++;
hhdr->hb_block = h;
hhdr->hb_sz = sz;
hhdr->hb_flags = 0;
GC_freehblk(h);
Expand Down
4 changes: 2 additions & 2 deletions headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ GC_prev_block(struct hblk *h)
} else if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
j -= (GC_signed_word)ADDR(hhdr);
} else {
/* TODO: return hhdr -> hb_block instead */
return (struct hblk *)MAKE_CPTR(HBLK_ADDR(bi, j));
GC_ASSERT(HBLK_ADDR(bi, j) == ADDR(hhdr->hb_block));
return hhdr->hb_block;
}
}
j = BOTTOM_SZ - 1;
Expand Down

0 comments on commit 816a802

Please sign in to comment.