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

process_vm_readv, process_vm_writev should be available on android #1878

Merged
merged 3 commits into from
Oct 16, 2020

Conversation

rupansh
Copy link
Contributor

@rupansh rupansh commented Aug 25, 2020

process_vm_readv and process_vm_writev generally return -EPERM(-1) when used in android, however the syscalls work fine when running under privileged shell.
The following was tested(with modified nix) on Android 9/10 running Linux Kernel 4.9 on a SDM 845 phone:

fn read_mem_real(pid: i32, addr: usize, vsize: usize) -> Result<Vec<u8>, String> {
    let mut res = vec![0; vsize];
    let riovec: [RemoteIoVec; 1] = [RemoteIoVec {base: addr, len: vsize}];

    match process_vm_readv(Pid::from_raw(pid), &[IoVec::from_mut_slice(&mut res)], &riovec) {
        Err(e) => {
            log::info!("ERR {}", e);
            return Err(e.to_string());
        },
        Ok(_) => {
            return Ok(res);
        }
    }
}

This will work fine when run under su shell.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rupansh rupansh changed the title process_vm_readv, process_vm_writev, etc should be available on android process_vm_readv, process_vm_writev should be available on android Aug 25, 2020
@joshtriplett
Copy link
Member

Closing and reopening to re-run CI.

@joshtriplett joshtriplett reopened this Oct 1, 2020
@rupansh
Copy link
Contributor Author

rupansh commented Oct 3, 2020

@joshtriplett I am not sure why its failing. I used android-ndk's aarch64-linux-android27-clang

@joshtriplett
Copy link
Member

joshtriplett commented Oct 3, 2020 via email

@rupansh
Copy link
Contributor Author

rupansh commented Oct 3, 2020

On Fri, Oct 02, 2020 at 07:46:05PM -0700, Rupansh wrote: @joshtriplett I am not sure why its failing. I used android-ndk's aarch64-linux-android27-clang
Since it succeeds on other Android targets, and fails on aarch64, is it possible that the Android SDK for aarch64 doesn't have that syscall in its headers yet?

sysroot/usr/include/sys/uio.h has it in my case for android27. It was added in a later version. android21(Lollipop, the TC used by CI) is pretty old now!
Edit: it was added with android23
sysroot/usr/include/sys/uio.h

#if __ANDROID_API__ >= 23
ssize_t process_vm_readv(pid_t __pid, const struct iovec* __local_iov, unsigned long __local_iov_count, const struct iovec* __remote_iov, unsigned long __remote_iov_count, unsigned long __flags) __INTRODUCED_IN(23)
ssize_t process_vm_writev(pid_t __pid, const struct iovec* __local_iov, unsigned long __local_iov_count, const struct iovec* __remote_iov, unsigned long __remote_iov_count, unsigned long __flags) __INTRODUCED_IN(23)
#endif /* __ANDROID_API__ >= 23 */

Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/unix/linux_like/android/mod.rs Outdated Show resolved Hide resolved
src/unix/linux_like/android/mod.rs Outdated Show resolved Hide resolved
@JohnTitor
Copy link
Member

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Oct 16, 2020

📌 Commit 0121c5c has been approved by JohnTitor

@bors
Copy link
Contributor

bors commented Oct 16, 2020

⌛ Testing commit 0121c5c with merge 2d044d9...

@bors
Copy link
Contributor

bors commented Oct 16, 2020

☀️ Test successful - checks-actions, checks-cirrus-freebsd-10, checks-cirrus-freebsd-11, checks-cirrus-freebsd-12
Approved by: JohnTitor
Pushing 2d044d9 to master...

@bors bors merged commit 2d044d9 into rust-lang:master Oct 16, 2020
bors bot added a commit to nix-rust/nix that referenced this pull request Feb 3, 2022
1557: expose process_vm_readv, process_vm_writev for android r=rtzoeller a=rupansh

see rust-lang/libc#1878

Co-authored-by: rupansh-arch <rupanshsekar@hotmail.com>
bors bot added a commit to nix-rust/nix that referenced this pull request Feb 3, 2022
1557: expose process_vm_readv, process_vm_writev for android r=rtzoeller a=rupansh

see rust-lang/libc#1878

Co-authored-by: rupansh-arch <rupanshsekar@hotmail.com>
bors bot added a commit to nix-rust/nix that referenced this pull request Feb 7, 2022
1557: expose process_vm_readv, process_vm_writev for android r=rtzoeller a=rupansh

see rust-lang/libc#1878

Co-authored-by: rupansh-arch <rupanshsekar@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants