1 /******************************************************************************
2  *
3  * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation;
8  * version 2.1 of the License.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Split out from xc_gnttab.c
19  */
20 
21 #include <stdlib.h>
22 
23 #include "private.h"
24 
xengntshr_open(xentoollog_logger * logger,unsigned open_flags)25 xengntshr_handle *xengntshr_open(xentoollog_logger *logger, unsigned open_flags)
26 {
27     xengntshr_handle *xgs = malloc(sizeof(*xgs));
28     int rc;
29 
30     if (!xgs) return NULL;
31 
32     xgs->fd = -1;
33     xgs->logger = logger;
34     xgs->logger_tofree  = NULL;
35 
36     if (!xgs->logger) {
37         xgs->logger = xgs->logger_tofree =
38             (xentoollog_logger*)
39             xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
40         if (!xgs->logger) goto err;
41     }
42 
43     rc = osdep_gntshr_open(xgs);
44     if ( rc  < 0 ) goto err;
45 
46     return xgs;
47 
48 err:
49     osdep_gntshr_close(xgs);
50     xtl_logger_destroy(xgs->logger_tofree);
51     free(xgs);
52     return NULL;
53 }
54 
xengntshr_close(xengntshr_handle * xgs)55 int xengntshr_close(xengntshr_handle *xgs)
56 {
57     int rc;
58 
59     if ( !xgs )
60         return 0;
61 
62     rc = osdep_gntshr_close(xgs);
63     xtl_logger_destroy(xgs->logger_tofree);
64     free(xgs);
65     return rc;
66 }
67 
xengntshr_fd(xengntshr_handle * xgs)68 int xengntshr_fd(xengntshr_handle *xgs)
69 {
70     return xgs->fd;
71 }
72 
xengntshr_share_pages(xengntshr_handle * xcg,uint32_t domid,int count,uint32_t * refs,int writable)73 void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid,
74                             int count, uint32_t *refs, int writable)
75 {
76     return osdep_gntshr_share_pages(xcg, domid, count, refs, writable, -1, -1);
77 }
78 
xengntshr_share_page_notify(xengntshr_handle * xcg,uint32_t domid,uint32_t * ref,int writable,uint32_t notify_offset,evtchn_port_t notify_port)79 void *xengntshr_share_page_notify(xengntshr_handle *xcg, uint32_t domid,
80                                   uint32_t *ref, int writable,
81                                   uint32_t notify_offset,
82                                   evtchn_port_t notify_port)
83 {
84     return osdep_gntshr_share_pages(xcg, domid, 1, ref, writable,
85                                     notify_offset, notify_port);
86 }
87 
xengntshr_unshare(xengntshr_handle * xgs,void * start_address,uint32_t count)88 int xengntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count)
89 {
90     return osdep_gntshr_unshare(xgs, start_address, count);
91 }
92 
93 /*
94  * Local variables:
95  * mode: C
96  * c-file-style: "BSD"
97  * c-basic-offset: 4
98  * tab-width: 4
99  * indent-tabs-mode: nil
100  * End:
101  */
102