Files
xen/tools/libxc/xc_foreign_memory.c
T
Ian Campbell cf8c4d3d13 tools/libs/foreignmemory: pull array length argument to map forward
By having the "num" argument before the page and error arrays we can
potentially use a variable-length-array argument ("int pages[num]") in
the function prototype.

However VLAs are a C99 feature and we are currently targetting C89 and
later, so we don't actually make use of this here, merely arrange that
we can switch to VLAs in the future without changing the function ABI.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
2016-01-22 12:24:19 +00:00

99 lines
2.7 KiB
C

/******************************************************************************
* xc_foreign_memory.c
*
* Functions for mapping foreign domain's memory.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*/
#define XC_BUILDING_COMPAT_MAP_FOREIGN_API
#include "xc_private.h"
void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
const xen_pfn_t *arr, int num)
{
if (num < 0) {
errno = EINVAL;
return NULL;
}
return xenforeignmemory_map(xch->fmem, dom, prot, num, arr, NULL);
}
void *xc_map_foreign_range(xc_interface *xch,
uint32_t dom, int size, int prot,
unsigned long mfn)
{
xen_pfn_t *arr;
int num;
int i;
void *ret;
num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
arr = calloc(num, sizeof(xen_pfn_t));
if ( arr == NULL )
return NULL;
for ( i = 0; i < num; i++ )
arr[i] = mfn + i;
ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
free(arr);
return ret;
}
void *xc_map_foreign_ranges(xc_interface *xch,
uint32_t dom, size_t size,
int prot, size_t chunksize,
privcmd_mmap_entry_t entries[],
int nentries)
{
xen_pfn_t *arr;
int num_per_entry;
int num;
int i;
int j;
void *ret;
num_per_entry = chunksize >> XC_PAGE_SHIFT;
num = num_per_entry * nentries;
arr = calloc(num, sizeof(xen_pfn_t));
if ( arr == NULL )
return NULL;
for ( i = 0; i < nentries; i++ )
for ( j = 0; j < num_per_entry; j++ )
arr[i * num_per_entry + j] = entries[i].mfn + j;
ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
free(arr);
return ret;
}
void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
const xen_pfn_t *arr, int *err, unsigned int num)
{
return xenforeignmemory_map(xch->fmem, dom, prot, num, arr, err);
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/