Skip to content

Commit

Permalink
Add process_vm_readv and process_vm_writev
Browse files Browse the repository at this point in the history
  • Loading branch information
geofft committed Apr 3, 2017
1 parent c086d23 commit b564344
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/sys/uio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(improper_ctypes)]

use {Errno, Result};
use libc::{self, c_int, c_void, size_t, off_t};
use libc::{self, c_int, c_ulong, c_void, size_t, off_t};
use std::marker::PhantomData;
use std::os::unix::io::RawFd;

Expand Down Expand Up @@ -56,6 +56,24 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
Errno::result(res).map(|r| r as usize)
}

pub fn process_vm_writev(pid: libc::pid_t, local_iov: &[IoVec<&[u8]>], remote_iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
let res = unsafe {
libc::process_vm_writev(pid, local_iov.as_ptr() as *const libc::iovec, local_iov.len() as c_ulong,
remote_iov.as_ptr() as *const libc::iovec, remote_iov.len() as c_ulong, 0)
};

Errno::result(res).map(|r| r as usize)
}

pub fn process_vm_readv(pid: libc::pid_t, local_iov: &mut [IoVec<&mut [u8]>], remote_iov: &[IoVec<&[u8]>]) -> Result<usize> {
let res = unsafe {
libc::process_vm_readv(pid, local_iov.as_ptr() as *const libc::iovec, local_iov.len() as c_ulong,
remote_iov.as_ptr() as *const libc::iovec, remote_iov.len() as c_ulong, 0)
};

Errno::result(res).map(|r| r as usize)
}

#[repr(C)]
pub struct IoVec<T>(libc::iovec, PhantomData<T>);

Expand Down

0 comments on commit b564344

Please sign in to comment.