| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include <new> | 9 #include <new> |
| 10 | 10 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return ShimMemalign(GetCachedPageSize(), size, context); | 240 return ShimMemalign(GetCachedPageSize(), size, context); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void* ShimPvalloc(size_t size) { | 243 void* ShimPvalloc(size_t size) { |
| 244 // pvalloc(0) should allocate one page, according to its man page. | 244 // pvalloc(0) should allocate one page, according to its man page. |
| 245 if (size == 0) { | 245 if (size == 0) { |
| 246 size = GetCachedPageSize(); | 246 size = GetCachedPageSize(); |
| 247 } else { | 247 } else { |
| 248 size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1); | 248 size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1); |
| 249 } | 249 } |
| 250 // The third argument is nullptr because pvalloc is glibc only and does not |
| 251 // exist on OSX/BSD systems. |
| 250 return ShimMemalign(GetCachedPageSize(), size, nullptr); | 252 return ShimMemalign(GetCachedPageSize(), size, nullptr); |
| 251 } | 253 } |
| 252 | 254 |
| 253 void ShimFree(void* address, void* context) { | 255 void ShimFree(void* address, void* context) { |
| 254 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); | 256 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); |
| 255 return chain_head->free_function(chain_head, address, context); | 257 return chain_head->free_function(chain_head, address, context); |
| 256 } | 258 } |
| 257 | 259 |
| 258 size_t ShimGetSizeEstimate(const void* address, void* context) { | 260 size_t ShimGetSizeEstimate(const void* address, void* context) { |
| 259 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); | 261 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // Cross-checks. | 335 // Cross-checks. |
| 334 | 336 |
| 335 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 337 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| 336 #error The allocator shim should not be compiled when building for memory tools. | 338 #error The allocator shim should not be compiled when building for memory tools. |
| 337 #endif | 339 #endif |
| 338 | 340 |
| 339 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ | 341 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ |
| 340 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) | 342 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) |
| 341 #error This code cannot be used when exceptions are turned on. | 343 #error This code cannot be used when exceptions are turned on. |
| 342 #endif | 344 #endif |
| OLD | NEW |