Index: base/memory/discardable_memory_android.cc |
diff --git a/base/memory/discardable_memory_android.cc b/base/memory/discardable_memory_android.cc |
index 7b1731a0f63c21df0bd4ec6580c714fb9053e332..fa89c189db7be5170ecf30ea3a2a882c24fc87db 100644 |
--- a/base/memory/discardable_memory_android.cc |
+++ b/base/memory/discardable_memory_android.cc |
@@ -2,23 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/memory/discardable_memory_android.h" |
- |
-#include <sys/mman.h> |
-#include <unistd.h> |
- |
-#include <limits> |
+#include "base/memory/discardable_memory.h" |
#include "base/android/sys_utils.h" |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
-#include "base/file_util.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/memory/discardable_memory_allocator_android.h" |
#include "base/memory/discardable_memory_emulated.h" |
#include "base/memory/discardable_memory_malloc.h" |
-#include "third_party/ashmem/ashmem.h" |
namespace base { |
namespace { |
@@ -47,71 +40,6 @@ LazyInstance<DiscardableMemoryAllocatorWrapper>::Leaky g_context = |
} // namespace |
-namespace internal { |
- |
-bool CreateAshmemRegion(const char* name, |
- size_t size, |
- int* out_fd, |
- void** out_address) { |
- int fd = ashmem_create_region(name, size); |
- if (fd < 0) { |
- DLOG(ERROR) << "ashmem_create_region() failed"; |
- return false; |
- } |
- file_util::ScopedFD fd_closer(&fd); |
- |
- const int err = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); |
- if (err < 0) { |
- DLOG(ERROR) << "Error " << err << " when setting protection of ashmem"; |
- return false; |
- } |
- |
- // There is a problem using MAP_PRIVATE here. As we are constantly calling |
- // Lock() and Unlock(), data could get lost if they are not written to the |
- // underlying file when Unlock() gets called. |
- void* const address = mmap( |
- NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
- if (address == MAP_FAILED) { |
- DPLOG(ERROR) << "Failed to map memory."; |
- return false; |
- } |
- |
- ignore_result(fd_closer.release()); |
- *out_fd = fd; |
- *out_address = address; |
- return true; |
-} |
- |
-bool CloseAshmemRegion(int fd, size_t size, void* address) { |
- if (munmap(address, size) == -1) { |
- DPLOG(ERROR) << "Failed to unmap memory."; |
- close(fd); |
- return false; |
- } |
- return close(fd) == 0; |
-} |
- |
-DiscardableMemoryLockStatus LockAshmemRegion(int fd, |
- size_t off, |
- size_t size, |
- const void* address) { |
- const int result = ashmem_pin_region(fd, off, size); |
- DCHECK_EQ(0, mprotect(address, size, PROT_READ | PROT_WRITE)); |
- return result == ASHMEM_WAS_PURGED ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED |
- : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS; |
-} |
- |
-bool UnlockAshmemRegion(int fd, size_t off, size_t size, const void* address) { |
- const int failed = ashmem_unpin_region(fd, off, size); |
- if (failed) |
- DLOG(ERROR) << "Failed to unpin memory."; |
- // This allows us to catch accesses to unlocked memory. |
- DCHECK_EQ(0, mprotect(address, size, PROT_NONE)); |
- return !failed; |
-} |
- |
-} // namespace internal |
- |
// static |
void DiscardableMemory::RegisterMemoryPressureListeners() { |
internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); |