debuggers.hg

view tools/libxc/xc_solaris.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 5cb466187e1f
children 3ffdb094c2c0 779c0ef9682c
line source
1 /******************************************************************************
2 *
3 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
9 * License.
10 */
12 #include "xc_private.h"
14 #include <xen/memory.h>
15 #include <xen/sys/evtchn.h>
16 #include <unistd.h>
17 #include <fcntl.h>
19 int xc_interface_open(void)
20 {
21 int flags, saved_errno;
22 int fd = open("/dev/xen/privcmd", O_RDWR);
24 if ( fd == -1 )
25 {
26 PERROR("Could not obtain handle on privileged command interface");
27 return -1;
28 }
30 /* Although we return the file handle as the 'xc handle' the API
31 does not specify / guarentee that this integer is in fact
32 a file handle. Thus we must take responsiblity to ensure
33 it doesn't propagate (ie leak) outside the process */
34 if ( (flags = fcntl(fd, F_GETFD)) < 0 )
35 {
36 PERROR("Could not get file handle flags");
37 goto error;
38 }
39 flags |= FD_CLOEXEC;
40 if ( fcntl(fd, F_SETFD, flags) < 0 )
41 {
42 PERROR("Could not set file handle flags");
43 goto error;
44 }
46 return fd;
48 error:
49 saved_errno = errno;
50 close(fd);
51 errno = saved_errno;
52 return -1;
53 }
55 int xc_interface_close(int xc_handle)
56 {
57 return close(xc_handle);
58 }
60 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
61 xen_pfn_t *arr, int num)
62 {
63 privcmd_mmapbatch_t ioctlx;
64 void *addr;
65 addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
66 if ( addr == MAP_FAILED )
67 return NULL;
69 ioctlx.num=num;
70 ioctlx.dom=dom;
71 ioctlx.addr=(unsigned long)addr;
72 ioctlx.arr=arr;
73 if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
74 {
75 int saved_errno = errno;
76 perror("XXXXXXXX");
77 (void)munmap(addr, num*PAGE_SIZE);
78 errno = saved_errno;
79 return NULL;
80 }
81 return addr;
83 }
85 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
86 int size, int prot,
87 unsigned long mfn)
88 {
89 privcmd_mmap_t ioctlx;
90 privcmd_mmap_entry_t entry;
91 void *addr;
92 addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
93 if ( addr == MAP_FAILED )
94 return NULL;
96 ioctlx.num=1;
97 ioctlx.dom=dom;
98 ioctlx.entry=&entry;
99 entry.va=(unsigned long) addr;
100 entry.mfn=mfn;
101 entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
102 if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
103 {
104 int saved_errno = errno;
105 (void)munmap(addr, size);
106 errno = saved_errno;
107 return NULL;
108 }
109 return addr;
110 }
112 void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
113 size_t size, int prot, size_t chunksize,
114 privcmd_mmap_entry_t entries[], int nentries)
115 {
116 privcmd_mmap_t ioctlx;
117 int i, rc;
118 void *addr;
120 addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
121 if (addr == MAP_FAILED)
122 goto mmap_failed;
124 for (i = 0; i < nentries; i++) {
125 entries[i].va = (uintptr_t)addr + (i * chunksize);
126 entries[i].npages = chunksize >> PAGE_SHIFT;
127 }
129 ioctlx.num = nentries;
130 ioctlx.dom = dom;
131 ioctlx.entry = entries;
133 rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
134 if (rc)
135 goto ioctl_failed;
137 return addr;
139 ioctl_failed:
140 rc = munmap(addr, size);
141 if (rc == -1)
142 ERROR("%s: error in error path\n", __FUNCTION__);
144 mmap_failed:
145 return NULL;
146 }
149 static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
150 {
151 return ioctl(xc_handle, cmd, data);
152 }
154 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
155 {
156 return do_privcmd(xc_handle,
157 IOCTL_PRIVCMD_HYPERCALL,
158 (unsigned long)hypercall);
159 }
161 int xc_evtchn_open(void)
162 {
163 int fd;
165 if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 )
166 {
167 PERROR("Could not open event channel interface");
168 return -1;
169 }
171 return fd;
172 }
174 int xc_evtchn_close(int xce_handle)
175 {
176 return close(xce_handle);
177 }
179 int xc_evtchn_fd(int xce_handle)
180 {
181 return xce_handle;
182 }
184 int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
185 {
186 struct ioctl_evtchn_notify notify;
188 notify.port = port;
190 return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
191 }
193 evtchn_port_or_error_t
194 xc_evtchn_bind_unbound_port(int xce_handle, int domid)
195 {
196 struct ioctl_evtchn_bind_unbound_port bind;
198 bind.remote_domain = domid;
200 return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
201 }
203 evtchn_port_or_error_t
204 xc_evtchn_bind_interdomain(int xce_handle, int domid,
205 evtchn_port_t remote_port)
206 {
207 struct ioctl_evtchn_bind_interdomain bind;
209 bind.remote_domain = domid;
210 bind.remote_port = remote_port;
212 return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
213 }
215 evtchn_port_or_error_t
216 xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
217 {
218 struct ioctl_evtchn_bind_virq bind;
220 bind.virq = virq;
222 return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
223 }
225 int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
226 {
227 struct ioctl_evtchn_unbind unbind;
229 unbind.port = port;
231 return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
232 }
234 evtchn_port_or_error_t
235 xc_evtchn_pending(int xce_handle)
236 {
237 evtchn_port_t port;
239 if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
240 return -1;
242 return port;
243 }
245 int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
246 {
247 return write_exact(xce_handle, (char *)&port, sizeof(port));
248 }
250 /* Optionally flush file to disk and discard page cache */
251 void discard_file_cache(int fd, int flush)
252 {
253 // TODO: Implement for Solaris!
254 }
256 grant_entry_v1_t *xc_gnttab_map_table_v1(
257 int xc_handle, int domid, int *gnt_num)
258 {
259 return NULL;
260 }
262 grant_entry_v2_t *xc_gnttab_map_table_v2(
263 int xc_handle, int domid, int *gnt_num)
264 {
265 return NULL;
266 }