ia64/xen-unstable

changeset 18383:846590f85062

stubdom: make munmap work in batches to fix stack overflow

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 27 09:47:24 2008 +0100 (2008-08-27)
parents fa98f03a6bcd
children f17ab0889f3b
files extras/mini-os/lib/sys.c
line diff
     1.1 --- a/extras/mini-os/lib/sys.c	Wed Aug 27 09:47:08 2008 +0100
     1.2 +++ b/extras/mini-os/lib/sys.c	Wed Aug 27 09:47:24 2008 +0100
     1.3 @@ -1143,34 +1143,44 @@ void *mmap(void *start, size_t length, i
     1.4      } else ASSERT(0);
     1.5  }
     1.6  
     1.7 +#define UNMAP_BATCH ((STACK_SIZE / 2) / sizeof(multicall_entry_t))
     1.8  int munmap(void *start, size_t length)
     1.9  {
    1.10 -    int i, n = length / PAGE_SIZE;
    1.11 -    multicall_entry_t call[n];
    1.12 -    unsigned char (*data)[PAGE_SIZE] = start;
    1.13 -    int ret;
    1.14 +    int total = length / PAGE_SIZE;
    1.15      ASSERT(!((unsigned long)start & ~PAGE_MASK));
    1.16 -    ASSERT(!(length & ~PAGE_MASK));
    1.17 +    while (total) {
    1.18 +        int n = UNMAP_BATCH;
    1.19 +        if (n > total)
    1.20 +            n = total;
    1.21 +        {
    1.22 +            int i;
    1.23 +            multicall_entry_t call[n];
    1.24 +            unsigned char (*data)[PAGE_SIZE] = start;
    1.25 +            int ret;
    1.26  
    1.27 -    for (i = 0; i < n; i++) {
    1.28 -	call[i].op = __HYPERVISOR_update_va_mapping;
    1.29 -	call[i].args[0] = (unsigned long) &data[i];
    1.30 -	call[i].args[1] = 0;
    1.31 -	call[i].args[2] = 0;
    1.32 -	call[i].args[3] = UVMF_INVLPG;
    1.33 -    }
    1.34 +            for (i = 0; i < n; i++) {
    1.35 +                call[i].op = __HYPERVISOR_update_va_mapping;
    1.36 +                call[i].args[0] = (unsigned long) &data[i];
    1.37 +                call[i].args[1] = 0;
    1.38 +                call[i].args[2] = 0;
    1.39 +                call[i].args[3] = UVMF_INVLPG;
    1.40 +            }
    1.41  
    1.42 -    ret = HYPERVISOR_multicall(call, n);
    1.43 -    if (ret) {
    1.44 -	errno = -ret;
    1.45 -	return -1;
    1.46 -    }
    1.47 +            ret = HYPERVISOR_multicall(call, n);
    1.48 +            if (ret) {
    1.49 +                errno = -ret;
    1.50 +                return -1;
    1.51 +            }
    1.52  
    1.53 -    for (i = 0; i < n; i++) {
    1.54 -	if (call[i].result) {
    1.55 -	    errno = call[i].result;
    1.56 -	    return -1;
    1.57 -	}
    1.58 +            for (i = 0; i < n; i++) {
    1.59 +                if (call[i].result) {
    1.60 +                    errno = call[i].result;
    1.61 +                    return -1;
    1.62 +                }
    1.63 +            }
    1.64 +        }
    1.65 +        start += n * PAGE_SIZE;
    1.66 +        total -= n;
    1.67      }
    1.68      return 0;
    1.69  }