| 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 "base/memory/aligned_memory.h" | 5 #include "base/memory/aligned_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" |
| 8 | 9 |
| 9 #if defined(OS_ANDROID) | 10 #if defined(OS_ANDROID) |
| 10 #include <malloc.h> | 11 #include <malloc.h> |
| 11 #endif | 12 #endif |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 void* AlignedAlloc(size_t size, size_t alignment) { | 16 void* AlignedAlloc(size_t size, size_t alignment) { |
| 16 DCHECK_GT(size, 0U); | 17 DCHECK_GT(size, 0U); |
| 17 DCHECK_EQ(alignment & (alignment - 1), 0U); | 18 DCHECK_EQ(alignment & (alignment - 1), 0U); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 37 DLOG(ERROR) << "If you crashed here, your aligned allocation is incorrect: " | 38 DLOG(ERROR) << "If you crashed here, your aligned allocation is incorrect: " |
| 38 << "size=" << size << ", alignment=" << alignment; | 39 << "size=" << size << ", alignment=" << alignment; |
| 39 CHECK(false); | 40 CHECK(false); |
| 40 } | 41 } |
| 41 // Sanity check alignment just to be safe. | 42 // Sanity check alignment just to be safe. |
| 42 DCHECK_EQ(reinterpret_cast<uintptr_t>(ptr) & (alignment - 1), 0U); | 43 DCHECK_EQ(reinterpret_cast<uintptr_t>(ptr) & (alignment - 1), 0U); |
| 43 return ptr; | 44 return ptr; |
| 44 } | 45 } |
| 45 | 46 |
| 46 } // namespace base | 47 } // namespace base |
| OLD | NEW |