Files
xen/tools/libxc/xc_private.h
T
kaf24@firebug.cl.cam.ac.uk 2d0922d515 Move Linux-specific privcmd code into private libxc implementations.
Make header path for kernel's privcmd/evtchn headers generic.
Remove pointless xi_*() interface that was using private libxc
interfaces.

Signed-off-by: John Levon <john.levon@sun.com>
2006-05-02 15:12:06 +01:00

105 lines
2.8 KiB
C

#ifndef XC_PRIVATE_H
#define XC_PRIVATE_H
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include "xenctrl.h"
#include <xen/sys/privcmd.h>
/* valgrind cannot see when a hypercall has filled in some values. For this
reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
call, if using valgrind. */
#ifdef VALGRIND
#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall = { 0 }
#define DECLARE_DOM0_OP dom0_op_t op = { 0 }
#else
#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
#define DECLARE_DOM0_OP dom0_op_t op
#endif
#define PAGE_SHIFT XC_PAGE_SHIFT
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
#define ERROR(_m, _a...) \
do { \
int __saved_errno = errno; \
fprintf(stderr, "ERROR: " _m "\n" , ## _a ); \
errno = __saved_errno; \
} while (0)
#define PERROR(_m, _a...) \
do { \
int __saved_errno = errno; \
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
__saved_errno, strerror(__saved_errno)); \
errno = __saved_errno; \
} while (0)
static inline void safe_munlock(const void *addr, size_t len)
{
int saved_errno = errno;
(void)munlock(addr, len);
errno = saved_errno;
}
int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
static inline int do_xen_version(int xc_handle, int cmd, void *dest)
{
DECLARE_HYPERCALL;
hypercall.op = __HYPERVISOR_xen_version;
hypercall.arg[0] = (unsigned long) cmd;
hypercall.arg[1] = (unsigned long) dest;
return do_xen_hypercall(xc_handle, &hypercall);
}
static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
{
int ret = -1;
DECLARE_HYPERCALL;
op->interface_version = DOM0_INTERFACE_VERSION;
hypercall.op = __HYPERVISOR_dom0_op;
hypercall.arg[0] = (unsigned long)op;
if ( mlock(op, sizeof(*op)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
}
if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
{
if ( errno == EACCES )
fprintf(stderr, "Dom0 operation failed -- need to"
" rebuild the user-space tool set?\n");
}
safe_munlock(op, sizeof(*op));
out1:
return ret;
}
int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
privcmd_mmap_entry_t *entries, int nr);
#endif /* __XC_PRIVATE_H__ */