ia64/xen-unstable

view tools/libxc/xc_private.h @ 13517:cd532c9351fc

[LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this
for conversion of the domctl_cpumap.
Original patch from Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jan 19 14:36:12 2007 +0000 (2007-01-19)
parents da87dc126b33
children 59b8d5168cc1
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 #else
28 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
29 #define DECLARE_DOMCTL struct xen_domctl domctl
30 #define DECLARE_SYSCTL struct xen_sysctl sysctl
31 #endif
33 #undef PAGE_SHIFT
34 #undef PAGE_SIZE
35 #undef PAGE_MASK
36 #define PAGE_SHIFT XC_PAGE_SHIFT
37 #define PAGE_SIZE (1UL << PAGE_SHIFT)
38 #define PAGE_MASK (~(PAGE_SIZE-1))
40 #define DEBUG 1
41 #define INFO 1
42 #define PROGRESS 0
44 #if INFO
45 #define IPRINTF(_f, _a...) printf(_f , ## _a)
46 #else
47 #define IPRINTF(_f, _a...) ((void)0)
48 #endif
50 #if DEBUG
51 #define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
52 #else
53 #define DPRINTF(_f, _a...) ((void)0)
54 #endif
56 #if PROGRESS
57 #define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
58 #else
59 #define PPRINTF(_f, _a...)
60 #endif
62 char *safe_strerror(int errcode);
63 void xc_set_error(int code, const char *fmt, ...);
65 #define ERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
66 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
67 ## _a , errno, safe_strerror(errno))
69 int lock_pages(void *addr, size_t len);
70 void unlock_pages(void *addr, size_t len);
72 static inline void safe_munlock(const void *addr, size_t len)
73 {
74 int saved_errno = errno;
75 (void)munlock(addr, len);
76 errno = saved_errno;
77 }
79 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
81 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
82 {
83 DECLARE_HYPERCALL;
85 hypercall.op = __HYPERVISOR_xen_version;
86 hypercall.arg[0] = (unsigned long) cmd;
87 hypercall.arg[1] = (unsigned long) dest;
89 return do_xen_hypercall(xc_handle, &hypercall);
90 }
92 static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
93 {
94 int ret = -1;
95 DECLARE_HYPERCALL;
97 domctl->interface_version = XEN_DOMCTL_INTERFACE_VERSION;
99 hypercall.op = __HYPERVISOR_domctl;
100 hypercall.arg[0] = (unsigned long)domctl;
102 if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
103 {
104 PERROR("Could not lock memory for Xen hypercall");
105 goto out1;
106 }
108 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
109 {
110 if ( errno == EACCES )
111 DPRINTF("domctl operation failed -- need to"
112 " rebuild the user-space tool set?\n");
113 }
115 unlock_pages(domctl, sizeof(*domctl));
117 out1:
118 return ret;
119 }
121 static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
122 {
123 int ret = -1;
124 DECLARE_HYPERCALL;
126 sysctl->interface_version = XEN_SYSCTL_INTERFACE_VERSION;
128 hypercall.op = __HYPERVISOR_sysctl;
129 hypercall.arg[0] = (unsigned long)sysctl;
131 if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
132 {
133 PERROR("Could not lock memory for Xen hypercall");
134 goto out1;
135 }
137 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
138 {
139 if ( errno == EACCES )
140 DPRINTF("sysctl operation failed -- need to"
141 " rebuild the user-space tool set?\n");
142 }
144 unlock_pages(sysctl, sizeof(*sysctl));
146 out1:
147 return ret;
148 }
150 int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
151 privcmd_mmap_entry_t *entries, int nr);
153 void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
154 vcpu_guest_context_t *ctxt);
155 int xc_waitdomain_core(int xc_handle, int domain, int *status,
156 int options, vcpu_guest_context_t *ctxt);
158 void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
159 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
161 #endif /* __XC_PRIVATE_H__ */