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

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

Issue 1249643007: Align base::Pickle allocations to 4k boundaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@accounting_fix
Patch Set: Nits test Created 5 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_shared_memory.h" 5 #include "base/memory/discardable_shared_memory.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <unistd.h> 8 #include <unistd.h>
9 #endif 9 #endif
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/bits.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/numerics/safe_math.h" 16 #include "base/numerics/safe_math.h"
16 #include "base/process/process_metrics.h" 17 #include "base/process/process_metrics.h"
17 18
18 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
19 #include "third_party/ashmem/ashmem.h" 20 #include "third_party/ashmem/ashmem.h"
20 #endif 21 #endif
21 22
22 namespace base { 23 namespace base {
23 namespace { 24 namespace {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 UAtomicType u; 83 UAtomicType u;
83 } value; 84 } value;
84 }; 85 };
85 86
86 // Shared state is stored at offset 0 in shared memory segments. 87 // Shared state is stored at offset 0 in shared memory segments.
87 SharedState* SharedStateFromSharedMemory(const SharedMemory& shared_memory) { 88 SharedState* SharedStateFromSharedMemory(const SharedMemory& shared_memory) {
88 DCHECK(shared_memory.memory()); 89 DCHECK(shared_memory.memory());
89 return static_cast<SharedState*>(shared_memory.memory()); 90 return static_cast<SharedState*>(shared_memory.memory());
90 } 91 }
91 92
92 // Round up |size| to a multiple of alignment, which must be a power of two.
93 size_t Align(size_t alignment, size_t size) {
94 DCHECK_EQ(alignment & (alignment - 1), 0u);
95 return (size + alignment - 1) & ~(alignment - 1);
96 }
97
98 // Round up |size| to a multiple of page size. 93 // Round up |size| to a multiple of page size.
99 size_t AlignToPageSize(size_t size) { 94 size_t AlignToPageSize(size_t size) {
100 return Align(base::GetPageSize(), size); 95 return bits::Align(size, base::GetPageSize());
101 } 96 }
102 97
103 } // namespace 98 } // namespace
104 99
105 DiscardableSharedMemory::DiscardableSharedMemory() 100 DiscardableSharedMemory::DiscardableSharedMemory()
106 : mapped_size_(0), locked_page_count_(0) { 101 : mapped_size_(0), locked_page_count_(0) {
107 } 102 }
108 103
109 DiscardableSharedMemory::DiscardableSharedMemory( 104 DiscardableSharedMemory::DiscardableSharedMemory(
110 SharedMemoryHandle shared_memory_handle) 105 SharedMemoryHandle shared_memory_handle)
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 NOTIMPLEMENTED(); 362 NOTIMPLEMENTED();
368 #endif 363 #endif
369 } 364 }
370 #endif 365 #endif
371 366
372 Time DiscardableSharedMemory::Now() const { 367 Time DiscardableSharedMemory::Now() const {
373 return Time::Now(); 368 return Time::Now();
374 } 369 }
375 370
376 } // namespace base 371 } // namespace base
OLDNEW
« base/bits_unittest.cc ('K') | « base/bits_unittest.cc ('k') | base/pickle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698