Whenever a memory region allocation request done through
`bootmemory_palloc` would require a length equal to one of the
available memory regions, a new, equivalent, memory region would
be created and the original one would be left empty, thus breaking
the memory allocator.
Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #848
ostart = mrd->pbase;
olen = mrd->len;
+ /* If fragmenting this memory region leaves it with length 0,
+ * then simply overwrite and return it instead
+ */
+ if (olen - (pstart - ostart) == size) {
+ mrd->pbase = pstart;
+ mrd->vbase = pstart;
+ mrd->len = pend - pstart;
+ mrd->type = type;
+ mrd->flags = UKPLAT_MEMRF_READ |
+ UKPLAT_MEMRF_WRITE |
+ UKPLAT_MEMRF_MAP;
+
+ return (void *)pstart;
+ }
+
/* Adjust free region */
mrd->len -= pend - mrd->pbase;
mrd->pbase = pend;