1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIB_ZX_VCPU_H_
6 #define LIB_ZX_VCPU_H_
7 
8 #include <lib/zx/guest.h>
9 #include <lib/zx/handle.h>
10 #include <lib/zx/object.h>
11 #include <zircon/syscalls/port.h>
12 
13 namespace zx {
14 
15 class vcpu : public object<vcpu> {
16 public:
17     static constexpr zx_obj_type_t TYPE = ZX_OBJ_TYPE_VCPU;
18 
19     constexpr vcpu() = default;
20 
vcpu(zx_handle_t value)21     explicit vcpu(zx_handle_t value) : object(value) {}
22 
vcpu(handle && h)23     explicit vcpu(handle&& h) : object(h.release()) {}
24 
vcpu(vcpu && other)25     vcpu(vcpu&& other) : object(other.release()) {}
26 
27     vcpu& operator=(vcpu&& other) {
28         reset(other.release());
29         return *this;
30     }
31 
32     static zx_status_t create(const guest& guest, uint32_t options,
33                               zx_gpaddr_t entry, vcpu* result);
34 
resume(zx_port_packet_t * packet)35     zx_status_t resume(zx_port_packet_t* packet) const {
36         return zx_vcpu_resume(get(), packet);
37     }
38 
interrupt(uint32_t interrupt)39     zx_status_t interrupt(uint32_t interrupt) const {
40         return zx_vcpu_interrupt(get(), interrupt);
41     }
42 
read_state(uint32_t kind,void * buf,size_t len)43     zx_status_t read_state(uint32_t kind, void* buf, size_t len) const {
44         return zx_vcpu_read_state(get(), kind, buf, len);
45     }
46 
write_state(uint32_t kind,const void * buf,size_t len)47     zx_status_t write_state(uint32_t kind, const void* buf, size_t len) const {
48         return zx_vcpu_write_state(get(), kind, buf, len);
49     }
50 };
51 
52 using unowned_vcpu = unowned<vcpu>;
53 
54 } // namespace zx
55 
56 #endif  // LIB_ZX_VCPU_H_
57