Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass PacketBuf as an argument of API #72

Merged
merged 7 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/armv4t/gdb/host_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ impl target::ext::host_io::HostIoReadlink for Emu {
.to_str()
.ok_or(HostIoError::Errno(HostIoErrno::ENOENT))?
.as_bytes();
Ok(copy_range_to_buf(data, 0, data.len(), buf))
if data.len() <= buf.len() {
bet4it marked this conversation as resolved.
Show resolved Hide resolved
Ok(copy_range_to_buf(data, 0, data.len(), buf))
} else {
Err(HostIoError::Errno(HostIoErrno::ENAMETOOLONG))
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions examples/armv4t/gdb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::convert::TryInto;
use core::convert::{TryFrom, TryInto};

use armv4t_emu::{reg, Memory};
use gdbstub::target;
Expand Down Expand Up @@ -37,12 +37,16 @@ fn cpu_reg_id(id: ArmCoreRegId) -> Option<u8> {
}

/// Copy a range of `data` (start at `offset` with a size of `length`) to `buf`.
/// Return the size of data copied. Return 0 if encounter EOF.
/// Return the size of data copied. Returns 0 if `offset >= buf.len()`.
///
/// Mainly used by qXfer:_object_:read commands.
pub fn copy_range_to_buf(data: &[u8], offset: u64, length: usize, buf: &mut [u8]) -> usize {
bet4it marked this conversation as resolved.
Show resolved Hide resolved
let offset = match usize::try_from(offset) {
Ok(v) => v,
Err(_) => return 0,
};
let len = data.len();
let data = &data[len.min(offset as usize)..len.min(offset as usize + length)];
let data = &data[len.min(offset)..len.min(offset + length)];
let buf = &mut buf[..data.len()];
buf.copy_from_slice(data);
data.len()
Expand Down