From 25ac753f474492ffa3625ca6b5aae254bb205c33 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 10 Jun 2015 17:24:20 -0700 Subject: [PATCH] Add process_vm_readv and process_vm_writev. Bug: http://b/21761353 Change-Id: Ic8ef3f241d62d2a4271fbc783c8af50257bac498 (cherry picked from commit be57a40d2973739c4fb0aa1cfb0014f34aeec2bd) --- libc/SYSCALLS.TXT | 3 ++ libc/arch-arm/syscalls/process_vm_readv.S | 22 +++++++++ libc/arch-arm/syscalls/process_vm_writev.S | 22 +++++++++ libc/arch-arm64/syscalls/process_vm_readv.S | 14 ++++++ libc/arch-arm64/syscalls/process_vm_writev.S | 14 ++++++ libc/arch-mips/syscalls/process_vm_readv.S | 19 ++++++++ libc/arch-mips/syscalls/process_vm_writev.S | 19 ++++++++ libc/arch-mips64/syscalls/process_vm_readv.S | 25 ++++++++++ libc/arch-mips64/syscalls/process_vm_writev.S | 25 ++++++++++ libc/arch-x86/syscalls/process_vm_readv.S | 46 +++++++++++++++++++ libc/arch-x86/syscalls/process_vm_writev.S | 46 +++++++++++++++++++ libc/arch-x86_64/syscalls/process_vm_readv.S | 16 +++++++ libc/arch-x86_64/syscalls/process_vm_writev.S | 16 +++++++ libc/include/sys/uio.h | 9 +++- tests/Android.mk | 1 + tests/sys_uio_test.cpp | 27 +++++++++++ 16 files changed, 322 insertions(+), 2 deletions(-) create mode 100644 libc/arch-arm/syscalls/process_vm_readv.S create mode 100644 libc/arch-arm/syscalls/process_vm_writev.S create mode 100644 libc/arch-arm64/syscalls/process_vm_readv.S create mode 100644 libc/arch-arm64/syscalls/process_vm_writev.S create mode 100644 libc/arch-mips/syscalls/process_vm_readv.S create mode 100644 libc/arch-mips/syscalls/process_vm_writev.S create mode 100644 libc/arch-mips64/syscalls/process_vm_readv.S create mode 100644 libc/arch-mips64/syscalls/process_vm_writev.S create mode 100644 libc/arch-x86/syscalls/process_vm_readv.S create mode 100644 libc/arch-x86/syscalls/process_vm_writev.S create mode 100644 libc/arch-x86_64/syscalls/process_vm_readv.S create mode 100644 libc/arch-x86_64/syscalls/process_vm_writev.S create mode 100644 tests/sys_uio_test.cpp diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 4890b89a2..ffab9f6b4 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -308,6 +308,9 @@ int inotify_rm_watch(int, unsigned int) all int __pselect6:pselect6(int, fd_set*, fd_set*, fd_set*, timespec*, void*) all int __ppoll:ppoll(pollfd*, unsigned int, timespec*, const sigset_t*, size_t) all +ssize_t process_vm_readv(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long) all +ssize_t process_vm_writev(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long) all + int __set_tid_address:set_tid_address(int*) all int setfsgid(gid_t) all diff --git a/libc/arch-arm/syscalls/process_vm_readv.S b/libc/arch-arm/syscalls/process_vm_readv.S new file mode 100644 index 000000000..48c49dc9e --- /dev/null +++ b/libc/arch-arm/syscalls/process_vm_readv.S @@ -0,0 +1,22 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_readv) + mov ip, sp + stmfd sp!, {r4, r5, r6, r7} + .cfi_def_cfa_offset 16 + .cfi_rel_offset r4, 0 + .cfi_rel_offset r5, 4 + .cfi_rel_offset r6, 8 + .cfi_rel_offset r7, 12 + ldmfd ip, {r4, r5, r6} + ldr r7, =__NR_process_vm_readv + swi #0 + ldmfd sp!, {r4, r5, r6, r7} + .cfi_def_cfa_offset 0 + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno_internal +END(process_vm_readv) diff --git a/libc/arch-arm/syscalls/process_vm_writev.S b/libc/arch-arm/syscalls/process_vm_writev.S new file mode 100644 index 000000000..4c21c43fd --- /dev/null +++ b/libc/arch-arm/syscalls/process_vm_writev.S @@ -0,0 +1,22 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_writev) + mov ip, sp + stmfd sp!, {r4, r5, r6, r7} + .cfi_def_cfa_offset 16 + .cfi_rel_offset r4, 0 + .cfi_rel_offset r5, 4 + .cfi_rel_offset r6, 8 + .cfi_rel_offset r7, 12 + ldmfd ip, {r4, r5, r6} + ldr r7, =__NR_process_vm_writev + swi #0 + ldmfd sp!, {r4, r5, r6, r7} + .cfi_def_cfa_offset 0 + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno_internal +END(process_vm_writev) diff --git a/libc/arch-arm64/syscalls/process_vm_readv.S b/libc/arch-arm64/syscalls/process_vm_readv.S new file mode 100644 index 000000000..1dd113b39 --- /dev/null +++ b/libc/arch-arm64/syscalls/process_vm_readv.S @@ -0,0 +1,14 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_readv) + mov x8, __NR_process_vm_readv + svc #0 + + cmn x0, #(MAX_ERRNO + 1) + cneg x0, x0, hi + b.hi __set_errno_internal + + ret +END(process_vm_readv) diff --git a/libc/arch-arm64/syscalls/process_vm_writev.S b/libc/arch-arm64/syscalls/process_vm_writev.S new file mode 100644 index 000000000..fb29cf805 --- /dev/null +++ b/libc/arch-arm64/syscalls/process_vm_writev.S @@ -0,0 +1,14 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_writev) + mov x8, __NR_process_vm_writev + svc #0 + + cmn x0, #(MAX_ERRNO + 1) + cneg x0, x0, hi + b.hi __set_errno_internal + + ret +END(process_vm_writev) diff --git a/libc/arch-mips/syscalls/process_vm_readv.S b/libc/arch-mips/syscalls/process_vm_readv.S new file mode 100644 index 000000000..22b74f0bf --- /dev/null +++ b/libc/arch-mips/syscalls/process_vm_readv.S @@ -0,0 +1,19 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_readv) + .set noreorder + .cpload t9 + li v0, __NR_process_vm_readv + syscall + bnez a3, 1f + move a0, v0 + j ra + nop +1: + la t9,__set_errno_internal + j t9 + nop + .set reorder +END(process_vm_readv) diff --git a/libc/arch-mips/syscalls/process_vm_writev.S b/libc/arch-mips/syscalls/process_vm_writev.S new file mode 100644 index 000000000..dd1dc4b8c --- /dev/null +++ b/libc/arch-mips/syscalls/process_vm_writev.S @@ -0,0 +1,19 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_writev) + .set noreorder + .cpload t9 + li v0, __NR_process_vm_writev + syscall + bnez a3, 1f + move a0, v0 + j ra + nop +1: + la t9,__set_errno_internal + j t9 + nop + .set reorder +END(process_vm_writev) diff --git a/libc/arch-mips64/syscalls/process_vm_readv.S b/libc/arch-mips64/syscalls/process_vm_readv.S new file mode 100644 index 000000000..f3c73726d --- /dev/null +++ b/libc/arch-mips64/syscalls/process_vm_readv.S @@ -0,0 +1,25 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_readv) + .set push + .set noreorder + li v0, __NR_process_vm_readv + syscall + bnez a3, 1f + move a0, v0 + j ra + nop +1: + move t0, ra + bal 2f + nop +2: + .cpsetup ra, t1, 2b + LA t9,__set_errno_internal + .cpreturn + j t9 + move ra, t0 + .set pop +END(process_vm_readv) diff --git a/libc/arch-mips64/syscalls/process_vm_writev.S b/libc/arch-mips64/syscalls/process_vm_writev.S new file mode 100644 index 000000000..0e8140b9c --- /dev/null +++ b/libc/arch-mips64/syscalls/process_vm_writev.S @@ -0,0 +1,25 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_writev) + .set push + .set noreorder + li v0, __NR_process_vm_writev + syscall + bnez a3, 1f + move a0, v0 + j ra + nop +1: + move t0, ra + bal 2f + nop +2: + .cpsetup ra, t1, 2b + LA t9,__set_errno_internal + .cpreturn + j t9 + move ra, t0 + .set pop +END(process_vm_writev) diff --git a/libc/arch-x86/syscalls/process_vm_readv.S b/libc/arch-x86/syscalls/process_vm_readv.S new file mode 100644 index 000000000..64965f631 --- /dev/null +++ b/libc/arch-x86/syscalls/process_vm_readv.S @@ -0,0 +1,46 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_readv) + pushl %ebx + .cfi_def_cfa_offset 8 + .cfi_rel_offset ebx, 0 + pushl %ecx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset ecx, 0 + pushl %edx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset edx, 0 + pushl %esi + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset esi, 0 + pushl %edi + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset edi, 0 + pushl %ebp + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset ebp, 0 + mov 28(%esp), %ebx + mov 32(%esp), %ecx + mov 36(%esp), %edx + mov 40(%esp), %esi + mov 44(%esp), %edi + mov 48(%esp), %ebp + movl $__NR_process_vm_readv, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno_internal + addl $4, %esp +1: + popl %ebp + popl %edi + popl %esi + popl %edx + popl %ecx + popl %ebx + ret +END(process_vm_readv) diff --git a/libc/arch-x86/syscalls/process_vm_writev.S b/libc/arch-x86/syscalls/process_vm_writev.S new file mode 100644 index 000000000..555c822ab --- /dev/null +++ b/libc/arch-x86/syscalls/process_vm_writev.S @@ -0,0 +1,46 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_writev) + pushl %ebx + .cfi_def_cfa_offset 8 + .cfi_rel_offset ebx, 0 + pushl %ecx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset ecx, 0 + pushl %edx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset edx, 0 + pushl %esi + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset esi, 0 + pushl %edi + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset edi, 0 + pushl %ebp + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset ebp, 0 + mov 28(%esp), %ebx + mov 32(%esp), %ecx + mov 36(%esp), %edx + mov 40(%esp), %esi + mov 44(%esp), %edi + mov 48(%esp), %ebp + movl $__NR_process_vm_writev, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno_internal + addl $4, %esp +1: + popl %ebp + popl %edi + popl %esi + popl %edx + popl %ecx + popl %ebx + ret +END(process_vm_writev) diff --git a/libc/arch-x86_64/syscalls/process_vm_readv.S b/libc/arch-x86_64/syscalls/process_vm_readv.S new file mode 100644 index 000000000..597649e9f --- /dev/null +++ b/libc/arch-x86_64/syscalls/process_vm_readv.S @@ -0,0 +1,16 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_readv) + movq %rcx, %r10 + movl $__NR_process_vm_readv, %eax + syscall + cmpq $-MAX_ERRNO, %rax + jb 1f + negl %eax + movl %eax, %edi + call __set_errno_internal +1: + ret +END(process_vm_readv) diff --git a/libc/arch-x86_64/syscalls/process_vm_writev.S b/libc/arch-x86_64/syscalls/process_vm_writev.S new file mode 100644 index 000000000..397c007fa --- /dev/null +++ b/libc/arch-x86_64/syscalls/process_vm_writev.S @@ -0,0 +1,16 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(process_vm_writev) + movq %rcx, %r10 + movl $__NR_process_vm_writev, %eax + syscall + cmpq $-MAX_ERRNO, %rax + jb 1f + negl %eax + movl %eax, %edi + call __set_errno_internal +1: + ret +END(process_vm_writev) diff --git a/libc/include/sys/uio.h b/libc/include/sys/uio.h index 025171638..187ec22a4 100644 --- a/libc/include/sys/uio.h +++ b/libc/include/sys/uio.h @@ -34,8 +34,13 @@ __BEGIN_DECLS -int readv(int, const struct iovec *, int); -int writev(int, const struct iovec *, int); +int readv(int, const struct iovec*, int); +int writev(int, const struct iovec*, int); + +#if defined(__USE_GNU) +ssize_t process_vm_readv(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long); +ssize_t process_vm_writev(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long); +#endif __END_DECLS diff --git a/tests/Android.mk b/tests/Android.mk index 37f7b4f43..29e9e1ef6 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -106,6 +106,7 @@ libBionicStandardTests_src_files := \ sys_sysinfo_test.cpp \ sys_time_test.cpp \ sys_types_test.cpp \ + sys_uio_test.cpp \ sys_vfs_test.cpp \ sys_xattr_test.cpp \ system_properties_test.cpp \ diff --git a/tests/sys_uio_test.cpp b/tests/sys_uio_test.cpp new file mode 100644 index 000000000..c7af8a77c --- /dev/null +++ b/tests/sys_uio_test.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +TEST(sys_uio, process_vm_readv_ESRCH) { + ASSERT_EQ(0, process_vm_readv(0, nullptr, 0, nullptr, 0, 0)); +} + +TEST(sys_uio, process_vm_writev_ESRCH) { + ASSERT_EQ(0, process_vm_writev(0, nullptr, 0, nullptr, 0, 0)); +}