forked from xen-project/xen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnttab_core.c
171 lines (145 loc) · 5.13 KB
/
gnttab_core.c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/******************************************************************************
*
* Copyright (c) 2007-2008, D G Murray <[email protected]>
* Copyright (c) 2018, Oleksandr Andrushchenko, EPAM Systems Inc.
*
* 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/>.
*
* Split out from xc_gnttab.c
*/
#include <stdlib.h>
#include "private.h"
static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) {
xengnttab_handle *xgt = CONTAINER_OF(ah, *xgt, tc_ah);
return xentoolcore__restrict_by_dup2_null(xgt->fd);
}
xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags)
{
xengnttab_handle *xgt = malloc(sizeof(*xgt));
int rc;
if (!xgt) return NULL;
xgt->fd = -1;
xgt->logger = logger;
xgt->logger_tofree = NULL;
xgt->tc_ah.restrict_callback = all_restrict_cb;
xentoolcore__register_active_handle(&xgt->tc_ah);
if (!xgt->logger) {
xgt->logger = xgt->logger_tofree =
(xentoollog_logger*)
xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
if (!xgt->logger) goto err;
}
rc = osdep_gnttab_open(xgt);
if ( rc < 0 ) goto err;
return xgt;
err:
xentoolcore__deregister_active_handle(&xgt->tc_ah);
osdep_gnttab_close(xgt);
xtl_logger_destroy(xgt->logger_tofree);
free(xgt);
return NULL;
}
int xengnttab_close(xengnttab_handle *xgt)
{
int rc;
if ( !xgt )
return 0;
xentoolcore__deregister_active_handle(&xgt->tc_ah);
rc = osdep_gnttab_close(xgt);
xtl_logger_destroy(xgt->logger_tofree);
free(xgt);
return rc;
}
int xengnttab_fd(xengnttab_handle *xgt)
{
return xgt->fd;
}
int xengnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count)
{
return osdep_gnttab_set_max_grants(xgt, count);
}
void *xengnttab_map_grant_ref(xengnttab_handle *xgt,
uint32_t domid,
uint32_t ref,
int prot)
{
return osdep_gnttab_grant_map(xgt, 1, 0, prot, &domid, &ref, -1, -1);
}
void *xengnttab_map_grant_refs(xengnttab_handle *xgt,
uint32_t count,
uint32_t *domids,
uint32_t *refs,
int prot)
{
return osdep_gnttab_grant_map(xgt, count, 0, prot, domids, refs, -1, -1);
}
void *xengnttab_map_domain_grant_refs(xengnttab_handle *xgt,
uint32_t count,
uint32_t domid,
uint32_t *refs,
int prot)
{
return osdep_gnttab_grant_map(xgt, count, XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN,
prot, &domid, refs, -1, -1);
}
void *xengnttab_map_grant_ref_notify(xengnttab_handle *xgt,
uint32_t domid,
uint32_t ref,
int prot,
uint32_t notify_offset,
evtchn_port_t notify_port)
{
return osdep_gnttab_grant_map(xgt, 1, 0, prot, &domid, &ref,
notify_offset, notify_port);
}
int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count)
{
return osdep_gnttab_unmap(xgt, start_address, count);
}
int xengnttab_grant_copy(xengnttab_handle *xgt,
uint32_t count,
xengnttab_grant_copy_segment_t *segs)
{
return osdep_gnttab_grant_copy(xgt, count, segs);
}
int xengnttab_dmabuf_exp_from_refs(xengnttab_handle *xgt, uint32_t domid,
uint32_t flags, uint32_t count,
const uint32_t *refs, uint32_t *fd)
{
return osdep_gnttab_dmabuf_exp_from_refs(xgt, domid, flags, count,
refs, fd);
}
int xengnttab_dmabuf_exp_wait_released(xengnttab_handle *xgt, uint32_t fd,
uint32_t wait_to_ms)
{
return osdep_gnttab_dmabuf_exp_wait_released(xgt, fd, wait_to_ms);
}
int xengnttab_dmabuf_imp_to_refs(xengnttab_handle *xgt, uint32_t domid,
uint32_t fd, uint32_t count, uint32_t *refs)
{
return osdep_gnttab_dmabuf_imp_to_refs(xgt, domid, fd, count, refs);
}
int xengnttab_dmabuf_imp_release(xengnttab_handle *xgt, uint32_t fd)
{
return osdep_gnttab_dmabuf_imp_release(xgt, fd);
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/