Add a lock before capturing coverage

This commit is contained in:
Zhang Junyang 2025-11-20 11:13:10 +08:00 committed by Tate, Hongliang Tian
parent 7876b7127d
commit 8096249765
1 changed files with 6 additions and 0 deletions

View File

@ -8,9 +8,15 @@
use alloc::vec::Vec;
use core::mem::ManuallyDrop;
use crate::sync::SpinLock;
/// A hook to be invoked on QEMU exit for dumping the code coverage data.
pub(crate) fn on_qemu_exit() {
let mut coverage = ManuallyDrop::new(Vec::new());
static COV_LOCK: SpinLock<()> = SpinLock::new(());
let _guard = COV_LOCK.disable_irq().lock();
// SAFETY: The above lock ensures that this function is not called
// concurrently by multiple threads.
unsafe {
minicov::capture_coverage(&mut *coverage).unwrap();
}