]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukboot: Ensure page-aligned mem regions are added to allocator
authorSergiu Moga <sergiu@unikraft.io>
Sat, 19 Aug 2023 10:35:23 +0000 (13:35 +0300)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:35:55 +0000 (19:35 +0300)
If paging is disabled, ensure compatibility with memory allocators
such as TLSF, by only adding page-aligned free memory regions to the
memory allocator pools. Throw an exception otherwise.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1060

lib/ukboot/boot.c

index 836d0456fbef8621c77c4fe8b56e0bfbe999e205..c53504d2a9884b81c7a209f1bc465c1380cfc3ab 100644 (file)
@@ -86,6 +86,7 @@
 #ifdef CONFIG_LIBUKSP
 #include <uk/sp.h>
 #endif
+#include <uk/arch/paging.h>
 #include <uk/arch/tls.h>
 #include <uk/plat/tls.h>
 #include "banner.h"
@@ -186,6 +187,11 @@ static struct uk_alloc *heap_init()
         * add every subsequent region to it.
         */
        ukplat_memregion_foreach(&md, UKPLAT_MEMRT_FREE, 0, 0) {
+               UK_ASSERT(md->vbase == md->pbase);
+               UK_ASSERT(!(md->pbase & ~PAGE_MASK));
+               UK_ASSERT(md->len);
+               UK_ASSERT(!(md->len & ~PAGE_MASK));
+
                uk_pr_debug("Trying %p-%p 0x%02x %s\n",
                            (void *)md->vbase, (void *)(md->vbase + md->len),
                            md->flags,