summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2023-08-23 16:55:33 +0200
committer VladimĂ­r Marko <vmarko@google.com> 2023-08-24 16:11:20 +0000
commit3b276d243809b14b6986f528ae498d3ebc758f3f (patch)
tree265a6a0aabe2c4c81d13898e6f3ef0623423b0f4
parent6863692a0e4ebde79b2c7d03478cb7b5e27ba5fc (diff)
Remove `SafeCopy`.
This code is unused since https://android-review.googlesource.com/2318778 . Test: buildbot-build.sh --target Bug: 296577614 Bug: 38383823 Change-Id: I4db5f12add98a59f138ebc586a4806d218601822
-rw-r--r--libartbase/Android.bp2
-rw-r--r--libartbase/base/safe_copy.cc83
-rw-r--r--libartbase/base/safe_copy.h31
-rw-r--r--libartbase/base/safe_copy_test.cc111
-rw-r--r--runtime/arch/x86/fault_handler_x86.cc1
-rw-r--r--runtime/fault_handler.cc1
6 files changed, 0 insertions, 229 deletions
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
index 7cd15324bb..c1bfc560f8 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -49,7 +49,6 @@ cc_defaults {
"base/metrics/metrics_common.cc",
"base/os_linux.cc",
"base/runtime_debug.cc",
- "base/safe_copy.cc",
"base/scoped_arena_allocator.cc",
"base/scoped_flock.cc",
"base/socket_peer_is_trusted.cc",
@@ -341,7 +340,6 @@ art_cc_defaults {
"base/memory_region_test.cc",
"base/mem_map_test.cc",
"base/metrics/metrics_test.cc",
- "base/safe_copy_test.cc",
"base/scoped_flock_test.cc",
"base/time_utils_test.cc",
"base/transform_array_ref_test.cc",
diff --git a/libartbase/base/safe_copy.cc b/libartbase/base/safe_copy.cc
deleted file mode 100644
index 7b0b895166..0000000000
--- a/libartbase/base/safe_copy.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2017 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 "safe_copy.h"
-
-#ifdef __linux__
-#include <sys/uio.h>
-#include <sys/user.h>
-#endif
-#include <unistd.h>
-
-#include <algorithm>
-
-#include <android-base/macros.h>
-
-#include "bit_utils.h"
-
-namespace art {
-
-ssize_t SafeCopy(void *dst, const void *src, size_t len) {
-#if defined(__linux__)
- struct iovec dst_iov = {
- .iov_base = dst,
- .iov_len = len,
- };
-
- // Split up the remote read across page boundaries.
- // From the manpage:
- // A partial read/write may result if one of the remote_iov elements points to an invalid
- // memory region in the remote process.
- //
- // Partial transfers apply at the granularity of iovec elements. These system calls won't
- // perform a partial transfer that splits a single iovec element.
- constexpr size_t kMaxIovecs = 64;
- struct iovec src_iovs[kMaxIovecs];
- size_t iovecs_used = 0;
-
- const char* cur = static_cast<const char*>(src);
- while (len > 0) {
- if (iovecs_used == kMaxIovecs) {
- errno = EINVAL;
- return -1;
- }
-
- src_iovs[iovecs_used].iov_base = const_cast<char*>(cur);
- if (!IsAlignedParam(cur, kPageSize)) {
- src_iovs[iovecs_used].iov_len = AlignUp(cur, kPageSize) - cur;
- } else {
- src_iovs[iovecs_used].iov_len = kPageSize;
- }
-
- src_iovs[iovecs_used].iov_len = std::min(src_iovs[iovecs_used].iov_len, len);
-
- len -= src_iovs[iovecs_used].iov_len;
- cur += src_iovs[iovecs_used].iov_len;
- ++iovecs_used;
- }
-
- ssize_t rc = process_vm_readv(getpid(), &dst_iov, 1, src_iovs, iovecs_used, 0);
- if (rc == -1) {
- return 0;
- }
- return rc;
-#else
- UNUSED(dst, src, len);
- return -1;
-#endif
-}
-
-} // namespace art
diff --git a/libartbase/base/safe_copy.h b/libartbase/base/safe_copy.h
deleted file mode 100644
index 56cdfecc2d..0000000000
--- a/libartbase/base/safe_copy.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#ifndef ART_LIBARTBASE_BASE_SAFE_COPY_H_
-#define ART_LIBARTBASE_BASE_SAFE_COPY_H_
-
-#include <sys/types.h>
-
-namespace art {
-
-// Safely dereference a pointer.
-// Returns -1 if safe copy isn't implemented on the platform, or if the transfer is too large.
-// Returns 0 if src is unreadable.
-ssize_t SafeCopy(void *dst, const void *src, size_t len);
-
-} // namespace art
-
-#endif // ART_LIBARTBASE_BASE_SAFE_COPY_H_
diff --git a/libartbase/base/safe_copy_test.cc b/libartbase/base/safe_copy_test.cc
deleted file mode 100644
index 01ed7cdc40..0000000000
--- a/libartbase/base/safe_copy_test.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2017 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 "safe_copy.h"
-
-#include <errno.h>
-#include <string.h>
-#include <sys/user.h>
-
-#include "android-base/logging.h"
-#include "globals.h"
-#include "gtest/gtest.h"
-#include "mman.h"
-
-
-namespace art {
-
-#if defined(__linux__)
-
-TEST(SafeCopyTest, smoke) {
- DCHECK_EQ(kPageSize, static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
-
- // Map four pages, mark the second one as PROT_NONE, unmap the last one.
- void* map = mmap(nullptr, kPageSize * 4, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- ASSERT_NE(MAP_FAILED, map);
- char* page1 = static_cast<char*>(map);
- char* page2 = page1 + kPageSize;
- char* page3 = page2 + kPageSize;
- char* page4 = page3 + kPageSize;
- ASSERT_EQ(0, mprotect(page1 + kPageSize, kPageSize, PROT_NONE));
- ASSERT_EQ(0, munmap(page4, kPageSize));
-
- page1[0] = 'a';
- page1[kPageSize - 1] = 'z';
-
- page3[0] = 'b';
- page3[kPageSize - 1] = 'y';
-
- char buf[kPageSize];
-
- // Completely valid read.
- memset(buf, 0xCC, sizeof(buf));
- EXPECT_EQ(static_cast<ssize_t>(kPageSize), SafeCopy(buf, page1, kPageSize)) << strerror(errno);
- EXPECT_EQ(0, memcmp(buf, page1, kPageSize));
-
- // Reading into a guard page.
- memset(buf, 0xCC, sizeof(buf));
- EXPECT_EQ(static_cast<ssize_t>(kPageSize - 1), SafeCopy(buf, page1 + 1, kPageSize));
- EXPECT_EQ(0, memcmp(buf, page1 + 1, kPageSize - 1));
-
- // Reading from a guard page into a real page.
- memset(buf, 0xCC, sizeof(buf));
- EXPECT_EQ(0, SafeCopy(buf, page2 + kPageSize - 1, kPageSize));
-
- // Reading off of the end of a mapping.
- memset(buf, 0xCC, sizeof(buf));
- EXPECT_EQ(static_cast<ssize_t>(kPageSize), SafeCopy(buf, page3, kPageSize * 2));
- EXPECT_EQ(0, memcmp(buf, page3, kPageSize));
-
- // Completely invalid.
- EXPECT_EQ(0, SafeCopy(buf, page1 + kPageSize, kPageSize));
-
- // Clean up.
- ASSERT_EQ(0, munmap(map, kPageSize * 3));
-}
-
-TEST(SafeCopyTest, alignment) {
- DCHECK_EQ(kPageSize, static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
-
- // Copy the middle of a mapping to the end of another one.
- void* src_map = mmap(nullptr, kPageSize * 3, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- ASSERT_NE(MAP_FAILED, src_map);
-
- // Add a guard page to make sure we don't write past the end of the mapping.
- void* dst_map = mmap(nullptr, kPageSize * 4, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- ASSERT_NE(MAP_FAILED, dst_map);
-
- char* src = static_cast<char*>(src_map);
- char* dst = static_cast<char*>(dst_map);
- ASSERT_EQ(0, mprotect(dst + 3 * kPageSize, kPageSize, PROT_NONE));
-
- src[512] = 'a';
- src[kPageSize * 3 - 512 - 1] = 'z';
-
- EXPECT_EQ(static_cast<ssize_t>(kPageSize * 3 - 1024),
- SafeCopy(dst + 1024, src + 512, kPageSize * 3 - 1024));
- EXPECT_EQ(0, memcmp(dst + 1024, src + 512, kPageSize * 3 - 1024));
-
- ASSERT_EQ(0, munmap(src_map, kPageSize * 3));
- ASSERT_EQ(0, munmap(dst_map, kPageSize * 4));
-}
-
-#endif // defined(__linux__)
-
-} // namespace art
diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc
index efc5249582..998051c0a2 100644
--- a/runtime/arch/x86/fault_handler_x86.cc
+++ b/runtime/arch/x86/fault_handler_x86.cc
@@ -24,7 +24,6 @@
#include "base/hex_dump.h"
#include "base/logging.h" // For VLOG.
#include "base/macros.h"
-#include "base/safe_copy.h"
#include "oat_quick_method_header.h"
#include "runtime_globals.h"
#include "thread-current-inl.h"
diff --git a/runtime/fault_handler.cc b/runtime/fault_handler.cc
index 75a14df32c..af311d23cf 100644
--- a/runtime/fault_handler.cc
+++ b/runtime/fault_handler.cc
@@ -25,7 +25,6 @@
#include "art_method-inl.h"
#include "base/logging.h" // For VLOG
#include "base/membarrier.h"
-#include "base/safe_copy.h"
#include "base/stl_util.h"
#include "dex/dex_file_types.h"
#include "gc/heap.h"