Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #7829: pointer comparisons in assertions #8585

Merged
merged 3 commits into from Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -586,6 +586,9 @@ OCaml 4.08.0
no-naked-pointers
(Sam Goldman, review by Gabriel Scherer, David Allsopp, Stephen Dolan)

- #7829, #8585: Fix pointer comparisons in freelist.c (for 32-bit platforms)
(David Allsopp and Damien Doligez)

- #8567, #8569: on ARM64, use 32-bit loads to access caml_backtrace_active
(Xavier Leroy, review by Mark Shinwell and Greta Yorsh)

Expand Down
24 changes: 13 additions & 11 deletions runtime/freelist.c
Expand Up @@ -90,7 +90,8 @@ static void fl_check (void)
CAMLassert (Next (flp[flp_found]) == cur);
++ flp_found;
}else{
CAMLassert (beyond == Val_NULL || cur >= Next (beyond));
CAMLassert (beyond == Val_NULL
|| Bp_val (cur) >= Bp_val (Next (beyond)));
}
}
if (cur == caml_fl_merge) merge_found = 1;
Expand Down Expand Up @@ -417,9 +418,10 @@ static void truncate_flp (value changed)
flp_size = 0;
beyond = Val_NULL;
}else{
while (flp_size > 0 && Next (flp[flp_size - 1]) >= changed)
while (flp_size > 0
&& Bp_val (Next (flp[flp_size - 1])) >= Bp_val (changed))
-- flp_size;
if (beyond >= changed) beyond = Val_NULL;
if (Bp_val (beyond) >= Bp_val (changed)) beyond = Val_NULL;
}
}

Expand Down Expand Up @@ -460,13 +462,13 @@ header_t *caml_fl_merge_block (value bp)
cur = Next (prev);
/* The sweep code makes sure that this is the right place to insert
this block: */
CAMLassert (prev < bp || prev == Fl_head);
CAMLassert (cur > bp || cur == Val_NULL);
CAMLassert (Bp_val (prev) < Bp_val (bp) || prev == Fl_head);
CAMLassert (Bp_val (cur) > Bp_val (bp) || cur == Val_NULL);

if (policy == Policy_first_fit) truncate_flp (prev);

/* If [last_fragment] and [bp] are adjacent, merge them. */
if (last_fragment == Hp_bp (bp)){
if (last_fragment == Hp_val (bp)){
dra27 marked this conversation as resolved.
Show resolved Hide resolved
mlsize_t bp_whsz = Whsize_val (bp);
if (bp_whsz <= Max_wosize){
hd = Make_header (bp_whsz, 0, Caml_white);
Expand Down Expand Up @@ -542,7 +544,7 @@ void caml_fl_add_blocks (value bp)
cur = Field(cur, 0);
} while (cur != Val_NULL);

if (bp > fl_last){
if (Bp_val (bp) > Bp_val (fl_last)){
Next (fl_last) = bp;
if (fl_last == caml_fl_merge && (char *) bp < caml_gc_sweep_hp){
caml_fl_merge = Field (bp, 1);
Expand All @@ -555,14 +557,14 @@ void caml_fl_add_blocks (value bp)

prev = Fl_head;
cur = Next (prev);
while (cur != Val_NULL && cur < bp){
CAMLassert (prev < bp || prev == Fl_head);
while (cur != Val_NULL && Bp_val (cur) < Bp_val (bp)){
CAMLassert (Bp_val (prev) < Bp_val (bp) || prev == Fl_head);
/* XXX TODO: extend flp on the fly */
prev = cur;
cur = Next (prev);
}
CAMLassert (prev < bp || prev == Fl_head);
CAMLassert (cur > bp || cur == Val_NULL);
CAMLassert (Bp_val (prev) < Bp_val (bp) || prev == Fl_head);
CAMLassert (Bp_val (cur) > Bp_val (bp) || cur == Val_NULL);
Next (Field (bp, 1)) = cur;
Next (prev) = bp;
/* When inserting blocks between [caml_fl_merge] and [caml_gc_sweep_hp],
Expand Down
2 changes: 1 addition & 1 deletion runtime/gc_ctrl.c
Expand Up @@ -60,7 +60,7 @@ extern uintnat caml_custom_major_ratio; /* see custom.c */
extern uintnat caml_custom_minor_ratio; /* see custom.c */
extern uintnat caml_custom_minor_max_bsz; /* see custom.c */

#define Next(hp) ((hp) + Whsize_hp (hp))
#define Next(hp) ((header_t *)(hp) + Whsize_hp (hp))

#ifdef DEBUG

Expand Down
2 changes: 1 addition & 1 deletion runtime/memory.c
Expand Up @@ -788,7 +788,7 @@ CAMLexport void* caml_stat_alloc_aligned_noexc(asize_t sz, int modulo,
{
char *raw_mem;
uintnat aligned_mem;
CAMLassert (modulo < Page_size);
CAMLassert (0 <= modulo && modulo < Page_size);
raw_mem = (char *) caml_stat_alloc_noexc(sz + Page_size);
if (raw_mem == NULL) return NULL;
*b = raw_mem;
Expand Down