use super::addresses::to_canonical_global;
use super::image::{Image, PointsTo};
use super::layout::K;
use super::regions::{Owner, PTRS};
use super::tables::*;
use super::types::*;
pub(super) fn is_render_list(pointee: u16) -> bool {
POINTEES[pointee as usize] == "DisplayListNode"
}
pub(super) fn region_leaves(
layout: u16,
base: u32,
count: u32,
f: &mut impl FnMut(u32, K, u16, u32),
) {
if layout == PTRS {
for i in 0..count {
f(base + 4 * i, K::Word, PTRS, 4 * i);
}
} else {
let pool_block = named_by("AllocOnlyPoolBlock").map(|x| x.1);
leaves(layout, base, &mut |a, k, l, o| {
if !(Some(l) == pool_block && o == 4) {
f(a, k, l, o)
}
});
}
}
pub(super) fn union_word_target(img: &Image, v: u32, rodata_ok: bool) -> PointsTo {
match img.classify(v) {
PointsTo::Heap(c, o) => PointsTo::Heap(c, o),
PointsTo::Global(g) if g >= DATA_START || rodata_ok => PointsTo::Global(g),
_ => PointsTo::Null,
}
}
pub(super) fn is_display_list_heap(owner: Owner) -> bool {
matches!(owner, Owner::Var(i) if VARS[i].0.ends_with(":gDisplayListHeap"))
}
pub(super) fn object_pointer_slots(img: &Image, obj: u32) -> u128 {
let bhv = img
.read(obj + OBJ_BEHAVIOR)
.and_then(|b| to_canonical_global(img.build, b));
match bhv.and_then(|b| {
BEHAVIOR_POINTER_SLOTS
.binary_search_by_key(&b, |x| x.0)
.ok()
}) {
Some(i) => COMMON_POINTER_SLOTS | BEHAVIOR_POINTER_SLOTS[i].1,
None => POINTER_SLOTS,
}
}
pub(super) fn is_number_slot(img: &Image, obj: Option<u16>, layout: u16, a: u32, off: u32) -> bool {
Some(layout) == obj
&& (OBJ_RAW..OBJ_RAW + 4 * OBJ_RAW_WORDS).contains(&off)
&& (object_pointer_slots(img, a - off) >> ((off - OBJ_RAW) / 4)) & 1 == 0
}
pub(super) fn may_point_to_constants(obj: Option<u16>, layout: u16, off: u32) -> bool {
if only_words(layout) {
return true;
}
Some(layout) == obj
&& (((OBJ_RAW..OBJ_RAW + 4 * OBJ_RAW_WORDS).contains(&off)
&& (POINTER_SLOTS >> ((off - OBJ_RAW) / 4)) & 1 != 0)
|| (OBJ_BHV_STACK..OBJ_BHV_STACK + 32).contains(&off))
}