Changeset 82876 in webkit


Ignore:
Timestamp:
Apr 4, 2011 2:59:48 PM (13 years ago)
Author:
oliver@apple.com
Message:

2011-04-04 Oliver Hunt <oliver@apple.com>

Reviewed by Geoffrey Garen.

Make malloc validation useful
https://bugs.webkit.org/show_bug.cgi?id=57502

This patch changes FAST_MALLOC_MATCH_VALIDATION with a general
corruption check that tags the beginning and end of all allocations
to check for write overflows and overwrites the contents of
memory on free in order to (hopefully) show up use-after-free issues
sooner.

We also turn it on by default for debug builds.

  • JavaScriptCore.exp:
  • wtf/FastMalloc.cpp: (WTF::tryFastMalloc): (WTF::fastMalloc): (WTF::tryFastCalloc): (WTF::fastCalloc): (WTF::fastFree): (WTF::tryFastRealloc): (WTF::fastRealloc): (WTF::TCMalloc_PageHeap::isScavengerSuspended): (WTF::TCMalloc_PageHeap::scheduleScavenger): (WTF::TCMalloc_PageHeap::suspendScavenger): (WTF::TCMalloc_PageHeap::signalScavenger): (WTF::TCMallocStats::malloc): (WTF::TCMallocStats::free): (WTF::TCMallocStats::fastCalloc): (WTF::TCMallocStats::tryFastCalloc): (WTF::TCMallocStats::calloc): (WTF::TCMallocStats::fastRealloc): (WTF::TCMallocStats::tryFastRealloc): (WTF::TCMallocStats::realloc):
  • wtf/FastMalloc.h: (WTF::Internal::fastMallocValidationHeader): (WTF::Internal::fastMallocValidationSuffix): (WTF::Internal::fastMallocMatchValidationType): (WTF::Internal::setFastMallocMatchValidationType): (WTF::fastMallocMatchValidateFree): (WTF::fastMallocValidate):
  • wtf/Platform.h:
Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r82875 r82876  
     12011-04-04  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Make malloc validation useful
     6        https://bugs.webkit.org/show_bug.cgi?id=57502
     7
     8        This patch changes FAST_MALLOC_MATCH_VALIDATION with a general
     9        corruption check that tags the beginning and end of all allocations
     10        to check for write overflows and overwrites the contents of
     11        memory on free in order to (hopefully) show up use-after-free issues
     12        sooner.
     13
     14        We also turn it on by default for debug builds.
     15
     16        * JavaScriptCore.exp:
     17        * wtf/FastMalloc.cpp:
     18        (WTF::tryFastMalloc):
     19        (WTF::fastMalloc):
     20        (WTF::tryFastCalloc):
     21        (WTF::fastCalloc):
     22        (WTF::fastFree):
     23        (WTF::tryFastRealloc):
     24        (WTF::fastRealloc):
     25        (WTF::TCMalloc_PageHeap::isScavengerSuspended):
     26        (WTF::TCMalloc_PageHeap::scheduleScavenger):
     27        (WTF::TCMalloc_PageHeap::suspendScavenger):
     28        (WTF::TCMalloc_PageHeap::signalScavenger):
     29        (WTF::TCMallocStats::malloc):
     30        (WTF::TCMallocStats::free):
     31        (WTF::TCMallocStats::fastCalloc):
     32        (WTF::TCMallocStats::tryFastCalloc):
     33        (WTF::TCMallocStats::calloc):
     34        (WTF::TCMallocStats::fastRealloc):
     35        (WTF::TCMallocStats::tryFastRealloc):
     36        (WTF::TCMallocStats::realloc):
     37        * wtf/FastMalloc.h:
     38        (WTF::Internal::fastMallocValidationHeader):
     39        (WTF::Internal::fastMallocValidationSuffix):
     40        (WTF::Internal::fastMallocMatchValidationType):
     41        (WTF::Internal::setFastMallocMatchValidationType):
     42        (WTF::fastMallocMatchValidateFree):
     43        (WTF::fastMallocValidate):
     44        * wtf/Platform.h:
     45
    1462011-04-04  Geoffrey Garen  <ggaren@apple.com>
    247
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r82849 r82876  
    493493__ZN3WTF8CollatorC1EPKc
    494494__ZN3WTF8CollatorD1Ev
     495__ZN3WTF8Internal21fastMallocMatchFailedEPv
    495496__ZN3WTF8fastFreeEPv
    496497__ZN3WTF8msToYearEd
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r82849 r82876  
    162162    ?fastFree@WTF@@YAXPAX@Z
    163163    ?fastMalloc@WTF@@YAPAXI@Z
     164    ?fastMallocMatchFailed@Internal@WTF@@YAXPAX@Z
    164165    ?fastMallocSize@WTF@@YAIPBX@Z
    165166    ?fastRealloc@WTF@@YAPAXPAXI@Z
  • trunk/Source/JavaScriptCore/wtf/FastMalloc.cpp

    r78176 r82876  
    162162namespace WTF {
    163163
    164 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    165164
    166165namespace Internal {
    167 
     166#if !ENABLE(WTF_MALLOC_VALIDATION)
     167void fastMallocMatchFailed(void*);
     168#else
     169COMPILE_ASSERT(((sizeof(ValidationHeader) % sizeof(AllocAlignmentInteger)) == 0), ValidationHeader_must_produce_correct_alignment);
     170#endif
    168171void fastMallocMatchFailed(void*)
    169172{
     
    173176} // namespace Internal
    174177
    175 #endif
    176178
    177179void* fastZeroedMalloc(size_t n)
     
    222224    ASSERT(!isForbidden());
    223225
    224 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    225     if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= n)  // If overflow would occur...
     226#if ENABLE(WTF_MALLOC_VALIDATION)
     227    if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= n)  // If overflow would occur...
    226228        return 0;
    227229
    228     void* result = malloc(n + sizeof(AllocAlignmentInteger));
     230    void* result = malloc(n + Internal::ValidationBufferSize);
    229231    if (!result)
    230232        return 0;
    231 
    232     *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
    233     result = static_cast<AllocAlignmentInteger*>(result) + 1;
    234 
     233    Internal::ValidationHeader* header = static_cast<Internal::ValidationHeader*>(result);
     234    header->m_size = n;
     235    header->m_type = Internal::AllocTypeMalloc;
     236    header->m_prefix = static_cast<unsigned>(Internal::ValidationPrefix);
     237    result = header + 1;
     238    *Internal::fastMallocValidationSuffix(result) = Internal::ValidationSuffix;
     239    fastMallocValidate(result);
    235240    return result;
    236241#else
     
    243248    ASSERT(!isForbidden());
    244249
    245 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     250#if ENABLE(WTF_MALLOC_VALIDATION)
    246251    TryMallocReturnValue returnValue = tryFastMalloc(n);
    247252    void* result;
     
    268273    ASSERT(!isForbidden());
    269274
    270 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     275#if ENABLE(WTF_MALLOC_VALIDATION)
    271276    size_t totalBytes = n_elements * element_size;
    272     if (n_elements > 1 && element_size && (totalBytes / element_size) != n_elements || (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= totalBytes))
     277    if (n_elements > 1 && element_size && (totalBytes / element_size) != n_elements)
    273278        return 0;
    274279
    275     totalBytes += sizeof(AllocAlignmentInteger);
    276     void* result = malloc(totalBytes);
    277     if (!result)
     280    TryMallocReturnValue returnValue = tryFastMalloc(totalBytes);
     281    void* result;
     282    if (!returnValue.getValue(result))
    278283        return 0;
    279 
    280284    memset(result, 0, totalBytes);
    281     *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
    282     result = static_cast<AllocAlignmentInteger*>(result) + 1;
     285    fastMallocValidate(result);
    283286    return result;
    284287#else
     
    291294    ASSERT(!isForbidden());
    292295
    293 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     296#if ENABLE(WTF_MALLOC_VALIDATION)
    294297    TryMallocReturnValue returnValue = tryFastCalloc(n_elements, element_size);
    295298    void* result;
     
    316319    ASSERT(!isForbidden());
    317320
    318 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     321#if ENABLE(WTF_MALLOC_VALIDATION)
    319322    if (!p)
    320323        return;
    321 
    322     AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(p);
    323     if (*header != Internal::AllocTypeMalloc)
    324         Internal::fastMallocMatchFailed(p);
     324   
     325    fastMallocMatchValidateFree(p, Internal::AllocTypeMalloc);
     326    Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
     327    memset(p, 0xCC, header->m_size);
    325328    free(header);
    326329#else
     
    333336    ASSERT(!isForbidden());
    334337
    335 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     338#if ENABLE(WTF_MALLOC_VALIDATION)
    336339    if (p) {
    337         if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= n)  // If overflow would occur...
     340        if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= n)  // If overflow would occur...
    338341            return 0;
    339         AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(p);
    340         if (*header != Internal::AllocTypeMalloc)
    341             Internal::fastMallocMatchFailed(p);
    342         void* result = realloc(header, n + sizeof(AllocAlignmentInteger));
     342        fastMallocValidate(p);
     343        Internal::ValidationHeader* result = static_cast<Internal::ValidationHeader*>(realloc(Internal::fastMallocValidationHeader(p), n + Internal::ValidationBufferSize));
    343344        if (!result)
    344345            return 0;
    345 
    346         // This should not be needed because the value is already there:
    347         // *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
    348         result = static_cast<AllocAlignmentInteger*>(result) + 1;
     346        result->m_size = n;
     347        result = result + 1;
     348        *fastMallocValidationSuffix(result) = Internal::ValidationSuffix;
     349        fastMallocValidate(result);
    349350        return result;
    350351    } else {
     
    360361    ASSERT(!isForbidden());
    361362
    362 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     363#if ENABLE(WTF_MALLOC_VALIDATION)
    363364    TryMallocReturnValue returnValue = tryFastRealloc(p, n);
    364365    void* result;
     
    383384size_t fastMallocSize(const void* p)
    384385{
    385 #if OS(DARWIN)
     386#if ENABLE(WTF_MALLOC_VALIDATION)
     387    return Internal::fastMallocValidationHeader(const_cast<void*>(p))->m_size;
     388#elif OS(DARWIN)
    386389    return malloc_size(p);
    387390#elif OS(WINDOWS) && !PLATFORM(BREWMP)
     
    13011304#endif
    13021305
     1306static SpinLock pageheap_lock = SPINLOCK_INITIALIZER;
     1307
    13031308class TCMalloc_PageHeap {
    13041309 public:
     
    15271532ALWAYS_INLINE bool TCMalloc_PageHeap::isScavengerSuspended()
    15281533{
    1529     ASSERT(IsHeld(pageheap_lock));
     1534    ASSERT(pageheap_lock.IsHeld());
    15301535    return m_scavengingSuspended;
    15311536}
     
    15331538ALWAYS_INLINE void TCMalloc_PageHeap::scheduleScavenger()
    15341539{
    1535     ASSERT(IsHeld(pageheap_lock));
     1540    ASSERT(pageheap_lock.IsHeld());
    15361541    m_scavengingSuspended = false;
    15371542    dispatch_resume(m_scavengeTimer);
     
    15451550ALWAYS_INLINE void TCMalloc_PageHeap::suspendScavenger()
    15461551{
    1547     ASSERT(IsHeld(pageheap_lock));
     1552    ASSERT(pageheap_lock.IsHeld());
    15481553    m_scavengingSuspended = true;
    15491554    dispatch_suspend(m_scavengeTimer);
     
    24382443
    24392444// Page-level allocator
    2440 static SpinLock pageheap_lock = SPINLOCK_INITIALIZER;
    24412445static AllocAlignmentInteger pageheap_memory[(sizeof(TCMalloc_PageHeap) + sizeof(AllocAlignmentInteger) - 1) / sizeof(AllocAlignmentInteger)];
    24422446static bool phinited = false;
     
    24762480ALWAYS_INLINE void TCMalloc_PageHeap::signalScavenger()
    24772481{
    2478     ASSERT(IsHeld(pageheap_lock));
     2482    ASSERT(pageheap_lock.IsHeld());
    24792483    if (isScavengerSuspended() && shouldScavenge())
    24802484        scheduleScavenger();
     
    38223826#endif
    38233827void* malloc(size_t size) {
    3824 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    3825     if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= size)  // If overflow would occur...
     3828#if ENABLE(WTF_MALLOC_VALIDATION)
     3829    if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= size)  // If overflow would occur...
    38263830        return 0;
    3827     size += sizeof(AllocAlignmentInteger);
    3828     void* result = do_malloc(size);
     3831    void* result = do_malloc(size + Internal::ValidationBufferSize);
    38293832    if (!result)
    38303833        return 0;
    38313834
    3832     *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
    3833     result = static_cast<AllocAlignmentInteger*>(result) + 1;
     3835    Internal::ValidationHeader* header = static_cast<Internal::ValidationHeader*>(result);
     3836    header->m_size = size;
     3837    header->m_type = Internal::AllocTypeMalloc;
     3838    header->m_prefix = static_cast<unsigned>(Internal::ValidationPrefix);
     3839    result = header + 1;
     3840    *Internal::fastMallocValidationSuffix(result) = Internal::ValidationSuffix;
     3841    fastMallocValidate(result);
    38343842#else
    38353843    void* result = do_malloc(size);
     
    38503858#endif
    38513859
    3852 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     3860#if ENABLE(WTF_MALLOC_VALIDATION)
    38533861    if (!ptr)
    38543862        return;
    38553863
    3856     AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(ptr);
    3857     if (*header != Internal::AllocTypeMalloc)
    3858         Internal::fastMallocMatchFailed(ptr);
     3864    fastMallocValidate(ptr);
     3865    Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(ptr);
     3866    memset(ptr, 0xCC, header->m_size);
    38593867    do_free(header);
    38603868#else
     
    38713879void* fastCalloc(size_t n, size_t elem_size)
    38723880{
    3873     return calloc<true>(n, elem_size);
     3881    void* result = calloc<true>(n, elem_size);
     3882#if ENABLE(WTF_MALLOC_VALIDATION)
     3883    fastMallocValidate(result);
     3884#endif
     3885    return result;
    38743886}
    38753887
    38763888TryMallocReturnValue tryFastCalloc(size_t n, size_t elem_size)
    38773889{
    3878     return calloc<false>(n, elem_size);
     3890    void* result = calloc<false>(n, elem_size);
     3891#if ENABLE(WTF_MALLOC_VALIDATION)
     3892    fastMallocValidate(result);
     3893#endif
     3894    return result;
    38793895}
    38803896
     
    38893905    return 0;
    38903906
    3891 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    3892     if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= totalBytes)  // If overflow would occur...
    3893         return 0;
    3894 
    3895     totalBytes += sizeof(AllocAlignmentInteger);
    3896     void* result = do_malloc(totalBytes);
     3907#if ENABLE(WTF_MALLOC_VALIDATION)
     3908    void* result = malloc<crashOnFailure>(totalBytes);
    38973909    if (!result)
    38983910        return 0;
    38993911
    39003912    memset(result, 0, totalBytes);
    3901     *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
    3902     result = static_cast<AllocAlignmentInteger*>(result) + 1;
     3913    fastMallocValidate(result);
    39033914#else
    39043915    void* result = do_malloc(totalBytes);
     
    39353946void* fastRealloc(void* old_ptr, size_t new_size)
    39363947{
    3937     return realloc<true>(old_ptr, new_size);
     3948#if ENABLE(WTF_MALLOC_VALIDATION)
     3949    fastMallocValidate(old_ptr);
     3950#endif
     3951    void* result = realloc<true>(old_ptr, new_size);
     3952#if ENABLE(WTF_MALLOC_VALIDATION)
     3953    fastMallocValidate(result);
     3954#endif
     3955    return result;
    39383956}
    39393957
    39403958TryMallocReturnValue tryFastRealloc(void* old_ptr, size_t new_size)
    39413959{
    3942     return realloc<false>(old_ptr, new_size);
     3960#if ENABLE(WTF_MALLOC_VALIDATION)
     3961    fastMallocValidate(old_ptr);
     3962#endif
     3963    void* result = realloc<false>(old_ptr, new_size);
     3964#if ENABLE(WTF_MALLOC_VALIDATION)
     3965    fastMallocValidate(result);
     3966#endif
     3967    return result;
    39433968}
    39443969
     
    39483973void* realloc(void* old_ptr, size_t new_size) {
    39493974  if (old_ptr == NULL) {
    3950 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    3951     void* result = malloc(new_size);
     3975#if ENABLE(WTF_MALLOC_VALIDATION)
     3976    void* result = malloc<crashOnFailure>(new_size);
    39523977#else
    39533978    void* result = do_malloc(new_size);
     
    39663991  }
    39673992
    3968 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    3969     if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= new_size)  // If overflow would occur...
     3993#if ENABLE(WTF_MALLOC_VALIDATION)
     3994    if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= new_size)  // If overflow would occur...
    39703995        return 0;
    3971     new_size += sizeof(AllocAlignmentInteger);
    3972     AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(old_ptr);
    3973     if (*header != Internal::AllocTypeMalloc)
    3974         Internal::fastMallocMatchFailed(old_ptr);
     3996    Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(old_ptr);
     3997    fastMallocValidate(old_ptr);
    39753998    old_ptr = header;
     3999    header->m_size = new_size;
     4000    new_size += Internal::ValidationBufferSize;
    39764001#endif
    39774002
     
    40124037    // would be small, so don't bother.
    40134038    do_free(old_ptr);
    4014 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    4015     new_ptr = static_cast<AllocAlignmentInteger*>(new_ptr) + 1;
     4039#if ENABLE(WTF_MALLOC_VALIDATION)
     4040    new_ptr = static_cast<Internal::ValidationHeader*>(new_ptr) + 1;
     4041    *Internal::fastMallocValidationSuffix(new_ptr) = Internal::ValidationSuffix;
    40164042#endif
    40174043    return new_ptr;
    40184044  } else {
    4019 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
    4020     old_ptr = static_cast<AllocAlignmentInteger*>(old_ptr) + 1; // Set old_ptr back to the user pointer.
     4045#if ENABLE(WTF_MALLOC_VALIDATION)
     4046    old_ptr = static_cast<Internal::ValidationHeader*>(old_ptr) + 1; // Set old_ptr back to the user pointer.
     4047    *Internal::fastMallocValidationSuffix(old_ptr) = Internal::ValidationSuffix;
    40214048#endif
    40224049    return old_ptr;
     
    42794306size_t fastMallocSize(const void* ptr)
    42804307{
     4308#if ENABLE(WTF_MALLOC_VALIDATION)
     4309    return Internal::fastMallocValidationHeader(p)->m_size;
     4310#else
    42814311    const PageID p = reinterpret_cast<uintptr_t>(ptr) >> kPageShift;
    42824312    Span* span = pageheap->GetDescriptorEnsureSafe(p);
     
    42944324
    42954325    return span->length << kPageShift;
     4326#endif
    42964327}
    42974328
  • trunk/Source/JavaScriptCore/wtf/FastMalloc.h

    r61544 r82876  
    104104            AllocTypeNewArray               // Encompasses global operator new[].
    105105        };
    106     }
    107 
    108 #if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     106
     107        enum {
     108            ValidationPrefix = 0xf00df00d,
     109            ValidationSuffix = 0x0badf00d
     110        };
     111
     112        typedef unsigned ValidationTag;
     113
     114        struct ValidationHeader {
     115            AllocType m_type;
     116            unsigned m_size;
     117            ValidationTag m_prefix;
     118            unsigned m_alignment;
     119        };
     120
     121        static const int ValidationBufferSize = sizeof(ValidationHeader) + sizeof(ValidationTag);
     122    }
     123
     124#if ENABLE(WTF_MALLOC_VALIDATION)
    109125
    110126    // Malloc validation is a scheme whereby a tag is attached to an
     
    121137
    122138    namespace Internal {
     139   
     140        // Handle a detected alloc/free mismatch. By default this calls CRASH().
     141        void fastMallocMatchFailed(void* p);
     142
     143        inline ValidationHeader* fastMallocValidationHeader(void* p)
     144        {
     145            return reinterpret_cast<ValidationHeader*>(static_cast<char*>(p) - sizeof(ValidationHeader));
     146        }
     147
     148        inline ValidationTag* fastMallocValidationSuffix(void* p)
     149        {
     150            ValidationHeader* header = fastMallocValidationHeader(p);
     151            if (header->m_prefix != static_cast<unsigned>(ValidationPrefix))
     152                fastMallocMatchFailed(p);
     153           
     154            return reinterpret_cast<ValidationTag*>(static_cast<char*>(p) + header->m_size);
     155        }
    123156
    124157        // Return the AllocType tag associated with the allocated block p.
    125         inline AllocType fastMallocMatchValidationType(const void* p)
    126         {
    127             const AllocAlignmentInteger* type = static_cast<const AllocAlignmentInteger*>(p) - 1;
    128             return static_cast<AllocType>(*type);
    129         }
    130 
    131         // Return the address of the AllocType tag associated with the allocated block p.
    132         inline AllocAlignmentInteger* fastMallocMatchValidationValue(void* p)
    133         {
    134             return reinterpret_cast<AllocAlignmentInteger*>(static_cast<char*>(p) - sizeof(AllocAlignmentInteger));
     158        inline AllocType fastMallocMatchValidationType(void* p)
     159        {
     160            return fastMallocValidationHeader(p)->m_type;
    135161        }
    136162
     
    138164        inline void setFastMallocMatchValidationType(void* p, AllocType allocType)
    139165        {
    140             AllocAlignmentInteger* type = static_cast<AllocAlignmentInteger*>(p) - 1;
    141             *type = static_cast<AllocAlignmentInteger>(allocType);
    142         }
    143 
    144         // Handle a detected alloc/free mismatch. By default this calls CRASH().
    145         void fastMallocMatchFailed(void* p);
     166            fastMallocValidationHeader(p)->m_type = allocType;
     167        }
    146168
    147169    } // namespace Internal
     
    157179
    158180    // This is a higher level function which is used by FastMalloc-using code.
    159     inline void fastMallocMatchValidateFree(void* p, Internal::AllocType allocType)
     181    inline void fastMallocMatchValidateFree(void* p, Internal::AllocType)
    160182    {
    161183        if (!p)
    162184            return;
    163 
    164         if (Internal::fastMallocMatchValidationType(p) != allocType)
    165             Internal::fastMallocMatchFailed(p);
     185   
     186        Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
     187        if (header->m_prefix != static_cast<unsigned>(Internal::ValidationPrefix))
     188            Internal::fastMallocMatchFailed(p);
     189
     190        if (*Internal::fastMallocValidationSuffix(p) != Internal::ValidationSuffix)
     191            Internal::fastMallocMatchFailed(p);
     192
    166193        Internal::setFastMallocMatchValidationType(p, Internal::AllocTypeMalloc);  // Set it to this so that fastFree thinks it's OK.
     194    }
     195
     196    inline void fastMallocValidate(void* p)
     197    {
     198        if (!p)
     199            return;
     200       
     201        Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
     202        if (header->m_prefix != static_cast<unsigned>(Internal::ValidationPrefix))
     203            Internal::fastMallocMatchFailed(p);
     204       
     205        if (*Internal::fastMallocValidationSuffix(p) != Internal::ValidationSuffix)
     206            Internal::fastMallocMatchFailed(p);
    167207    }
    168208
  • trunk/Source/JavaScriptCore/wtf/Platform.h

    r82516 r82876  
    2828#ifndef WTF_Platform_h
    2929#define WTF_Platform_h
     30#define ENABLE_JIT 0
    3031
    3132/* ==== PLATFORM handles OS, operating environment, graphics API, and
     
    876877/* fastMalloc match validation allows for runtime verification that
    877878   new is matched by delete, fastMalloc is matched by fastFree, etc. */
    878 #if !defined(ENABLE_FAST_MALLOC_MATCH_VALIDATION)
    879 #define ENABLE_FAST_MALLOC_MATCH_VALIDATION 0
     879#if !defined(ENABLE_WTF_MALLOC_VALIDATION)
     880#ifndef NDEBUG
     881#define ENABLE_WTF_MALLOC_VALIDATION 1
     882#else
     883#define ENABLE_WTF_MALLOC_VALIDATION 0
     884#endif
    880885#endif
    881886
Note: See TracChangeset for help on using the changeset viewer.