OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/discardable_memory_android.h" | 5 #include "base/memory/discardable_memory_android.h" |
6 | 6 |
7 #include <sys/mman.h> | 7 #include <sys/mman.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // Total number of discardable memory in the process. | 26 // Total number of discardable memory in the process. |
27 int g_num_discardable_memory = 0; | 27 int g_num_discardable_memory = 0; |
28 | 28 |
29 // Upper limit on the number of discardable memory to avoid hitting file | 29 // Upper limit on the number of discardable memory to avoid hitting file |
30 // descriptor limit. | 30 // descriptor limit. |
31 const int kDiscardableMemoryNumLimit = 128; | 31 const int kDiscardableMemoryNumLimit = 128; |
32 | 32 |
33 class DiscardableMemoryAndroid : public DiscardableMemory { | 33 class DiscardableMemoryAndroid : public DiscardableMemory { |
34 public: | 34 public: |
35 DiscardableMemoryAndroid(int fd, void* address, size_t size) | 35 DiscardableMemoryAndroid(int fd, void* address, size_t size) |
36 : fd_(fd), | 36 : DiscardableMemory(size), |
| 37 fd_(fd), |
37 memory_(address), | 38 memory_(address), |
38 size_(size) { | 39 size_(size) { |
39 DCHECK_GE(fd_, 0); | 40 DCHECK_GE(fd_, 0); |
40 DCHECK(memory_); | 41 DCHECK(memory_); |
41 } | 42 } |
42 | 43 |
43 virtual ~DiscardableMemoryAndroid() { | 44 virtual ~DiscardableMemoryAndroid() { |
44 internal::DeleteAshmemRegion(fd_, size_, memory_); | 45 internal::DeleteAshmemRegion(fd_, size_, memory_); |
45 } | 46 } |
46 | 47 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 DLOG(ERROR) << "Failed to unpin memory."; | 162 DLOG(ERROR) << "Failed to unpin memory."; |
162 #if !defined(NDEBUG) | 163 #if !defined(NDEBUG) |
163 // This allows us to catch accesses to unlocked memory. | 164 // This allows us to catch accesses to unlocked memory. |
164 DCHECK_EQ(0, mprotect(address, size, PROT_NONE)); | 165 DCHECK_EQ(0, mprotect(address, size, PROT_NONE)); |
165 #endif | 166 #endif |
166 return !failed; | 167 return !failed; |
167 } | 168 } |
168 | 169 |
169 } // namespace internal | 170 } // namespace internal |
170 } // namespace base | 171 } // namespace base |
OLD | NEW |