Build an overlap map if entries completely overlap

This commit adds the logic to construct the overlap map used by
        the split_entry() function later. The reason an overlap map must
        be constructed is because complete overlaps within a usable
        region of memory may happen multiple times. The overlap map
        keeps track of these overlaps so that entries are correctly
        split if that is the case.
This commit is contained in:
Yggdrasill 2023-07-30 04:41:06 +01:00
parent c8581242a9
commit 5c289f58b4
1 changed files with 13 additions and 11 deletions

View File

@ -150,8 +150,10 @@ static size_t split_entry(struct memmap_entry *dst, struct memmap_entry *bad, st
}
static void sanitise_entries(struct memmap_entry *m, size_t *_count, bool align_entries) {
size_t num_overlaps;
size_t count = *_count;
num_overlaps = 0;
for (size_t i = 0; i < count; i++) {
if (m[i].type != MEMMAP_USABLE)
continue;
@ -171,20 +173,20 @@ static void sanitise_entries(struct memmap_entry *m, size_t *_count, bool align_
if ( (res_base >= base && res_base < top)
&& (res_top >= base && res_top < top) ) {
// TODO actually handle splitting off usable chunks
panic(false, "A non-usable memory map entry is inside a usable section.");
}
overlap[num_overlaps++] = m + j;
overlap[num_overlaps++] = m + i;
} else {
if (res_base >= base && res_base < top) {
top = res_base;
}
if (res_base >= base && res_base < top) {
top = res_base;
}
if (res_top >= base && res_top < top) {
base = res_top;
}
if (res_top >= base && res_top < top) {
base = res_top;
m[i].base = base;
m[i].length = top - base;
}
m[i].base = base;
m[i].length = top - base;
}
if (!m[i].length