WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] stubdom: make munmap work in batches to fix stack ov

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] stubdom: make munmap work in batches to fix stack overflow
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Tue, 26 Aug 2008 17:30:04 +0100
Delivery-date: Tue, 26 Aug 2008 09:30:29 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
stubdom: make munmap work in batches to fix stack overflow

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>

diff -r c2472ded5c7c extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Tue Aug 26 15:16:57 2008 +0100
+++ b/extras/mini-os/lib/sys.c  Tue Aug 26 17:26:28 2008 +0100
@@ -1115,34 +1115,44 @@
     } 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));
+    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;
-    }
+            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;
-    }
+            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;
-       }
+            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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] stubdom: make munmap work in batches to fix stack overflow, Samuel Thibault <=