Skip to content

Commit

Permalink
kernel: gdb: don't panic when accessing kernel memory
Browse files Browse the repository at this point in the history
Instead, just return 0x00000000.

Signed-off-by: Sean Cross <[email protected]>
  • Loading branch information
xobs committed Dec 22, 2023
1 parent 9c2523d commit 0673ad9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions kernel/src/debug/gdb/multi_thread_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ impl MultiThreadBase for XousTarget {
regs: &gdbstub_arch::riscv::reg::RiscvCoreRegs<u32>,
tid: Tid,
) -> TargetResult<(), Self> {
let Some(pid) = self.pid else {
return Ok(())
};
let Some(pid) = self.pid else { return Ok(()) };

crate::services::SystemServices::with(|system_services| {
let current_pid = system_services.current_pid();
Expand Down Expand Up @@ -92,8 +90,19 @@ impl MultiThreadBase for XousTarget {
_tid: Tid, // same address space for each core
) -> TargetResult<(), Self> {
let current_addr = start_addr as usize;
if (current_addr + data.len()) >= crate::arch::mem::USER_AREA_END
|| (current_addr >= crate::arch::mem::USER_AREA_END)
{
for entry in data.iter_mut() {
*entry = 0
}
return Ok(()); // don't allow reads outside of the user area
}

let Some(pid) = self.pid else {
for entry in data.iter_mut() { *entry = 0 };
for entry in data.iter_mut() {
*entry = 0
}
return Ok(());
};

Expand Down Expand Up @@ -153,11 +162,16 @@ impl MultiThreadBase for XousTarget {
data: &[u8],
_tid: Tid, // all threads share the same process memory space
) -> TargetResult<(), Self> {
let mut current_addr = start_addr;
let mut current_addr = start_addr as usize;
let Some(pid) = self.pid else {
println!("Couldn't poke memory: no current process!");
return Ok(());
};

if (current_addr + data.len()) > crate::arch::mem::USER_AREA_END {
return Ok(()); // don't allow reads outside of the user area
}

crate::services::SystemServices::with(|system_services| {
let current_pid = system_services.current_pid();

Expand Down

0 comments on commit 0673ad9

Please sign in to comment.