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

[Xen-changelog] [xen-unstable] stubdom: make munmap work in batches to fix stack overflow



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1219826844 -3600
# Node ID 846590f850624742ebe98e070b2b4c1a96693eac
# Parent  fa98f03a6bcd571db59548292b6850ef39e4bbc9
stubdom: make munmap work in batches to fix stack overflow

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
---
 extras/mini-os/lib/sys.c |   60 +++++++++++++++++++++++++++--------------------
 1 files changed, 35 insertions(+), 25 deletions(-)

diff -r fa98f03a6bcd -r 846590f85062 extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Wed Aug 27 09:47:08 2008 +0100
+++ b/extras/mini-os/lib/sys.c  Wed Aug 27 09:47:24 2008 +0100
@@ -1143,34 +1143,44 @@ void *mmap(void *start, size_t length, i
     } else ASSERT(0);
 }
 
+#define UNMAP_BATCH ((STACK_SIZE / 2) / sizeof(multicall_entry_t))
 int munmap(void *start, size_t length)
 {
-    int i, n = length / PAGE_SIZE;
-    multicall_entry_t call[n];
-    unsigned char (*data)[PAGE_SIZE] = start;
-    int ret;
+    int total = length / PAGE_SIZE;
     ASSERT(!((unsigned long)start & ~PAGE_MASK));
-    ASSERT(!(length & ~PAGE_MASK));
-
-    for (i = 0; i < n; i++) {
-       call[i].op = __HYPERVISOR_update_va_mapping;
-       call[i].args[0] = (unsigned long) &data[i];
-       call[i].args[1] = 0;
-       call[i].args[2] = 0;
-       call[i].args[3] = UVMF_INVLPG;
-    }
-
-    ret = HYPERVISOR_multicall(call, n);
-    if (ret) {
-       errno = -ret;
-       return -1;
-    }
-
-    for (i = 0; i < n; i++) {
-       if (call[i].result) {
-           errno = call[i].result;
-           return -1;
-       }
+    while (total) {
+        int n = UNMAP_BATCH;
+        if (n > total)
+            n = total;
+        {
+            int i;
+            multicall_entry_t call[n];
+            unsigned char (*data)[PAGE_SIZE] = start;
+            int ret;
+
+            for (i = 0; i < n; i++) {
+                call[i].op = __HYPERVISOR_update_va_mapping;
+                call[i].args[0] = (unsigned long) &data[i];
+                call[i].args[1] = 0;
+                call[i].args[2] = 0;
+                call[i].args[3] = UVMF_INVLPG;
+            }
+
+            ret = HYPERVISOR_multicall(call, n);
+            if (ret) {
+                errno = -ret;
+                return -1;
+            }
+
+            for (i = 0; i < n; i++) {
+                if (call[i].result) {
+                    errno = call[i].result;
+                    return -1;
+                }
+            }
+        }
+        start += n * PAGE_SIZE;
+        total -= n;
     }
     return 0;
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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