1 | /****************************************************************************** |
---|
2 | * domain.c |
---|
3 | * |
---|
4 | */ |
---|
5 | |
---|
6 | #include <xen/config.h> |
---|
7 | #include <xen/lib.h> |
---|
8 | #include <xen/sched.h> |
---|
9 | #include <xen/domain.h> |
---|
10 | #include <xen/guest_access.h> |
---|
11 | #include <xen/hypercall.h> |
---|
12 | #include <compat/vcpu.h> |
---|
13 | |
---|
14 | int compat_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE(void) arg) |
---|
15 | { |
---|
16 | struct domain *d = current->domain; |
---|
17 | struct vcpu *v; |
---|
18 | long rc = 0; |
---|
19 | |
---|
20 | if ( (vcpuid < 0) || (vcpuid >= MAX_VIRT_CPUS) ) |
---|
21 | return -EINVAL; |
---|
22 | |
---|
23 | if ( (v = d->vcpu[vcpuid]) == NULL ) |
---|
24 | return -ENOENT; |
---|
25 | |
---|
26 | switch ( cmd ) |
---|
27 | { |
---|
28 | case VCPUOP_initialise: |
---|
29 | { |
---|
30 | struct compat_vcpu_guest_context *cmp_ctxt; |
---|
31 | |
---|
32 | if ( (cmp_ctxt = xmalloc(struct compat_vcpu_guest_context)) == NULL ) |
---|
33 | { |
---|
34 | rc = -ENOMEM; |
---|
35 | break; |
---|
36 | } |
---|
37 | |
---|
38 | if ( copy_from_guest(cmp_ctxt, arg, 1) ) |
---|
39 | { |
---|
40 | xfree(cmp_ctxt); |
---|
41 | rc = -EFAULT; |
---|
42 | break; |
---|
43 | } |
---|
44 | |
---|
45 | LOCK_BIGLOCK(d); |
---|
46 | rc = -EEXIST; |
---|
47 | if ( !v->is_initialised ) |
---|
48 | rc = boot_vcpu(d, vcpuid, cmp_ctxt); |
---|
49 | UNLOCK_BIGLOCK(d); |
---|
50 | |
---|
51 | xfree(cmp_ctxt); |
---|
52 | break; |
---|
53 | } |
---|
54 | |
---|
55 | case VCPUOP_up: |
---|
56 | case VCPUOP_down: |
---|
57 | case VCPUOP_is_up: |
---|
58 | case VCPUOP_set_periodic_timer: |
---|
59 | case VCPUOP_stop_periodic_timer: |
---|
60 | case VCPUOP_set_singleshot_timer: |
---|
61 | case VCPUOP_stop_singleshot_timer: |
---|
62 | rc = do_vcpu_op(cmd, vcpuid, arg); |
---|
63 | break; |
---|
64 | |
---|
65 | case VCPUOP_get_runstate_info: |
---|
66 | { |
---|
67 | union { |
---|
68 | struct vcpu_runstate_info nat; |
---|
69 | struct compat_vcpu_runstate_info cmp; |
---|
70 | } runstate; |
---|
71 | |
---|
72 | vcpu_runstate_get(v, &runstate.nat); |
---|
73 | xlat_vcpu_runstate_info(&runstate.nat); |
---|
74 | if ( copy_to_guest(arg, &runstate.cmp, 1) ) |
---|
75 | rc = -EFAULT; |
---|
76 | break; |
---|
77 | } |
---|
78 | |
---|
79 | default: |
---|
80 | rc = arch_compat_vcpu_op(cmd, v, arg); |
---|
81 | break; |
---|
82 | } |
---|
83 | |
---|
84 | return rc; |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * Local variables: |
---|
89 | * mode: C |
---|
90 | * c-set-style: "BSD" |
---|
91 | * c-basic-offset: 4 |
---|
92 | * tab-width: 4 |
---|
93 | * indent-tabs-mode: nil |
---|
94 | * End: |
---|
95 | */ |
---|