debuggers.hg

view tools/internal/dom0_defs.h @ 655:ef9e002c0596

bitkeeper revision 1.339.1.5 (3f12bf52q2jR3Bjy5IVRUmb2tYPLpw)

dom0_defs.h:
Fix xi_ tools to get return code from privcmd proc file.
author kaf24@scramble.cl.cam.ac.uk
date Mon Jul 14 14:33:54 2003 +0000 (2003-07-14)
parents 9339f3942f4e
children c085fac641e2
line source
2 #ifndef __DOM0_DEFS_H__
3 #define __DOM0_DEFS_H__
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <sys/mman.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <stdlib.h>
13 #include <sys/ioctl.h>
14 #include <errno.h>
15 #include <string.h>
17 typedef unsigned char u8;
18 typedef unsigned short u16;
19 typedef unsigned long u32;
20 typedef unsigned long long u64;
21 typedef signed char s8;
22 typedef signed short s16;
23 typedef signed long s32;
24 typedef signed long long s64;
26 #include "mem_defs.h"
27 #include <asm-xeno/proc_cmd.h>
28 #include <hypervisor-ifs/hypervisor-if.h>
29 #include <hypervisor-ifs/dom0_ops.h>
31 #define ERROR(_m) \
32 fprintf(stderr, "ERROR: %s\n", (_m))
34 #define PERROR(_m) \
35 fprintf(stderr, "ERROR: %s (%d = %s)\n", (_m), errno, strerror(errno))
37 static inline int do_privcmd(unsigned int cmd, unsigned long data)
38 {
39 int fd, ret;
41 if ( (fd = open("/proc/xeno/privcmd", O_RDWR)) < 0 )
42 {
43 PERROR("Could not open proc interface");
44 return -1;
45 }
47 if ( (ret = ioctl(fd, cmd, data)) < 0 )
48 {
49 #ifndef SILENT_ERRORS_FROM_XEN
50 PERROR("Error when executing privileged control ioctl");
51 #endif
52 close(fd);
53 return -1;
54 }
56 close(fd);
57 return ret;
58 }
60 static inline int xldev_to_physdev(int xldev)
61 {
62 return do_privcmd(IOCTL_PRIVCMD_LINDEV_TO_XENDEV,
63 (unsigned long)xldev);
64 }
66 static inline int physdev_to_xldev(int physdev)
67 {
68 return do_privcmd(IOCTL_PRIVCMD_XENDEV_TO_LINDEV,
69 (unsigned long)physdev);
70 }
72 static inline int do_xen_blkmsg(privcmd_blkmsg_t *blkmsg)
73 {
74 return do_privcmd(IOCTL_PRIVCMD_BLKMSG, (unsigned long)blkmsg);
75 }
77 static inline int do_xen_hypercall(privcmd_hypercall_t *hypercall)
78 {
79 return do_privcmd(IOCTL_PRIVCMD_HYPERCALL, (unsigned long)hypercall);
80 }
82 static inline int do_dom0_op(dom0_op_t *op)
83 {
84 int ret = -1;
85 privcmd_hypercall_t hypercall;
87 hypercall.op = __HYPERVISOR_dom0_op;
88 hypercall.arg[0] = (unsigned long)op;
90 if ( mlock(op, sizeof(*op)) != 0 )
91 {
92 PERROR("Could not lock memory for Xen hypercall");
93 goto out1;
94 }
96 if ( do_xen_hypercall(&hypercall) < 0 )
97 goto out2;
99 ret = 0;
101 out2: (void)munlock(op, sizeof(*op));
102 out1: return ret;
103 }
105 static inline int do_network_op(network_op_t *op)
106 {
107 int ret = -1;
108 privcmd_hypercall_t hypercall;
110 hypercall.op = __HYPERVISOR_network_op;
111 hypercall.arg[0] = (unsigned long)op;
113 if ( mlock(op, sizeof(*op)) != 0 )
114 {
115 PERROR("Could not lock memory for Xen hypercall");
116 goto out1;
117 }
119 if ( do_xen_hypercall(&hypercall) < 0 )
120 goto out2;
122 ret = 0;
124 out2: (void)munlock(op, sizeof(*op));
125 out1: return ret;
126 }
128 #endif /* __DOM0_DEFS_H__ */