Ensure that we do not try to fetch a memory region descriptor by an
index that is larger than our current memory region descriptor count.
Furthermore, this guarantees that `ukplat_memregion_count` is always
called before `ukplat_memregion_get` is executed fully. This way we
will always have the memory region descriptors as well as their count
set up and available before we try to fetch one.
Co-authored-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Diego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
GitHub-Fixes: #766
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #878
UK_ASSERT(m);
+ if (i >= ukplat_memregion_count())
+ return -1;
+
if (i == 0 && _liblinuxuplat_opts.heap.base) {
mrd[0].pbase = (__paddr_t)_liblinuxuplat_opts.heap.base;
mrd[0].vbase = mrd[0].pbase;