5
5
// Use of this source code is governed by a BSD-style license that can be
6
6
// found in the THIRD-PARTY file.
7
7
8
+ use std:: mem:: offset_of;
9
+
8
10
use kvm_bindings:: * ;
9
11
use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
10
12
@@ -19,28 +21,9 @@ const PSR_D_BIT: u64 = 0x0000_0200;
19
21
/// Taken from arch/arm64/kvm/inject_fault.c.
20
22
pub const PSTATE_FAULT_BITS_64 : u64 = PSR_MODE_EL1h | PSR_A_BIT | PSR_F_BIT | PSR_I_BIT | PSR_D_BIT ;
21
23
22
- // Following are macros that help with getting the ID of a aarch64 core register.
23
- // The core register are represented by the user_pt_regs structure. Look for it in
24
- // arch/arm64/include/uapi/asm/ptrace.h.
25
-
26
- /// Gets offset of a member (`field`) within a struct (`container`).
27
- /// Same as bindgen offset tests.
28
- macro_rules! offset__of {
29
- ( $container: ty, $field: ident) => {
30
- // SAFETY: The implementation closely matches that of the memoffset crate,
31
- // which have been under extensive review.
32
- unsafe {
33
- let uninit = std:: mem:: MaybeUninit :: <$container>:: uninit( ) ;
34
- let ptr = uninit. as_ptr( ) ;
35
- std:: ptr:: addr_of!( ( * ptr) . $field) as usize - ptr as usize
36
- }
37
- } ;
38
- }
39
- pub ( crate ) use offset__of;
40
-
41
24
/// Gets a core id.
42
25
macro_rules! arm64_core_reg_id {
43
- ( $size: tt , $offset: tt ) => {
26
+ ( $size: ident , $offset: expr ) => {
44
27
// The core registers of an arm64 machine are represented
45
28
// in kernel by the `kvm_regs` structure. This structure is a
46
29
// mix of 32, 64 and 128 bit fields:
@@ -130,15 +113,11 @@ pub const KVM_REG_ARM64_SVE_VLS: u64 =
130
113
///
131
114
/// https://github.com/torvalds/linux/blob/master/Documentation/virt/kvm/api.rst#L2578
132
115
/// > 0x6030 0000 0010 0040 PC 64 regs.pc
133
- pub const PC : u64 = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , 0x100 ) ;
134
-
135
- // TODO: Once `core::mem::offset_of!()` macro becomes stable (maybe since 1.77.0?), use the
136
- // following instead: https://github.com/firecracker-microvm/firecracker/issues/4504
137
- // pub const PC: u64 = {
138
- // let kreg_off = offset_of!(kvm_regs, regs);
139
- // let pc_off = offset_of!(user_pt_regs, pc);
140
- // arm64_core_reg_id!(KVM_REG_SIZE_U64, kreg_off + pc_off)
141
- // };
116
+ pub const PC : u64 = {
117
+ let kreg_off = offset_of ! ( kvm_regs, regs) ;
118
+ let pc_off = offset_of ! ( user_pt_regs, pc) ;
119
+ arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , kreg_off + pc_off)
120
+ } ;
142
121
143
122
/// Different aarch64 registers sizes
144
123
#[ derive( Debug ) ]
0 commit comments