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

Side by Side Diff: third_party/tcmalloc/chromium/src/common.cc

Issue 11857007: TCMalloc: restrict maximum size of memory ranges (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable test in ASAN. Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2008, Google Inc. 1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 // Author: Sanjay Ghemawat <opensource@google.com> 31 // Author: Sanjay Ghemawat <opensource@google.com>
32 32
33 #include "config.h" 33 #include "config.h"
34 #include "common.h" 34 #include "common.h"
35 #include "system-alloc.h" 35 #include "system-alloc.h"
36 36
37 #if defined(HAVE_UNISTD_H) && defined(HAVE_GETPAGESIZE) 37 #if defined(HAVE_UNISTD_H) && defined(HAVE_GETPAGESIZE)
38 #include <unistd.h> // for getpagesize 38 #include <unistd.h> // for getpagesize
39 #endif 39 #endif
40 40
41 #include <limits>
42
41 namespace tcmalloc { 43 namespace tcmalloc {
42 44
45 bool IsContiguousAllocSizePermitted(size_t alloc_size) {
46 // Never allow an allocation of a contiguous area larger than what can
47 // be indexed via an int. This is meant as a security mitigation, see
48 // crbug.com/169369 for more background.
49
50 // Remove kPageSize to account for various rounding.
51 return alloc_size <= ((std::numeric_limits<int>::max)() - kPageSize);
Chris Evans 2013/01/11 19:51:51 Unusual parens used again.
jln (very slow on Chromium) 2013/01/11 20:02:04 Windows, again ;)
52 }
53
43 // Note: the following only works for "n"s that fit in 32-bits, but 54 // Note: the following only works for "n"s that fit in 32-bits, but
44 // that is fine since we only use it for small sizes. 55 // that is fine since we only use it for small sizes.
45 static inline int LgFloor(size_t n) { 56 static inline int LgFloor(size_t n) {
46 int log = 0; 57 int log = 0;
47 for (int i = 4; i >= 0; --i) { 58 for (int i = 4; i >= 0; --i) {
48 int shift = (1 << i); 59 int shift = (1 << i);
49 size_t x = n >> shift; 60 size_t x = n >> shift;
50 if (x != 0) { 61 if (x != 0) {
51 n = x; 62 n = x;
52 log += shift; 63 log += shift;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 uint64_t metadata_unmapped_bytes() { return metadata_unmapped_bytes_; } 224 uint64_t metadata_unmapped_bytes() { return metadata_unmapped_bytes_; }
214 225
215 void update_metadata_system_bytes(int diff) { 226 void update_metadata_system_bytes(int diff) {
216 metadata_system_bytes_ += diff; 227 metadata_system_bytes_ += diff;
217 } 228 }
218 void update_metadata_unmapped_bytes(int diff) { 229 void update_metadata_unmapped_bytes(int diff) {
219 metadata_unmapped_bytes_ += diff; 230 metadata_unmapped_bytes_ += diff;
220 } 231 }
221 232
222 } // namespace tcmalloc 233 } // namespace tcmalloc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698