debuggers.hg

view tools/libxc/xc_private.h @ 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 fbe8f32fa257
children ce1003709cf0
line source
2 #ifndef XC_PRIVATE_H
3 #define XC_PRIVATE_H
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <string.h>
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <stdlib.h>
14 #include <sys/ioctl.h>
16 #include "xenctrl.h"
18 #include <xen/sys/privcmd.h>
20 /* valgrind cannot see when a hypercall has filled in some values. For this
21 reason, we must zero the privcmd_hypercall_t or domctl/sysctl instance
22 before a call, if using valgrind. */
23 #ifdef VALGRIND
24 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall = { 0 }
25 #define DECLARE_DOMCTL struct xen_domctl domctl = { 0 }
26 #define DECLARE_SYSCTL struct xen_sysctl sysctl = { 0 }
27 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op = { 0 }
28 #else
29 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
30 #define DECLARE_DOMCTL struct xen_domctl domctl
31 #define DECLARE_SYSCTL struct xen_sysctl sysctl
32 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op
33 #endif
35 #undef PAGE_SHIFT
36 #undef PAGE_SIZE
37 #undef PAGE_MASK
38 #define PAGE_SHIFT XC_PAGE_SHIFT
39 #define PAGE_SIZE (1UL << PAGE_SHIFT)
40 #define PAGE_MASK (~(PAGE_SIZE-1))
42 #define DEBUG 1
43 #define INFO 1
44 #define PROGRESS 0
46 /* Force a compilation error if condition is true */
47 #define XC_BUILD_BUG_ON(p) ((void)sizeof(struct { int:-!!(p); }))
49 /*
50 ** Define max dirty page cache to permit during save/restore -- need to balance
51 ** keeping cache usage down with CPU impact of invalidating too often.
52 ** (Currently 16MB)
53 */
54 #define MAX_PAGECACHE_USAGE (4*1024)
56 #if INFO
57 #define IPRINTF(_f, _a...) printf(_f , ## _a)
58 #else
59 #define IPRINTF(_f, _a...) ((void)0)
60 #endif
62 #if DEBUG
63 #define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
64 #else
65 #define DPRINTF(_f, _a...) ((void)0)
66 #endif
68 #if PROGRESS
69 #define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
70 #else
71 #define PPRINTF(_f, _a...)
72 #endif
74 char *safe_strerror(int errcode);
75 void xc_set_error(int code, const char *fmt, ...);
77 #define ERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
78 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
79 ## _a , errno, safe_strerror(errno))
81 void *xc_memalign(size_t alignment, size_t size);
83 int lock_pages(void *addr, size_t len);
84 void unlock_pages(void *addr, size_t len);
86 int hcall_buf_prep(void **addr, size_t len);
87 void hcall_buf_release(void **addr, size_t len);
89 static inline void safe_munlock(const void *addr, size_t len)
90 {
91 int saved_errno = errno;
92 (void)munlock(addr, len);
93 errno = saved_errno;
94 }
96 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
98 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
99 {
100 DECLARE_HYPERCALL;
102 hypercall.op = __HYPERVISOR_xen_version;
103 hypercall.arg[0] = (unsigned long) cmd;
104 hypercall.arg[1] = (unsigned long) dest;
106 return do_xen_hypercall(xc_handle, &hypercall);
107 }
109 static inline int do_physdev_op(int xc_handle, int cmd, void *op, size_t len)
110 {
111 int ret = -1;
113 DECLARE_HYPERCALL;
115 if ( hcall_buf_prep(&op, len) != 0 )
116 {
117 PERROR("Could not lock memory for Xen hypercall");
118 goto out1;
119 }
121 hypercall.op = __HYPERVISOR_physdev_op;
122 hypercall.arg[0] = (unsigned long) cmd;
123 hypercall.arg[1] = (unsigned long) op;
125 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
126 {
127 if ( errno == EACCES )
128 DPRINTF("physdev operation failed -- need to"
129 " rebuild the user-space tool set?\n");
130 }
132 hcall_buf_release(&op, len);
134 out1:
135 return ret;
136 }
138 static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
139 {
140 int ret = -1;
141 DECLARE_HYPERCALL;
143 if ( hcall_buf_prep((void **)&domctl, sizeof(*domctl)) != 0 )
144 {
145 PERROR("Could not lock memory for Xen hypercall");
146 goto out1;
147 }
149 domctl->interface_version = XEN_DOMCTL_INTERFACE_VERSION;
151 hypercall.op = __HYPERVISOR_domctl;
152 hypercall.arg[0] = (unsigned long)domctl;
154 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
155 {
156 if ( errno == EACCES )
157 DPRINTF("domctl operation failed -- need to"
158 " rebuild the user-space tool set?\n");
159 }
161 hcall_buf_release((void **)&domctl, sizeof(*domctl));
163 out1:
164 return ret;
165 }
167 static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
168 {
169 int ret = -1;
170 DECLARE_HYPERCALL;
172 if ( hcall_buf_prep((void **)&sysctl, sizeof(*sysctl)) != 0 )
173 {
174 PERROR("Could not lock memory for Xen hypercall");
175 goto out1;
176 }
178 sysctl->interface_version = XEN_SYSCTL_INTERFACE_VERSION;
180 hypercall.op = __HYPERVISOR_sysctl;
181 hypercall.arg[0] = (unsigned long)sysctl;
183 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
184 {
185 if ( errno == EACCES )
186 DPRINTF("sysctl operation failed -- need to"
187 " rebuild the user-space tool set?\n");
188 }
190 hcall_buf_release((void **)&sysctl, sizeof(*sysctl));
192 out1:
193 return ret;
194 }
196 void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
197 size_t size, int prot, size_t chunksize,
198 privcmd_mmap_entry_t entries[], int nentries);
200 int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
201 unsigned int num, xen_pfn_t *);
203 void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
204 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
206 /* Optionally flush file to disk and discard page cache */
207 void discard_file_cache(int fd, int flush);
209 #define MAX_MMU_UPDATES 1024
210 struct xc_mmu {
211 mmu_update_t updates[MAX_MMU_UPDATES];
212 int idx;
213 domid_t subject;
214 };
215 /* Structure returned by xc_alloc_mmu_updates must be free()'ed by caller. */
216 struct xc_mmu *xc_alloc_mmu_updates(int xc_handle, domid_t dom);
217 int xc_add_mmu_update(int xc_handle, struct xc_mmu *mmu,
218 unsigned long long ptr, unsigned long long val);
219 int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu);
221 /* Return 0 on success; -1 on error. */
222 int read_exact(int fd, void *data, size_t size);
223 int write_exact(int fd, const void *data, size_t size);
225 int xc_ffs8(uint8_t x);
226 int xc_ffs16(uint16_t x);
227 int xc_ffs32(uint32_t x);
228 int xc_ffs64(uint64_t x);
230 #endif /* __XC_PRIVATE_H__ */