Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • redox-os/syscall
  • ids1024/syscall
  • microcolonel/syscall
  • liamnprg/syscall
  • rosehuds/syscall
  • jferard/syscall
  • xTibor/syscall
  • sergey-melnychuk/syscall
  • jD91mZM2/syscall
  • NickeZ/syscall
  • ayf/syscall
  • potatogim/syscall
  • 4lDO2/syscall
  • joboet1/syscall
  • tcrawford/syscall
  • henritel/syscall
  • ansg191/syscall
  • saraelsa/syscall
  • Forest0923/syscall
  • rw_van/syscall
  • devnexen/syscall
  • daxpedda/syscall
  • usapmz/syscall
  • gmacd/syscall
  • aaronjanse/syscall
  • jmaine/syscall
  • hasheddan/syscall
  • lygstate/syscall
  • 8tab/syscall
  • coolreader18/syscall
  • poly000/syscall
  • ahmedmasud/syscall
  • enygmator/syscall
  • kamirr/syscall
  • ebalalic/syscall
  • andypython/syscall
36 results
Show changes
Commits on Source (5)
......@@ -190,6 +190,7 @@ bitflags! {
const PTRACE_STOP_SIGNAL = 0x0000_0000_0000_0008;
const PTRACE_STOP_BREAKPOINT = 0x0000_0000_0000_0010;
const PTRACE_STOP_EXIT = 0x0000_0000_0000_0020;
const PTRACE_STOP_EXEC = 0x0000_0000_0000_0040;
const PTRACE_STOP_MASK = 0x0000_0000_0000_00FF;
const PTRACE_EVENT_CLONE = 0x0000_0000_0000_0100;
......
......@@ -2,8 +2,10 @@ pub use self::scheme::Scheme;
pub use self::scheme_mut::SchemeMut;
pub use self::scheme_block::SchemeBlock;
pub use self::scheme_block_mut::SchemeBlockMut;
pub use self::seek::*;
mod scheme;
mod scheme_mut;
mod scheme_block;
mod scheme_block_mut;
mod seek;
......@@ -16,7 +16,7 @@ pub trait Scheme {
SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
SYS_LSEEK => self.seek(packet.b, packet.c as isize, packet.d).map(|o| o as usize),
SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
......@@ -92,7 +92,7 @@ pub trait Scheme {
}
#[allow(unused_variables)]
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
fn seek(&self, id: usize, pos: isize, whence: usize) -> Result<isize> {
Err(Error::new(EBADF))
}
......
use core::cmp;
use core::convert::TryFrom;
use crate::error::*;
use crate::flag::*;
/// Helper for seek calls
/// In most cases it's easier to use a usize to track the offset and buffer size internally,
/// but the seek interface uses isize. This wrapper ensures EOVERFLOW errors are returned
/// as appropriate if the value in the usize can't fit in the isize.
pub fn calc_seek_offset_usize(cur_offset: usize, pos: isize, whence: usize, buf_len: usize) -> Result<isize> {
let cur_offset = isize::try_from(cur_offset).or_else(|_| Err(Error::new(EOVERFLOW)))?;
let buf_len = isize::try_from(buf_len).or_else(|_| Err(Error::new(EOVERFLOW)))?;
calc_seek_offset_isize(cur_offset, pos, whence, buf_len)
}
/// Helper for seek calls
/// Result is guaranteed to be positive.
/// EOVERFLOW returned if the arguments would cause an overflow.
/// EINVAL returned if the new offset is out of bounds.
pub fn calc_seek_offset_isize(cur_offset: isize, pos: isize, whence: usize, buf_len: isize) -> Result<isize> {
let new_offset = match whence {
SEEK_CUR => pos.checked_add(cur_offset),
SEEK_END => pos.checked_add(buf_len),
SEEK_SET => Some(pos),
_ => None,
};
match new_offset {
Some(new_offset) if new_offset < 0 => Err(Error::new(EINVAL)),
Some(new_offset) => Ok(cmp::min(new_offset, buf_len)),
None => Err(Error::new(EOVERFLOW))
}
}
\ No newline at end of file