1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/******************************************************************************
* 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:
*/
|