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 }
xengntshr_share_pages(xengntshr_handle * xcg,uint32_t domid,int count,uint32_t * refs,int writable)67 void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid,
68                             int count, uint32_t *refs, int writable)
69 {
70     return osdep_gntshr_share_pages(xcg, domid, count, refs, writable, -1, -1);
71 }
72 
xengntshr_share_page_notify(xengntshr_handle * xcg,uint32_t domid,uint32_t * ref,int writable,uint32_t notify_offset,evtchn_port_t notify_port)73 void *xengntshr_share_page_notify(xengntshr_handle *xcg, uint32_t domid,
74                                   uint32_t *ref, int writable,
75                                   uint32_t notify_offset,
76                                   evtchn_port_t notify_port)
77 {
78     return osdep_gntshr_share_pages(xcg, domid, 1, ref, writable,
79                                     notify_offset, notify_port);
80 }
81 
xengntshr_unshare(xengntshr_handle * xgs,void * start_address,uint32_t count)82 int xengntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count)
83 {
84     return osdep_gntshr_unshare(xgs, start_address, count);
85 }
86 
87 /*
88  * Local variables:
89  * mode: C
90  * c-file-style: "BSD"
91  * c-basic-offset: 4
92  * tab-width: 4
93  * indent-tabs-mode: nil
94  * End:
95  */
96