debuggers.hg

view tools/xenpaging/xc.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents ae3567ccf524
children
line source
1 /******************************************************************************
2 * tools/xenpaging/lib/xc.c
3 *
4 * libxc-type add-ons for paging support.
5 *
6 * Copyright (c) 2009 Citrix Systems, Inc. (Patrick Colp)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
24 #include <errno.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <sys/poll.h>
28 #include <xc_private.h>
29 #include <xg_save_restore.h>
30 #include <xs.h>
31 #include "xc.h"
34 int alloc_bitmap(unsigned long **bitmap, unsigned long bitmap_size)
35 {
36 if ( *bitmap == NULL )
37 {
38 *bitmap = calloc(bitmap_size / BITS_PER_LONG, sizeof(unsigned long));
40 if ( *bitmap == NULL )
41 return -ENOMEM;
42 }
44 memset(*bitmap, 0, bitmap_size / 8);
46 return 0;
47 }
49 int xc_mem_paging_flush_ioemu_cache(domid_t domain_id)
50 {
51 struct xs_handle *xsh = NULL;
52 char path[80];
53 int rc;
55 sprintf(path, "/local/domain/0/device-model/%u/command", domain_id);
57 xsh = xs_daemon_open();
58 if ( xsh == NULL )
59 return -EIO;
61 rc = xs_write(xsh, XBT_NULL, path, "flush-cache", strlen("flush-cache"));
63 xs_daemon_close(xsh);
65 return rc ? 0 : -1;
66 }
68 int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms)
69 {
70 struct pollfd fd = { .fd = xc_evtchn_fd(xce), .events = POLLIN | POLLERR };
71 int port;
72 int rc;
74 rc = poll(&fd, 1, ms);
75 if ( rc == -1 )
76 {
77 if (errno == EINTR)
78 return 0;
80 ERROR("Poll exited with an error");
81 goto err;
82 }
84 if ( rc == 1 )
85 {
86 port = xc_evtchn_pending(xce);
87 if ( port == -1 )
88 {
89 ERROR("Failed to read port from event channel");
90 goto err;
91 }
93 rc = xc_evtchn_unmask(xce, port);
94 if ( rc != 0 )
95 {
96 ERROR("Failed to unmask event channel port");
97 goto err;
98 }
99 }
100 else
101 port = -1;
103 return port;
105 err:
106 return -errno;
107 }
109 int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce)
110 {
111 return xc_wait_for_event_or_timeout(xch, xce, -1);
112 }
114 int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
115 xc_platform_info_t *platform_info)
116 {
117 return get_platform_info(xc_handle, domain_id,
118 &platform_info->max_mfn,
119 &platform_info->hvirt_start,
120 &platform_info->pt_levels,
121 &platform_info->guest_width);
122 }
125 /*
126 * Local variables:
127 * mode: C
128 * c-set-style: "BSD"
129 * c-basic-offset: 4
130 * tab-width: 4
131 * indent-tabs-mode: nil
132 * End:
133 */