| OLD | NEW | 
|    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  Loading... | 
|   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 IsAllocSizePermitted(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, padding and to | 
 |   51   // have a small margin. | 
 |   52   return alloc_size <= ((std::numeric_limits<int>::max)() - kPageSize); | 
 |   53 } | 
 |   54  | 
|   43 // Note: the following only works for "n"s that fit in 32-bits, but |   55 // 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. |   56 // that is fine since we only use it for small sizes. | 
|   45 static inline int LgFloor(size_t n) { |   57 static inline int LgFloor(size_t n) { | 
|   46   int log = 0; |   58   int log = 0; | 
|   47   for (int i = 4; i >= 0; --i) { |   59   for (int i = 4; i >= 0; --i) { | 
|   48     int shift = (1 << i); |   60     int shift = (1 << i); | 
|   49     size_t x = n >> shift; |   61     size_t x = n >> shift; | 
|   50     if (x != 0) { |   62     if (x != 0) { | 
|   51       n = x; |   63       n = x; | 
|   52       log += shift; |   64       log += shift; | 
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  213 uint64_t metadata_unmapped_bytes() { return metadata_unmapped_bytes_; } |  225 uint64_t metadata_unmapped_bytes() { return metadata_unmapped_bytes_; } | 
|  214  |  226  | 
|  215 void update_metadata_system_bytes(int diff) { |  227 void update_metadata_system_bytes(int diff) { | 
|  216   metadata_system_bytes_ += diff; |  228   metadata_system_bytes_ += diff; | 
|  217 } |  229 } | 
|  218 void update_metadata_unmapped_bytes(int diff) { |  230 void update_metadata_unmapped_bytes(int diff) { | 
|  219   metadata_unmapped_bytes_ += diff; |  231   metadata_unmapped_bytes_ += diff; | 
|  220 } |  232 } | 
|  221  |  233  | 
|  222 }  // namespace tcmalloc |  234 }  // namespace tcmalloc | 
| OLD | NEW |