debuggers.hg

changeset 20000:6d41644623de

libxc: Use a single mmap interface to Linux

Modify xc_map_foreign_range and xc_map_foreign_ranges to call
mmap_map_foreign_batch. This eliminates the need for multiple privcmd
mmap ioctls. Now only IOCTL_PRIVCMD_MMAPBATCH is required.

Signed-off-by: Patrick Colp <Patrick.Colp@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jul 20 10:58:06 2009 +0100 (2009-07-20)
parents e34975d7d8f1
children 5333e6497af6
files tools/libxc/xc_linux.c
line diff
     1.1 --- a/tools/libxc/xc_linux.c	Mon Jul 20 10:12:38 2009 +0100
     1.2 +++ b/tools/libxc/xc_linux.c	Mon Jul 20 10:58:06 2009 +0100
     1.3 @@ -92,67 +92,38 @@ void *xc_map_foreign_range(int xc_handle
     1.4                             int size, int prot,
     1.5                             unsigned long mfn)
     1.6  {
     1.7 -    privcmd_mmap_t ioctlx;
     1.8 -    privcmd_mmap_entry_t entry;
     1.9 -    void *addr;
    1.10 -    addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
    1.11 -    if ( addr == MAP_FAILED ) {
    1.12 -        perror("xc_map_foreign_range: mmap failed");
    1.13 -        return NULL;
    1.14 -    }
    1.15 +    xen_pfn_t *arr;
    1.16 +    int num;
    1.17 +    int i;
    1.18  
    1.19 -    ioctlx.num=1;
    1.20 -    ioctlx.dom=dom;
    1.21 -    ioctlx.entry=&entry;
    1.22 -    entry.va=(unsigned long) addr;
    1.23 -    entry.mfn=mfn;
    1.24 -    entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
    1.25 -    if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
    1.26 -    {
    1.27 -        int saved_errno = errno;
    1.28 -        perror("xc_map_foreign_range: ioctl failed");
    1.29 -        (void)munmap(addr, size);
    1.30 -        errno = saved_errno;
    1.31 -        return NULL;
    1.32 -    }
    1.33 -    return addr;
    1.34 +    num = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
    1.35 +    arr = calloc(num, sizeof(xen_pfn_t));
    1.36 +
    1.37 +    for ( i = 0; i < num; i++ )
    1.38 +        arr[i] = mfn + i;
    1.39 +
    1.40 +    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
    1.41  }
    1.42  
    1.43  void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
    1.44                              size_t size, int prot, size_t chunksize,
    1.45                              privcmd_mmap_entry_t entries[], int nentries)
    1.46  {
    1.47 -    privcmd_mmap_t ioctlx;
    1.48 -    int i, rc;
    1.49 -    void *addr;
    1.50 +    xen_pfn_t *arr;
    1.51 +    int num_per_entry;
    1.52 +    int num;
    1.53 +    int i;
    1.54 +    int j;
    1.55  
    1.56 -    addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
    1.57 -    if ( addr == MAP_FAILED )
    1.58 -        goto mmap_failed;
    1.59 +    num_per_entry = chunksize >> PAGE_SHIFT;
    1.60 +    num = num_per_entry * nentries;
    1.61 +    arr = calloc(num, sizeof(xen_pfn_t));
    1.62  
    1.63      for ( i = 0; i < nentries; i++ )
    1.64 -    {
    1.65 -        entries[i].va = (unsigned long)addr + (i * chunksize);
    1.66 -        entries[i].npages = chunksize >> PAGE_SHIFT;
    1.67 -    }
    1.68 -
    1.69 -    ioctlx.num   = nentries;
    1.70 -    ioctlx.dom   = dom;
    1.71 -    ioctlx.entry = entries;
    1.72 +        for ( j = 0; j < num_per_entry; j++ )
    1.73 +            arr[i * num_per_entry + j] = entries[i].mfn + j;
    1.74  
    1.75 -    rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
    1.76 -    if ( rc )
    1.77 -        goto ioctl_failed;
    1.78 -
    1.79 -    return addr;
    1.80 -
    1.81 -ioctl_failed:
    1.82 -    rc = munmap(addr, size);
    1.83 -    if ( rc == -1 )
    1.84 -        ERROR("%s: error in error path\n", __FUNCTION__);
    1.85 -
    1.86 -mmap_failed:
    1.87 -    return NULL;
    1.88 +    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
    1.89  }
    1.90  
    1.91  static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)