OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "courgette/memory_allocator.h" | 5 #include "courgette/memory_allocator.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 128 } |
129 | 129 |
130 TempMapping** write = reinterpret_cast<TempMapping**>(mapping_.view()); | 130 TempMapping** write = reinterpret_cast<TempMapping**>(mapping_.view()); |
131 write[0] = this; | 131 write[0] = this; |
132 | 132 |
133 return true; | 133 return true; |
134 } | 134 } |
135 | 135 |
136 void* TempMapping::memory() const { | 136 void* TempMapping::memory() const { |
137 uint8* mem = reinterpret_cast<uint8*>(mapping_.view()); | 137 uint8* mem = reinterpret_cast<uint8*>(mapping_.view()); |
138 // The 'this' pointer is written at the start of mapping_.view, so | |
139 // go past it. (See Initialize()). | |
tommi (sloooow) - chröme
2012/07/25 19:04:05
Ah, nice! That's not at all clear from the code.
Greg Billock
2012/07/25 20:12:04
Done.
| |
138 if (mem) | 140 if (mem) |
139 mem += sizeof(this); | 141 mem += sizeof(this); |
140 DCHECK(mem); | 142 DCHECK(mem); |
141 return mem; | 143 return mem; |
142 } | 144 } |
143 | 145 |
144 bool TempMapping::valid() const { | 146 bool TempMapping::valid() const { |
145 return mapping_.valid(); | 147 return mapping_.valid(); |
146 } | 148 } |
147 | 149 |
148 // static | 150 // static |
149 TempMapping* TempMapping::GetMappingFromPtr(void* mem) { | 151 TempMapping* TempMapping::GetMappingFromPtr(void* mem) { |
150 TempMapping* ret = NULL; | 152 TempMapping* ret = NULL; |
151 if (mem) { | 153 if (mem) { |
152 ret = reinterpret_cast<TempMapping**>(mem)[-1]; | 154 ret = reinterpret_cast<TempMapping**>(mem)[-1]; |
153 } | 155 } |
154 DCHECK(ret); | 156 DCHECK(ret); |
155 return ret; | 157 return ret; |
156 } | 158 } |
157 | 159 |
158 } // namespace courgette | 160 } // namespace courgette |
159 | 161 |
160 #endif // OS_WIN | 162 #endif // OS_WIN |
OLD | NEW |