Changeset 179915 in webkit
- Timestamp:
- Feb 10, 2015, 8:54:03 PM (12 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
wtf/FastMalloc.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r179866 r179915 1 2015-02-10 Darin Adler <darin@apple.com> 2 3 Add the crash-on-failure behavior to bmalloc-based fastMalloc 4 https://bugs.webkit.org/show_bug.cgi?id=141434 5 6 Reviewed by Alexey Proskuryakov. 7 8 * wtf/FastMalloc.cpp: Removed unneeded includes. 9 (WTF::fastMalloc): Added null check and CRASH. 10 (WTF::fastCalloc): Added overflow checking, null check, and CRASH. 11 (WTF::fastRealloc): Added null check and CRASH. 12 (WTF::fastMallocSize): Added FIXME comment. 13 (WTF::fastMallocGoodSize): Added FIXME comment. 14 (WTF::fastAlignedMalloc): Added null check and CRASH. 15 (WTF::tryFastMalloc): Changed to call bmalloc directly instead of 16 calling fastMalloc, since fastMalloc will now crash on failure. 17 (WTF::tryFastRealloc): Changed to call bmalloc directly instead of 18 calling fastRealloc, since fastRealloc will now crash on failure. 19 (WTF::tryFastCalloc): Added overflow checking. 20 (WTF::fastMallocStatistics): Added FIXME comment. 21 1 22 2015-02-10 Carlos Garcia Campos <cgarcia@igalia.com> 2 23 -
trunk/Source/WTF/wtf/FastMalloc.cpp
r179855 r179915 1 1 // Copyright (c) 2005, 2007, Google Inc. 2 2 // All rights reserved. 3 // Copyright (C) 2005 , 2006, 2007, 2008,2009, 2011, 2015 Apple Inc. All rights reserved.3 // Copyright (C) 2005-2009, 2011, 2015 Apple Inc. All rights reserved. 4 4 // 5 5 // Redistribution and use in source and binary forms, with or without … … 78 78 #include "FastMalloc.h" 79 79 80 #include " Assertions.h"80 #include "CheckedArithmetic.h" 81 81 #include "CurrentTime.h" 82 83 82 #include <limits> 83 #include <string.h> 84 #include <wtf/DataLog.h> 85 84 86 #if OS(WINDOWS) 85 87 #include <windows.h> … … 87 89 #include <pthread.h> 88 90 #endif 89 #include <string.h>90 #include <wtf/DataLog.h>91 #include <wtf/StdLibExtras.h>92 91 93 92 #if OS(DARWIN) … … 274 273 void* fastMalloc(size_t size) 275 274 { 275 void* result = bmalloc::api::malloc(size); 276 if (!result) 277 CRASH(); 278 return result; 279 } 280 281 void* fastCalloc(size_t numElements, size_t elementSize) 282 { 283 Checked<size_t> checkedSize = elementSize; 284 checkedSize *= numElements; 285 void* result = fastZeroedMalloc(checkedSize.unsafeGet()); 286 if (!result) 287 CRASH(); 288 return result; 289 } 290 291 void* fastRealloc(void* object, size_t size) 292 { 293 void* result = bmalloc::api::realloc(object, size); 294 if (!result) 295 CRASH(); 296 return result; 297 } 298 299 void fastFree(void* object) 300 { 301 bmalloc::api::free(object); 302 } 303 304 size_t fastMallocSize(const void*) 305 { 306 // FIXME: This is incorrect; best fix is probably to remove this function. 307 // Caller currently are all using this for assertion, not to actually check 308 // the size of the allocation, so maybe we can come up with something for that. 309 return 1; 310 } 311 312 size_t fastMallocGoodSize(size_t size) 313 { 314 // FIXME: This is non-helpful; fastMallocGoodSize will be removed soon. 315 return size; 316 } 317 318 void* fastAlignedMalloc(size_t alignment, size_t size) 319 { 320 void* result = bmalloc::api::memalign(alignment, size); 321 if (!result) 322 CRASH(); 323 return result; 324 } 325 326 void fastAlignedFree(void* p) 327 { 328 bmalloc::api::free(p); 329 } 330 331 TryMallocReturnValue tryFastMalloc(size_t size) 332 { 276 333 return bmalloc::api::malloc(size); 277 334 } 278 279 void* fastCalloc(size_t numElements, size_t elementSize)280 {281 return fastZeroedMalloc(numElements * elementSize);282 }283 335 284 void* fastRealloc(void* object, size_t size)336 TryMallocReturnValue tryFastRealloc(void* object, size_t size) 285 337 { 286 338 return bmalloc::api::realloc(object, size); 287 }288 289 void fastFree(void* object)290 {291 bmalloc::api::free(object);292 }293 294 size_t fastMallocSize(const void*)295 {296 return 1;297 }298 299 size_t fastMallocGoodSize(size_t size)300 {301 return size;302 }303 304 void* fastAlignedMalloc(size_t alignment, size_t size)305 {306 return bmalloc::api::memalign(alignment, size);307 }308 309 void fastAlignedFree(void* p)310 {311 bmalloc::api::free(p);312 }313 314 TryMallocReturnValue tryFastMalloc(size_t size)315 {316 return fastMalloc(size);317 }318 319 TryMallocReturnValue tryFastRealloc(void* p, size_t n)320 {321 return fastRealloc(p, n);322 339 } 323 340 324 341 TryMallocReturnValue tryFastCalloc(size_t numElements, size_t elementSize) 325 342 { 326 return tryFastZeroedMalloc(numElements * elementSize); 343 Checked<size_t, RecordOverflow> checkedSize = elementSize; 344 checkedSize *= numElements; 345 if (checkedSize.hasOverflowed()) 346 return nullptr; 347 return tryFastZeroedMalloc(checkedSize.unsafeGet()); 327 348 } 328 349 … … 339 360 FastMallocStatistics fastMallocStatistics() 340 361 { 362 // FIXME: This is incorrect; needs an implementation or to be removed. 341 363 FastMallocStatistics statistics = { 0, 0, 0 }; 342 364 return statistics;
Note:
See TracChangeset
for help on using the changeset viewer.