Add copy_file_range(2) syscall stub to bionic.

Test: treehugger
Bug: https://buganizer.corp.google.com/issues/227784687
Change-Id: I543306cd2234189401bf7c9d80d405eeb6e4d41d
This commit is contained in:
zijunzhao 2022-04-22 18:08:09 +00:00 committed by Zijun Zhao
parent bcd8f15e27
commit c2e412e086
4 changed files with 29 additions and 0 deletions

View file

@ -108,6 +108,7 @@ ssize_t __pwritev64v2:pwritev2(int, const struct iovec*, int, long, long, in
int __close:close(int) all
int close_range(unsigned int, unsigned int, int) all
ssize_t copy_file_range(int, off64_t*, int, off64_t*, size_t, unsigned int) all
pid_t __getpid:getpid() all
int memfd_create(const char*, unsigned) all
int munmap(void*, size_t) all

View file

@ -313,6 +313,17 @@ int tcsetpgrp(int __fd, pid_t __pid);
int getdomainname(char* __buf, size_t __buf_size) __INTRODUCED_IN(26);
int setdomainname(const char* __name, size_t __n) __INTRODUCED_IN(26);
/**
* [copy_file_range(2)](https://man7.org/linux/man-pages/man2/copy_file_range.2.html) copies
* a range of data from one file descriptor to another.
*
* Returns the number of bytes copied on success, and returns -1 and sets errno
* on failure.
*
* Available since API level 34.
*/
ssize_t copy_file_range(int __fd_in, off64_t* __off_in, int __fd_out, off64_t* __off_out, size_t __length, unsigned int __flags) __INTRODUCED_IN(34);
#if __ANDROID_API__ >= 28
void swab(const void* __src, void* __dst, ssize_t __byte_count) __INTRODUCED_IN(28);
#endif

View file

@ -1579,6 +1579,7 @@ LIBC_T { # introduced=Tiramisu
LIBC_U { # introduced=UpsideDownCake
global:
close_range;
copy_file_range;
} LIBC_T;
LIBC_PRIVATE {

View file

@ -1668,3 +1668,19 @@ TEST(UNISTD_TEST, close_range) {
}
#endif // __GLIBC__
}
TEST(UNISTD_TEST, copy_file_range) {
#if defined(__GLIBC__)
GTEST_SKIP() << "glibc too old";
#else // __GLIBC__
TemporaryFile tf;
ASSERT_TRUE(android::base::WriteStringToFd("hello world", tf.fd));
ASSERT_EQ(0, lseek(tf.fd, SEEK_SET, 0));
TemporaryFile tf2;
ASSERT_EQ(11, copy_file_range(tf.fd, NULL, tf2.fd, NULL, 11, 0));
ASSERT_EQ(0, lseek(tf2.fd, SEEK_SET, 0));
std::string content;
ASSERT_TRUE(android::base::ReadFdToString(tf2.fd, &content));
ASSERT_EQ("hello world", content);
#endif // __GLIBC__
}