Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: base/memory/discardable_memory_mac.cc

Issue 271353003: Fix iOS after r269483. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "base/memory/discardable_memory.h"
6 6
7 #include <mach/mach.h> 7 #include <mach/mach.h>
8 #include <mach/mach_vm.h> 8 #include <mach/mach_vm.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 15 matching lines...) Expand all
26 26
27 class DiscardableMemoryMac : public DiscardableMemory { 27 class DiscardableMemoryMac : public DiscardableMemory {
28 public: 28 public:
29 explicit DiscardableMemoryMac(size_t size) 29 explicit DiscardableMemoryMac(size_t size)
30 : memory_(0, 0), 30 : memory_(0, 0),
31 size_(mach_vm_round_page(size)) { 31 size_(mach_vm_round_page(size)) {
32 } 32 }
33 33
34 bool Initialize() { 34 bool Initialize() {
35 DCHECK_EQ(memory_.size(), 0u); 35 DCHECK_EQ(memory_.size(), 0u);
36 mach_vm_address_t address = 0; 36 vm_address_t address = 0;
37 kern_return_t ret = mach_vm_allocate(mach_task_self(), 37 kern_return_t ret = vm_allocate(mach_task_self(),
38 &address, 38 &address,
39 size_, 39 size_,
40 VM_FLAGS_PURGABLE | 40 VM_FLAGS_PURGABLE |
41 VM_FLAGS_ANYWHERE | 41 VM_FLAGS_ANYWHERE |
42 kDiscardableMemoryTag); 42 kDiscardableMemoryTag);
43 if (ret != KERN_SUCCESS) { 43 if (ret != KERN_SUCCESS) {
44 MACH_DLOG(ERROR, ret) << "mach_vm_allocate"; 44 MACH_DLOG(ERROR, ret) << "vm_allocate";
45 return false; 45 return false;
46 } 46 }
47 47
48 memory_.reset(address, size_); 48 memory_.reset(address, size_);
49 49
50 return true; 50 return true;
51 } 51 }
52 52
53 virtual ~DiscardableMemoryMac() { 53 virtual ~DiscardableMemoryMac() {
54 } 54 }
55 55
56 virtual DiscardableMemoryLockStatus Lock() OVERRIDE { 56 virtual DiscardableMemoryLockStatus Lock() OVERRIDE {
57 kern_return_t ret; 57 kern_return_t ret;
58 MACH_DCHECK((ret = mach_vm_protect(mach_task_self(), 58 MACH_DCHECK((ret = vm_protect(mach_task_self(),
59 memory_.address(), 59 memory_.address(),
60 memory_.size(), 60 memory_.size(),
61 FALSE, 61 FALSE,
62 VM_PROT_DEFAULT)) == KERN_SUCCESS, ret); 62 VM_PROT_DEFAULT)) == KERN_SUCCESS, ret);
63 int state = VM_PURGABLE_NONVOLATILE; 63 int state = VM_PURGABLE_NONVOLATILE;
64 ret = mach_vm_purgable_control(mach_task_self(), 64 ret = vm_purgable_control(mach_task_self(),
65 memory_.address(), 65 memory_.address(),
66 VM_PURGABLE_SET_STATE, 66 VM_PURGABLE_SET_STATE,
67 &state); 67 &state);
68 if (ret != KERN_SUCCESS) 68 if (ret != KERN_SUCCESS)
69 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; 69 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
70 70
71 return state & VM_PURGABLE_EMPTY ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED 71 return state & VM_PURGABLE_EMPTY ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
72 : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS; 72 : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
73 } 73 }
74 74
75 virtual void Unlock() OVERRIDE { 75 virtual void Unlock() OVERRIDE {
76 int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT; 76 int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT;
77 kern_return_t ret = mach_vm_purgable_control(mach_task_self(), 77 kern_return_t ret = vm_purgable_control(mach_task_self(),
78 memory_.address(), 78 memory_.address(),
79 VM_PURGABLE_SET_STATE, 79 VM_PURGABLE_SET_STATE,
80 &state); 80 &state);
81 MACH_DLOG_IF(ERROR, ret != KERN_SUCCESS, ret) << "mach_vm_purgable_control"; 81 MACH_DLOG_IF(ERROR, ret != KERN_SUCCESS, ret) << "vm_purgable_control";
82 MACH_DCHECK((ret = mach_vm_protect(mach_task_self(), 82 MACH_DCHECK((ret = vm_protect(mach_task_self(),
83 memory_.address(), 83 memory_.address(),
84 memory_.size(), 84 memory_.size(),
85 FALSE, 85 FALSE,
86 VM_PROT_NONE)) == KERN_SUCCESS, ret); 86 VM_PROT_NONE)) == KERN_SUCCESS, ret);
87 } 87 }
88 88
89 virtual void* Memory() const OVERRIDE { 89 virtual void* Memory() const OVERRIDE {
90 return reinterpret_cast<void*>(memory_.address()); 90 return reinterpret_cast<void*>(memory_.address());
91 } 91 }
92 92
93 private: 93 private:
94 mac::ScopedMachVM memory_; 94 mac::ScopedMachVM memory_;
95 size_t size_; 95 size_t size_;
96 96
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 } 153 }
154 154
155 NOTREACHED(); 155 NOTREACHED();
156 return scoped_ptr<DiscardableMemory>(); 156 return scoped_ptr<DiscardableMemory>();
157 } 157 }
158 158
159 // static 159 // static
160 void DiscardableMemory::PurgeForTesting() { 160 void DiscardableMemory::PurgeForTesting() {
161 int state = 0; 161 int state = 0;
162 mach_vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); 162 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state);
163 internal::DiscardableMemoryEmulated::PurgeForTesting(); 163 internal::DiscardableMemoryEmulated::PurgeForTesting();
164 } 164 }
165 165
166 } // namespace base 166 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698