| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <map> | 10 #include <map> |
| 8 | 11 |
| 9 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 10 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 11 | 14 |
| 12 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 // The file is created in the %TEMP% folder. | 19 // The file is created in the %TEMP% folder. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return false; | 104 return false; |
| 102 } | 105 } |
| 103 | 106 |
| 104 TempMapping** write = reinterpret_cast<TempMapping**>(mapping_.view()); | 107 TempMapping** write = reinterpret_cast<TempMapping**>(mapping_.view()); |
| 105 write[0] = this; | 108 write[0] = this; |
| 106 | 109 |
| 107 return true; | 110 return true; |
| 108 } | 111 } |
| 109 | 112 |
| 110 void* TempMapping::memory() const { | 113 void* TempMapping::memory() const { |
| 111 uint8* mem = reinterpret_cast<uint8*>(mapping_.view()); | 114 uint8_t* mem = reinterpret_cast<uint8_t*>(mapping_.view()); |
| 112 // The 'this' pointer is written at the start of mapping_.view(), so | 115 // The 'this' pointer is written at the start of mapping_.view(), so |
| 113 // go past it. (See Initialize()). | 116 // go past it. (See Initialize()). |
| 114 if (mem) | 117 if (mem) |
| 115 mem += sizeof(this); | 118 mem += sizeof(this); |
| 116 DCHECK(mem); | 119 DCHECK(mem); |
| 117 return mem; | 120 return mem; |
| 118 } | 121 } |
| 119 | 122 |
| 120 bool TempMapping::valid() const { | 123 bool TempMapping::valid() const { |
| 121 return mapping_.valid(); | 124 return mapping_.valid(); |
| 122 } | 125 } |
| 123 | 126 |
| 124 // static | 127 // static |
| 125 TempMapping* TempMapping::GetMappingFromPtr(void* mem) { | 128 TempMapping* TempMapping::GetMappingFromPtr(void* mem) { |
| 126 TempMapping* ret = NULL; | 129 TempMapping* ret = NULL; |
| 127 if (mem) { | 130 if (mem) { |
| 128 ret = reinterpret_cast<TempMapping**>(mem)[-1]; | 131 ret = reinterpret_cast<TempMapping**>(mem)[-1]; |
| 129 } | 132 } |
| 130 DCHECK(ret); | 133 DCHECK(ret); |
| 131 return ret; | 134 return ret; |
| 132 } | 135 } |
| 133 | 136 |
| 134 } // namespace courgette | 137 } // namespace courgette |
| 135 | 138 |
| 136 #endif // OS_WIN | 139 #endif // OS_WIN |
| OLD | NEW |