[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/ukalloc: uk_getmallocsize should return size not order



Fixed uk_getmallocsize in order to get the allocated size
instead of the order. The allocated size is needed by
uk_realloc_ifpages in order to determine how much to copy
from the old allocation to the new allocated area.

Signed-off-by: Radu Nicolau <radunicolau102@xxxxxxxxx>
---
 lib/ukalloc/alloc.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
index 3260554..52e9a77 100644
--- a/lib/ukalloc/alloc.c
+++ b/lib/ukalloc/alloc.c
@@ -124,7 +124,7 @@ static void *uk_get_real_start(const void *ptr)
                                     (uintptr_t) __PAGE_SIZE);
        if (intptr == ptr) {
                /* special case: the memory was page-aligned.
-                * In this cas,e the size information lies at the start of the
+                * In this case the size information lies at the start of the
                 * previous page, with the rest of that page unused.
                 */
                intptr -= __PAGE_SIZE;
@@ -135,8 +135,24 @@ static void *uk_get_real_start(const void *ptr)
 static size_t uk_getmallocsize(const void *ptr)
 {
        size_t *intptr = uk_get_real_start(ptr);
+       size_t mallocsize = __PAGE_SIZE << (*intptr);
 
-       return *intptr;
+       if (((uintptr_t) ptr & (~__PAGE_MASK)) == 0) {
+               /*
+                * special case: the memory was page-aligned
+                * In this case the allocated size should not account for the
+                * previous page which was used for storing the order
+                */
+               mallocsize -= __PAGE_SIZE;
+       } else {
+               /*
+                * If pointer is not page aligned it means the header is
+                * on the same page. This will break if metadata size increases
+                */
+               mallocsize -= sizeof(*intptr);
+       }
+
+       return mallocsize;
 }
 
 /* return the smallest order (1<<order pages) that can fit size bytes */
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.