ia64/xen-unstable

view tools/libxc/xc_private.h @ 6433:0610add7c3fe

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 16:27:04 2005 +0000 (2005-08-25)
parents b54144915ae6 fdfd511768a3
children b4b3f6be5226
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/linux/privcmd.h>
20 #define PAGE_SHIFT XC_PAGE_SHIFT
21 #define PAGE_SIZE (1UL << PAGE_SHIFT)
22 #define PAGE_MASK (~(PAGE_SIZE-1))
24 #define ERROR(_m, _a...) \
25 do { \
26 int __saved_errno = errno; \
27 fprintf(stderr, "ERROR: " _m "\n" , ## _a ); \
28 errno = __saved_errno; \
29 } while (0)
32 #define PERROR(_m, _a...) \
33 do { \
34 int __saved_errno = errno; \
35 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
36 __saved_errno, strerror(__saved_errno)); \
37 errno = __saved_errno; \
38 } while (0)
40 static inline void safe_munlock(const void *addr, size_t len)
41 {
42 int saved_errno = errno;
43 (void)munlock(addr, len);
44 errno = saved_errno;
45 }
47 static inline int do_privcmd(int xc_handle,
48 unsigned int cmd,
49 unsigned long data)
50 {
51 return ioctl(xc_handle, cmd, data);
52 }
54 static inline int do_xen_hypercall(int xc_handle,
55 privcmd_hypercall_t *hypercall)
56 {
57 return do_privcmd(xc_handle,
58 IOCTL_PRIVCMD_HYPERCALL,
59 (unsigned long)hypercall);
60 }
62 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
63 {
64 int ret = -1;
65 privcmd_hypercall_t hypercall;
67 op->interface_version = DOM0_INTERFACE_VERSION;
69 hypercall.op = __HYPERVISOR_dom0_op;
70 hypercall.arg[0] = (unsigned long)op;
72 if ( mlock(op, sizeof(*op)) != 0 )
73 {
74 PERROR("Could not lock memory for Xen hypercall");
75 goto out1;
76 }
78 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
79 {
80 if ( errno == EACCES )
81 fprintf(stderr, "Dom0 operation failed -- need to"
82 " rebuild the user-space tool set?\n");
83 }
85 safe_munlock(op, sizeof(*op));
87 out1:
88 return ret;
89 }
92 /*
93 * ioctl-based mfn mapping interface
94 */
96 /*
97 typedef struct privcmd_mmap_entry {
98 unsigned long va;
99 unsigned long mfn;
100 unsigned long npages;
101 } privcmd_mmap_entry_t;
103 typedef struct privcmd_mmap {
104 int num;
105 domid_t dom;
106 privcmd_mmap_entry_t *entry;
107 } privcmd_mmap_t;
108 */
110 #endif /* __XC_PRIVATE_H__ */