/root/src/xen/xen/common/compat/domain.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * domain.c |
3 | | * |
4 | | */ |
5 | | |
6 | | asm(".file \"" __FILE__ "\""); |
7 | | |
8 | | #include <xen/lib.h> |
9 | | #include <xen/sched.h> |
10 | | #include <xen/domain.h> |
11 | | #include <xen/guest_access.h> |
12 | | #include <xen/hypercall.h> |
13 | | #include <compat/vcpu.h> |
14 | | #include <compat/hvm/hvm_vcpu.h> |
15 | | |
16 | | #define xen_vcpu_set_periodic_timer vcpu_set_periodic_timer |
17 | | CHECK_vcpu_set_periodic_timer; |
18 | | #undef xen_vcpu_set_periodic_timer |
19 | | |
20 | | #define xen_vcpu_info vcpu_info |
21 | | CHECK_SIZE_(struct, vcpu_info); |
22 | | #undef xen_vcpu_info |
23 | | |
24 | | #define xen_vcpu_register_vcpu_info vcpu_register_vcpu_info |
25 | | CHECK_vcpu_register_vcpu_info; |
26 | | #undef xen_vcpu_register_vcpu_info |
27 | | |
28 | | #define xen_vcpu_hvm_context vcpu_hvm_context |
29 | | #define xen_vcpu_hvm_x86_32 vcpu_hvm_x86_32 |
30 | | #define xen_vcpu_hvm_x86_64 vcpu_hvm_x86_64 |
31 | | CHECK_vcpu_hvm_context; |
32 | | #undef xen_vcpu_hvm_x86_64 |
33 | | #undef xen_vcpu_hvm_x86_32 |
34 | | #undef xen_vcpu_hvm_context |
35 | | |
36 | | int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg) |
37 | 0 | { |
38 | 0 | struct domain *d = current->domain; |
39 | 0 | struct vcpu *v; |
40 | 0 | int rc = 0; |
41 | 0 |
|
42 | 0 | if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL ) |
43 | 0 | return -ENOENT; |
44 | 0 |
|
45 | 0 | switch ( cmd ) |
46 | 0 | { |
47 | 0 | case VCPUOP_initialise: |
48 | 0 | { |
49 | 0 | if ( v->vcpu_info == &dummy_vcpu_info ) |
50 | 0 | return -EINVAL; |
51 | 0 |
|
52 | 0 | if ( is_hvm_vcpu(v) ) |
53 | 0 | { |
54 | 0 | struct vcpu_hvm_context ctxt; |
55 | 0 |
|
56 | 0 | if ( copy_from_guest(&ctxt, arg, 1) ) |
57 | 0 | return -EFAULT; |
58 | 0 |
|
59 | 0 | domain_lock(d); |
60 | 0 | rc = v->is_initialised ? -EEXIST : arch_set_info_hvm_guest(v, &ctxt); |
61 | 0 | domain_unlock(d); |
62 | 0 | } |
63 | 0 | else |
64 | 0 | { |
65 | 0 | struct compat_vcpu_guest_context *ctxt; |
66 | 0 |
|
67 | 0 | if ( (ctxt = xmalloc(struct compat_vcpu_guest_context)) == NULL ) |
68 | 0 | return -ENOMEM; |
69 | 0 |
|
70 | 0 | if ( copy_from_guest(ctxt, arg, 1) ) |
71 | 0 | { |
72 | 0 | xfree(ctxt); |
73 | 0 | return -EFAULT; |
74 | 0 | } |
75 | 0 |
|
76 | 0 | domain_lock(d); |
77 | 0 | rc = v->is_initialised ? -EEXIST : arch_set_info_guest(v, ctxt); |
78 | 0 | domain_unlock(d); |
79 | 0 |
|
80 | 0 | xfree(ctxt); |
81 | 0 | } |
82 | 0 |
|
83 | 0 | if ( rc == -ERESTART ) |
84 | 0 | rc = hypercall_create_continuation(__HYPERVISOR_vcpu_op, "iuh", |
85 | 0 | cmd, vcpuid, arg); |
86 | 0 |
|
87 | 0 | break; |
88 | 0 | } |
89 | 0 |
|
90 | 0 | case VCPUOP_up: |
91 | 0 | case VCPUOP_down: |
92 | 0 | case VCPUOP_is_up: |
93 | 0 | case VCPUOP_set_periodic_timer: |
94 | 0 | case VCPUOP_stop_periodic_timer: |
95 | 0 | case VCPUOP_stop_singleshot_timer: |
96 | 0 | case VCPUOP_register_vcpu_info: |
97 | 0 | case VCPUOP_send_nmi: |
98 | 0 | rc = do_vcpu_op(cmd, vcpuid, arg); |
99 | 0 | break; |
100 | 0 |
|
101 | 0 | case VCPUOP_get_runstate_info: |
102 | 0 | { |
103 | 0 | union { |
104 | 0 | struct vcpu_runstate_info nat; |
105 | 0 | struct compat_vcpu_runstate_info cmp; |
106 | 0 | } runstate; |
107 | 0 |
|
108 | 0 | vcpu_runstate_get(v, &runstate.nat); |
109 | 0 | xlat_vcpu_runstate_info(&runstate.nat); |
110 | 0 | if ( copy_to_guest(arg, &runstate.cmp, 1) ) |
111 | 0 | rc = -EFAULT; |
112 | 0 | break; |
113 | 0 | } |
114 | 0 |
|
115 | 0 | case VCPUOP_set_singleshot_timer: |
116 | 0 | { |
117 | 0 | struct compat_vcpu_set_singleshot_timer cmp; |
118 | 0 | struct vcpu_set_singleshot_timer *nat; |
119 | 0 |
|
120 | 0 | if ( copy_from_guest(&cmp, arg, 1) ) |
121 | 0 | return -EFAULT; |
122 | 0 | nat = COMPAT_ARG_XLAT_VIRT_BASE; |
123 | 0 | XLAT_vcpu_set_singleshot_timer(nat, &cmp); |
124 | 0 | rc = do_vcpu_op(cmd, vcpuid, guest_handle_from_ptr(nat, void)); |
125 | 0 | break; |
126 | 0 | } |
127 | 0 |
|
128 | 0 | default: |
129 | 0 | rc = arch_compat_vcpu_op(cmd, v, arg); |
130 | 0 | break; |
131 | 0 | } |
132 | 0 |
|
133 | 0 | return rc; |
134 | 0 | } |
135 | | |
136 | | /* |
137 | | * Local variables: |
138 | | * mode: C |
139 | | * c-file-style: "BSD" |
140 | | * c-basic-offset: 4 |
141 | | * tab-width: 4 |
142 | | * indent-tabs-mode: nil |
143 | | * End: |
144 | | */ |