⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 179915 in webkit


Ignore:
Timestamp:
Feb 10, 2015, 8:54:03 PM (12 years ago)
Author:
Darin Adler
Message:

Add the crash-on-failure behavior to bmalloc-based fastMalloc
https://bugs.webkit.org/show_bug.cgi?id=141434

Reviewed by Alexey Proskuryakov.

  • wtf/FastMalloc.cpp: Removed unneeded includes.

(WTF::fastMalloc): Added null check and CRASH.
(WTF::fastCalloc): Added overflow checking, null check, and CRASH.
(WTF::fastRealloc): Added null check and CRASH.
(WTF::fastMallocSize): Added FIXME comment.
(WTF::fastMallocGoodSize): Added FIXME comment.
(WTF::fastAlignedMalloc): Added null check and CRASH.
(WTF::tryFastMalloc): Changed to call bmalloc directly instead of
calling fastMalloc, since fastMalloc will now crash on failure.
(WTF::tryFastRealloc): Changed to call bmalloc directly instead of
calling fastRealloc, since fastRealloc will now crash on failure.
(WTF::tryFastCalloc): Added overflow checking.
(WTF::fastMallocStatistics): Added FIXME comment.

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r179866 r179915  
     12015-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
    1222015-02-10  Carlos Garcia Campos  <cgarcia@igalia.com>
    223
  • trunk/Source/WTF/wtf/FastMalloc.cpp

    r179855 r179915  
    11// Copyright (c) 2005, 2007, Google Inc.
    22// 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.
    44//
    55// Redistribution and use in source and binary forms, with or without
     
    7878#include "FastMalloc.h"
    7979
    80 #include "Assertions.h"
     80#include "CheckedArithmetic.h"
    8181#include "CurrentTime.h"
    82 
    8382#include <limits>
     83#include <string.h>
     84#include <wtf/DataLog.h>
     85
    8486#if OS(WINDOWS)
    8587#include <windows.h>
     
    8789#include <pthread.h>
    8890#endif
    89 #include <string.h>
    90 #include <wtf/DataLog.h>
    91 #include <wtf/StdLibExtras.h>
    9291
    9392#if OS(DARWIN)
     
    274273void* fastMalloc(size_t size)
    275274{
     275    void* result = bmalloc::api::malloc(size);
     276    if (!result)
     277        CRASH();
     278    return result;
     279}
     280
     281void* 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
     291void* 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
     299void fastFree(void* object)
     300{
     301    bmalloc::api::free(object);
     302}
     303
     304size_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
     312size_t fastMallocGoodSize(size_t size)
     313{
     314    // FIXME: This is non-helpful; fastMallocGoodSize will be removed soon.
     315    return size;
     316}
     317
     318void* 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
     326void fastAlignedFree(void* p)
     327{
     328    bmalloc::api::free(p);
     329}
     330
     331TryMallocReturnValue tryFastMalloc(size_t size)
     332{
    276333    return bmalloc::api::malloc(size);
    277334}
    278 
    279 void* fastCalloc(size_t numElements, size_t elementSize)
    280 {
    281     return fastZeroedMalloc(numElements * elementSize);
    282 }
    283335   
    284 void* fastRealloc(void* object, size_t size)
     336TryMallocReturnValue tryFastRealloc(void* object, size_t size)
    285337{
    286338    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);
    322339}
    323340   
    324341TryMallocReturnValue tryFastCalloc(size_t numElements, size_t elementSize)
    325342{
    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());
    327348}
    328349   
     
    339360FastMallocStatistics fastMallocStatistics()
    340361{
     362    // FIXME: This is incorrect; needs an implementation or to be removed.
    341363    FastMallocStatistics statistics = { 0, 0, 0 };
    342364    return statistics;
Note: See TracChangeset for help on using the changeset viewer.