vmm: Restrict the maximum number of HW breakpoints

Set the maximum number of HW breakpoints according to the value returned
from `Hypervisor::get_guest_debug_hw_bps()`.

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao
2022-08-23 12:00:37 +08:00
committed by Sebastien Boeuf
parent 223b1f6c51
commit d66d64c325
3 changed files with 19 additions and 12 deletions
+8 -4
View File
@@ -133,12 +133,13 @@ impl GdbStub {
gdb_sender: mpsc::Sender<GdbRequest>,
gdb_event: vmm_sys_util::eventfd::EventFd,
vm_event: vmm_sys_util::eventfd::EventFd,
hw_breakpoints: usize,
) -> Self {
Self {
gdb_sender,
gdb_event,
vm_event,
hw_breakpoints: Default::default(),
hw_breakpoints: Vec::with_capacity(hw_breakpoints),
single_step: false,
}
}
@@ -383,9 +384,12 @@ impl HwBreakpoint for GdbStub {
addr: <Self::Arch as Arch>::Usize,
_kind: <Self::Arch as Arch>::BreakpointKind,
) -> TargetResult<bool, Self> {
// If we already have 4 breakpoints, we cannot set a new one.
if self.hw_breakpoints.len() >= 4 {
error!("Not allowed to set more than 4 HW breakpoints");
// If the HW breakpoints reach the limit, no more can be added.
if self.hw_breakpoints.len() >= self.hw_breakpoints.capacity() {
error!(
"Not allowed to set more than {} HW breakpoints",
self.hw_breakpoints.capacity()
);
return Ok(false);
}