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

Side by Side Diff: base/allocator/partition_allocator/address_space_randomization.cc

Issue 2614883006: Change PartitionAlloc to Chromium naming style. (Closed)
Patch Set: Rebase and fix some names. Created 3 years, 11 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/allocator/partition_allocator/address_space_randomization.h" 5 #include "base/allocator/partition_allocator/address_space_randomization.h"
6 6
7 #include "base/allocator/partition_allocator/page_allocator.h" 7 #include "base/allocator/partition_allocator/page_allocator.h"
8 #include "base/synchronization/spin_lock.h" 8 #include "base/synchronization/spin_lock.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 uint32_t ret = ranvalInternal(x); 73 uint32_t ret = ranvalInternal(x);
74 return ret; 74 return ret;
75 } 75 }
76 76
77 static struct ranctx s_ranctx; 77 static struct ranctx s_ranctx;
78 78
79 } // namespace 79 } // namespace
80 80
81 // Calculates a random preferred mapping address. In calculating an address, we 81 // Calculates a random preferred mapping address. In calculating an address, we
82 // balance good ASLR against not fragmenting the address space too badly. 82 // balance good ASLR against not fragmenting the address space too badly.
83 void* getRandomPageBase() { 83 void* GetRandomPageBase() {
84 uintptr_t random; 84 uintptr_t random;
85 random = static_cast<uintptr_t>(ranval(&s_ranctx)); 85 random = static_cast<uintptr_t>(ranval(&s_ranctx));
86 #if defined(ARCH_CPU_X86_64) 86 #if defined(ARCH_CPU_X86_64)
87 random <<= 32UL; 87 random <<= 32UL;
88 random |= static_cast<uintptr_t>(ranval(&s_ranctx)); 88 random |= static_cast<uintptr_t>(ranval(&s_ranctx));
89 // This address mask gives a low likelihood of address space collisions. We 89 // This address mask gives a low likelihood of address space collisions. We
90 // handle the situation gracefully if there is a collision. 90 // handle the situation gracefully if there is a collision.
91 #if defined(OS_WIN) 91 #if defined(OS_WIN)
92 // 64-bit Windows has a bizarrely small 8TB user address space. Allocates in 92 // 64-bit Windows has a bizarrely small 8TB user address space. Allocates in
93 // the 1-5TB region. TODO(palmer): See if Windows >= 8.1 has the full 47 bits, 93 // the 1-5TB region. TODO(palmer): See if Windows >= 8.1 has the full 47 bits,
(...skipping 27 matching lines...) Expand all
121 // This is a good range on Windows, Linux and Mac. 121 // This is a good range on Windows, Linux and Mac.
122 // Allocates in the 0.5-1.5GB region. 122 // Allocates in the 0.5-1.5GB region.
123 random &= 0x3fffffff; 123 random &= 0x3fffffff;
124 random += 0x20000000; 124 random += 0x20000000;
125 #endif // defined(ARCH_CPU_X86_64) 125 #endif // defined(ARCH_CPU_X86_64)
126 random &= kPageAllocationGranularityBaseMask; 126 random &= kPageAllocationGranularityBaseMask;
127 return reinterpret_cast<void*>(random); 127 return reinterpret_cast<void*>(random);
128 } 128 }
129 129
130 } // namespace base 130 } // namespace base
OLDNEW
« no previous file with comments | « base/allocator/partition_allocator/address_space_randomization.h ('k') | base/allocator/partition_allocator/page_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698