|
1 | 1 | // Silence invalid warnings due to rust-lang/rust#16719
|
2 | 2 | #![allow(improper_ctypes)]
|
| 3 | +// Silence warning from empty bitflags |
| 4 | +#![allow(unused_imports)] |
3 | 5 |
|
4 | 6 | use {Errno, Result};
|
| 7 | +use unistd::Pid; |
5 | 8 | use libc::{self, c_int, c_void, size_t, off_t};
|
6 | 9 | use std::marker::PhantomData;
|
7 | 10 | use std::os::unix::io::RawFd;
|
@@ -56,6 +59,39 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
|
56 | 59 | Errno::result(res).map(|r| r as usize)
|
57 | 60 | }
|
58 | 61 |
|
| 62 | +// process_vm_{read,write}v currently doesn't use flags, but we define this |
| 63 | +// type for forwards-compatibility. |
| 64 | +#[cfg(any(target_os = "linux", |
| 65 | + target_os = "android"))] |
| 66 | +bitflags!( |
| 67 | + pub struct CmaFlags: libc::c_ulong { |
| 68 | + // The bitflags! macro requires at least one variant. any() evaluates |
| 69 | + // to false, so this symbol never actually exists. |
| 70 | + #[cfg(any())] |
| 71 | + const CMA_DUMMY = 0; |
| 72 | + } |
| 73 | +); |
| 74 | + |
| 75 | +#[cfg(any(target_os = "linux", target_os = "android"))] |
| 76 | +pub fn process_vm_writev(pid: Pid, local_iov: &[IoVec<&[u8]>], remote_iov: &mut [IoVec<&mut [u8]>], flags: CmaFlags) -> Result<usize> { |
| 77 | + let res = unsafe { |
| 78 | + libc::process_vm_writev(pid.into(), local_iov.as_ptr() as *const libc::iovec, local_iov.len() as libc::c_ulong, |
| 79 | + remote_iov.as_ptr() as *const libc::iovec, remote_iov.len() as libc::c_ulong, flags.bits()) |
| 80 | + }; |
| 81 | + |
| 82 | + Errno::result(res).map(|r| r as usize) |
| 83 | +} |
| 84 | + |
| 85 | +#[cfg(any(target_os = "linux", target_os = "android"))] |
| 86 | +pub fn process_vm_readv(pid: Pid, local_iov: &mut [IoVec<&mut [u8]>], remote_iov: &[IoVec<&[u8]>], flags: CmaFlags) -> Result<usize> { |
| 87 | + let res = unsafe { |
| 88 | + libc::process_vm_readv(pid.into(), local_iov.as_ptr() as *const libc::iovec, local_iov.len() as libc::c_ulong, |
| 89 | + remote_iov.as_ptr() as *const libc::iovec, remote_iov.len() as libc::c_ulong, flags.bits()) |
| 90 | + }; |
| 91 | + |
| 92 | + Errno::result(res).map(|r| r as usize) |
| 93 | +} |
| 94 | + |
59 | 95 | #[repr(C)]
|
60 | 96 | pub struct IoVec<T>(libc::iovec, PhantomData<T>);
|
61 | 97 |
|
|
0 commit comments