direct-io.hg

view tools/libxc/xc_private.h @ 11774:5d2ce349f9f4

[SOLARIS] Don't build ptrace code on Solaris.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Oct 17 17:59:32 2006 +0100 (2006-10-17)
parents 86d26e6ec89b
children 5b036362c1b0
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 #define ERR(_f, _a...) do { \
63 DPRINTF(_f ": %d\n" , ## _a, errno); \
64 fflush(stderr); } \
65 while (0)
67 #define ERROR(_m, _a...) \
68 do { \
69 int __saved_errno = errno; \
70 DPRINTF("ERROR: " _m "\n" , ## _a ); \
71 errno = __saved_errno; \
72 } while (0)
74 #define PERROR(_m, _a...) \
75 do { \
76 int __saved_errno = errno; \
77 DPRINTF("ERROR: " _m " (%d = %s)\n" , ## _a , \
78 __saved_errno, strerror(__saved_errno)); \
79 errno = __saved_errno; \
80 } while (0)
82 static inline void safe_munlock(const void *addr, size_t len)
83 {
84 int saved_errno = errno;
85 (void)munlock(addr, len);
86 errno = saved_errno;
87 }
89 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
91 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
92 {
93 DECLARE_HYPERCALL;
95 hypercall.op = __HYPERVISOR_xen_version;
96 hypercall.arg[0] = (unsigned long) cmd;
97 hypercall.arg[1] = (unsigned long) dest;
99 return do_xen_hypercall(xc_handle, &hypercall);
100 }
102 static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
103 {
104 int ret = -1;
105 DECLARE_HYPERCALL;
107 domctl->interface_version = XEN_DOMCTL_INTERFACE_VERSION;
109 hypercall.op = __HYPERVISOR_domctl;
110 hypercall.arg[0] = (unsigned long)domctl;
112 if ( mlock(domctl, sizeof(*domctl)) != 0 )
113 {
114 PERROR("Could not lock memory for Xen hypercall");
115 goto out1;
116 }
118 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
119 {
120 if ( errno == EACCES )
121 DPRINTF("domctl operation failed -- need to"
122 " rebuild the user-space tool set?\n");
123 }
125 safe_munlock(domctl, sizeof(*domctl));
127 out1:
128 return ret;
129 }
131 static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
132 {
133 int ret = -1;
134 DECLARE_HYPERCALL;
136 sysctl->interface_version = XEN_SYSCTL_INTERFACE_VERSION;
138 hypercall.op = __HYPERVISOR_sysctl;
139 hypercall.arg[0] = (unsigned long)sysctl;
141 if ( mlock(sysctl, sizeof(*sysctl)) != 0 )
142 {
143 PERROR("Could not lock memory for Xen hypercall");
144 goto out1;
145 }
147 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
148 {
149 if ( errno == EACCES )
150 DPRINTF("sysctl operation failed -- need to"
151 " rebuild the user-space tool set?\n");
152 }
154 safe_munlock(sysctl, sizeof(*sysctl));
156 out1:
157 return ret;
158 }
160 int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
161 privcmd_mmap_entry_t *entries, int nr);
163 #endif /* __XC_PRIVATE_H__ */