#ifndef __DOM0_DEFS_H__ #define __DOM0_DEFS_H__ #include #include #include #include #include #include #include #include #include #include #include typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; typedef unsigned long long u64; typedef signed char s8; typedef signed short s16; typedef signed long s32; typedef signed long long s64; #include "mem_defs.h" #include #include #include #define ERROR(_m) \ fprintf(stderr, "ERROR: %s\n", (_m)) #define PERROR(_m) \ fprintf(stderr, "ERROR: %s (%d = %s)\n", (_m), errno, strerror(errno)) static inline int do_privcmd(unsigned int cmd, unsigned long data) { int fd, ret; if ( (fd = open("/proc/xeno/privcmd", O_RDWR)) < 0 ) { PERROR("Could not open proc interface"); return -1; } if ( (ret = ioctl(fd, cmd, data)) < 0 ) { #ifndef SILENT_ERRORS_FROM_XEN PERROR("Error when executing privileged control ioctl"); #endif close(fd); return -1; } close(fd); return ret; } static inline int xldev_to_physdev(int xldev) { return do_privcmd(IOCTL_PRIVCMD_LINDEV_TO_XENDEV, (unsigned long)xldev); } static inline int physdev_to_xldev(int physdev) { return do_privcmd(IOCTL_PRIVCMD_XENDEV_TO_LINDEV, (unsigned long)physdev); } static inline int do_xen_blkmsg(privcmd_blkmsg_t *blkmsg) { return do_privcmd(IOCTL_PRIVCMD_BLKMSG, (unsigned long)blkmsg); } static inline int do_xen_hypercall(privcmd_hypercall_t *hypercall) { return do_privcmd(IOCTL_PRIVCMD_HYPERCALL, (unsigned long)hypercall); } static inline int do_dom0_op(dom0_op_t *op) { int ret = -1; privcmd_hypercall_t hypercall; 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 ( do_xen_hypercall(&hypercall) < 0 ) goto out2; ret = 0; out2: (void)munlock(op, sizeof(*op)); out1: return ret; } static inline int do_network_op(network_op_t *op) { int ret = -1; privcmd_hypercall_t hypercall; hypercall.op = __HYPERVISOR_network_op; hypercall.arg[0] = (unsigned long)op; if ( mlock(op, sizeof(*op)) != 0 ) { PERROR("Could not lock memory for Xen hypercall"); goto out1; } if ( do_xen_hypercall(&hypercall) < 0 ) goto out2; ret = 0; out2: (void)munlock(op, sizeof(*op)); out1: return ret; } #endif /* __DOM0_DEFS_H__ */