Skip to content

Commit b564344

Browse files
committed
Add process_vm_readv and process_vm_writev
1 parent c086d23 commit b564344

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/sys/uio.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(improper_ctypes)]
33

44
use {Errno, Result};
5-
use libc::{self, c_int, c_void, size_t, off_t};
5+
use libc::{self, c_int, c_ulong, c_void, size_t, off_t};
66
use std::marker::PhantomData;
77
use std::os::unix::io::RawFd;
88

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

59+
pub fn process_vm_writev(pid: libc::pid_t, local_iov: &[IoVec<&[u8]>], remote_iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
60+
let res = unsafe {
61+
libc::process_vm_writev(pid, local_iov.as_ptr() as *const libc::iovec, local_iov.len() as c_ulong,
62+
remote_iov.as_ptr() as *const libc::iovec, remote_iov.len() as c_ulong, 0)
63+
};
64+
65+
Errno::result(res).map(|r| r as usize)
66+
}
67+
68+
pub fn process_vm_readv(pid: libc::pid_t, local_iov: &mut [IoVec<&mut [u8]>], remote_iov: &[IoVec<&[u8]>]) -> Result<usize> {
69+
let res = unsafe {
70+
libc::process_vm_readv(pid, local_iov.as_ptr() as *const libc::iovec, local_iov.len() as c_ulong,
71+
remote_iov.as_ptr() as *const libc::iovec, remote_iov.len() as c_ulong, 0)
72+
};
73+
74+
Errno::result(res).map(|r| r as usize)
75+
}
76+
5977
#[repr(C)]
6078
pub struct IoVec<T>(libc::iovec, PhantomData<T>);
6179

0 commit comments

Comments
 (0)