1 /* Compatibility functions for mapping foreign domain's memory.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation;
6 * version 2.1 of the License.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Split out from xc_foreign_memory.c
17 */
18 #if !defined(__NetBSD__) && !defined(__sun__)
19 #error Please implement osdep_xenforeignmemory_map directly for new ports.
20 #endif
21
22 #include "private.h"
23
osdep_xenforeignmemory_map(xenforeignmemory_handle * fmem,uint32_t dom,void * addr,int prot,int flags,size_t num,const xen_pfn_t arr[],int err[])24 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
25 void *addr, int prot, int flags, size_t num,
26 const xen_pfn_t arr[/*num*/], int err[/*num*/])
27 {
28 xen_pfn_t *pfn;
29 unsigned int i;
30 void *ret;
31
32 if ((int)num <= 0) {
33 errno = EINVAL;
34 return NULL;
35 }
36
37 pfn = malloc(num * sizeof(*pfn));
38 if (!pfn) {
39 errno = ENOMEM;
40 return NULL;
41 }
42
43 memcpy(pfn, arr, num * sizeof(*arr));
44 ret = osdep_map_foreign_batch(fmem, dom, addr, prot, flags, pfn, num);
45
46 if (ret) {
47 for (i = 0; i < num; ++i)
48 switch (pfn[i] ^ arr[i]) {
49 case 0:
50 err[i] = 0;
51 break;
52 default:
53 err[i] = -EINVAL;
54 break;
55 }
56 } else
57 memset(err, 0, num * sizeof(*err));
58
59 free(pfn);
60
61 return ret;
62 }
63
64 /*
65 * Local variables:
66 * mode: C
67 * c-file-style: "BSD"
68 * c-basic-offset: 4
69 * tab-width: 4
70 * indent-tabs-mode: nil
71 * End:
72 */
73