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

[UNIKRAFT PATCH 2/2] lib/ukmmap: Add page-alignment support to mmap/munmap



The D runtime library is dependent on this property
---
 lib/ukmmap/mmap.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/ukmmap/mmap.c b/lib/ukmmap/mmap.c
index 7cee8dc..3422411 100644
--- a/lib/ukmmap/mmap.c
+++ b/lib/ukmmap/mmap.c
@@ -38,6 +38,13 @@
 #include <uk/alloc.h>
 #include <string.h>
 
+#ifdef DRUNTIME
+#include <uk/essentials.h>
+
+#define size_to_num_pages(size) \
+       (ALIGN_UP((unsigned long)(size), __PAGE_SIZE) / __PAGE_SIZE)
+#endif
+
 struct mmap_addr {
        void *begin;
        void *end;
@@ -94,8 +101,12 @@ void *mmap(void *addr, size_t len, int prot,
                last = tmp;
                tmp = tmp->next;
        }
-       void *mem = uk_malloc(uk_alloc_get_default(), len);
-
+#ifdef DRUNTIME
+    int num_pages = size_to_num_pages(len);
+       void *mem = uk_palloc(uk_alloc_get_default(), num_pages);
+#else
+    void *mem = uk_malloc(uk_alloc_get_default(), len);
+#endif
        if (!mem) {
                errno = ENOMEM;
                return (void *) -1;
@@ -131,6 +142,7 @@ int munmap(void *addr, size_t len)
        if (!addr)
                return 0;
        while (tmp) {
+#ifndef DRUNTIME
                if (addr != tmp->begin) {
                        if (tmp->end > addr + len) {
                                errno = EINVAL;
@@ -158,6 +170,19 @@ int munmap(void *addr, size_t len)
                        uk_free(uk_alloc_get_default(), addr);
                        return 0;
                }
+#else
+        if (addr == tmp->begin) {
+                       int num_pages = size_to_num_pages(len);
+
+                       if (!prev)
+                               mmap_addr = tmp->next;
+                       else
+                               prev->next = tmp->next;
+                       uk_free(uk_alloc_get_default(), tmp);
+                       uk_pfree(uk_alloc_get_default(), addr, num_pages);
+                       break;
+        }
+#endif
                prev = tmp;
                tmp = tmp->next;
        }
-- 
2.17.1




 


Rackspace

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