Files
xen/tools/libxc/xc_foreign_memory.c
T
Ian Campbell bd1c1ea440 tools/libs/foreignmemory: Support err == NULL to map.
The existing xc_map_foreign_bulk-like interface encourages callers to
miss error checking for partial failure (by forgetting to scan the err
array).

Add support for passing err==NULL which behaves in a
xc_map_foreign_pages-like manner and returns a global error for any
failure.

While documenting this also clarify the overall behaviour and the
behaviour with err!=NULL.

With this the compat wrapper of xc_map_foreign_pages() can be
simplified.

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:18 +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, arr, NULL, num);
}
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, arr, err, num);
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/