|
|
|
|
|
|
|
|
|
|
xen-devel
[Xen-devel] [PATCH] stubdom: make munmap work in batches to fix stack ov
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 <=
|
|
|
|
|