Skip to content

Commit c097461

Browse files
committed
Fix construction
1 parent 1dfdad1 commit c097461

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

vm/hv1/hv1_emulator/src/synic.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,17 @@ struct SharedProcessorState {
9393
sint: [hvdef::HvSynicSint; NUM_SINTS],
9494
}
9595

96-
impl Default for SharedProcessorState {
97-
fn default() -> Self {
96+
impl SharedProcessorState {
97+
fn new() -> Self {
98+
Self {
99+
online: false,
100+
enabled: false,
101+
siefp_page: OverlayPage::default(),
102+
sint: [hvdef::HvSynicSint::new(); NUM_SINTS],
103+
}
104+
}
105+
106+
fn at_reset() -> Self {
98107
Self {
99108
online: true,
100109
enabled: true,
@@ -201,7 +210,9 @@ impl GlobalSynic {
201210
/// Returns a new instance of the synthetic interrupt controller.
202211
pub fn new(guest_memory: GuestMemory, max_vp_count: u32) -> Self {
203212
Self {
204-
vps: (0..max_vp_count).map(|_| Default::default()).collect(),
213+
vps: (0..max_vp_count)
214+
.map(|_| Arc::new(RwLock::new(SharedProcessorState::new())))
215+
.collect(),
205216
guest_memory,
206217
}
207218
}
@@ -259,7 +270,7 @@ impl GlobalSynic {
259270
/// Adds a virtual processor to the synthetic interrupt controller state.
260271
pub fn add_vp(&self, vp_index: VpIndex) -> ProcessorSynic {
261272
let shared = self.vps[vp_index.index() as usize].clone();
262-
let old_shared = std::mem::take(&mut *shared.write());
273+
let old_shared = std::mem::replace(&mut *shared.write(), SharedProcessorState::at_reset());
263274
assert!(!old_shared.online);
264275

265276
ProcessorSynic {
@@ -284,7 +295,7 @@ impl ProcessorSynic {
284295
} = self;
285296
*sints = SintState::default();
286297
*timers = array::from_fn(|_| Timer::default());
287-
*shared.write() = SharedProcessorState::default();
298+
*shared.write() = SharedProcessorState::at_reset();
288299
*vina = HvRegisterVsmVina::new();
289300
}
290301

0 commit comments

Comments
 (0)