source: trunk/packages/xen-3.1/xen-3.1/tools/libxc/xc_private.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 5.0 KB
Line 
1
2#ifndef XC_PRIVATE_H
3#define XC_PRIVATE_H
4
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>
15
16#include "xenctrl.h"
17
18#include <xen/sys/privcmd.h>
19
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
32
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))
39
40#define DEBUG    1
41#define INFO     1
42#define PROGRESS 0
43
44/*
45** Define max dirty page cache to permit during save/restore -- need to balance
46** keeping cache usage down with CPU impact of invalidating too often.
47** (Currently 16MB)
48*/
49#define MAX_PAGECACHE_USAGE (4*1024)
50
51#if INFO
52#define IPRINTF(_f, _a...) printf(_f , ## _a)
53#else
54#define IPRINTF(_f, _a...) ((void)0)
55#endif
56
57#if DEBUG
58#define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
59#else
60#define DPRINTF(_f, _a...) ((void)0)
61#endif
62
63#if PROGRESS
64#define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
65#else
66#define PPRINTF(_f, _a...)
67#endif
68
69char *safe_strerror(int errcode);
70void xc_set_error(int code, const char *fmt, ...);
71
72#define ERROR(_m, _a...)  xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
73#define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
74                                       ## _a , errno, safe_strerror(errno))
75
76int lock_pages(void *addr, size_t len);
77void unlock_pages(void *addr, size_t len);
78
79static inline void safe_munlock(const void *addr, size_t len)
80{
81    int saved_errno = errno;
82    (void)munlock(addr, len);
83    errno = saved_errno;
84}
85
86int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
87
88static inline int do_xen_version(int xc_handle, int cmd, void *dest)
89{
90    DECLARE_HYPERCALL;
91
92    hypercall.op     = __HYPERVISOR_xen_version;
93    hypercall.arg[0] = (unsigned long) cmd;
94    hypercall.arg[1] = (unsigned long) dest;
95
96    return do_xen_hypercall(xc_handle, &hypercall);
97}
98
99static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
100{
101    int ret = -1;
102    DECLARE_HYPERCALL;
103
104    domctl->interface_version = XEN_DOMCTL_INTERFACE_VERSION;
105
106    hypercall.op     = __HYPERVISOR_domctl;
107    hypercall.arg[0] = (unsigned long)domctl;
108
109    if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
110    {
111        PERROR("Could not lock memory for Xen hypercall");
112        goto out1;
113    }
114
115    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
116    {
117        if ( errno == EACCES )
118            DPRINTF("domctl operation failed -- need to"
119                    " rebuild the user-space tool set?\n");
120    }
121
122    unlock_pages(domctl, sizeof(*domctl));
123
124 out1:
125    return ret;
126}
127
128static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
129{
130    int ret = -1;
131    DECLARE_HYPERCALL;
132
133    sysctl->interface_version = XEN_SYSCTL_INTERFACE_VERSION;
134
135    hypercall.op     = __HYPERVISOR_sysctl;
136    hypercall.arg[0] = (unsigned long)sysctl;
137
138    if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
139    {
140        PERROR("Could not lock memory for Xen hypercall");
141        goto out1;
142    }
143
144    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
145    {
146        if ( errno == EACCES )
147            DPRINTF("sysctl operation failed -- need to"
148                    " rebuild the user-space tool set?\n");
149    }
150
151    unlock_pages(sysctl, sizeof(*sysctl));
152
153 out1:
154    return ret;
155}
156
157int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
158                          privcmd_mmap_entry_t *entries, int nr);
159
160void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
161                         vcpu_guest_context_t *ctxt);
162int xc_waitdomain_core(int xc_handle, int domain, int *status,
163    int options, vcpu_guest_context_t *ctxt);
164
165void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
166void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
167
168/* Optionally flush file to disk and discard page cache */
169void discard_file_cache(int fd, int flush);
170
171#define MAX_MMU_UPDATES 1024
172struct xc_mmu {
173    mmu_update_t updates[MAX_MMU_UPDATES];
174    int          idx;
175    domid_t      subject;
176};
177/* Structure returned by xc_alloc_mmu_updates must be free()'ed by caller. */
178struct xc_mmu *xc_alloc_mmu_updates(int xc_handle, domid_t dom);
179int xc_add_mmu_update(int xc_handle, struct xc_mmu *mmu,
180                   unsigned long long ptr, unsigned long long val);
181int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu);
182
183#endif /* __XC_PRIVATE_H__ */
Note: See TracBrowser for help on using the repository browser.