Ignore:
Timestamp:
Dec 11, 2020, 7:53:45 AM (10 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
73a3be5
Parents:
97aca3d
Message:

for debug, fill deleted memory with deadbeef pattern

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r97aca3d re4b6b7d3  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep  7 22:17:46 2020
    13 // Update Count     : 957
     12// Last Modified On : Fri Dec 11 07:36:34 2020
     13// Update Count     : 970
    1414//
    1515
     
    464464} // headers
    465465
     466#ifdef __CFA_DEBUG__
     467#if __SIZEOF_POINTER__ == 4
     468#define MASK 0xdeadbeef
     469#else
     470#define MASK 0xdeadbeefdeadbeef
     471#endif
     472#define STRIDE size_t
     473
     474static void * Memset( void * addr, STRIDE size ) {              // debug only
     475        if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );
     476        if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );
     477
     478        STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);
     479        for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;
     480        return addr;
     481} // Memset
     482#endif // __CFA_DEBUG__
     483
    466484#define NO_MEMORY_MSG "insufficient heap memory available for allocating %zd new bytes."
    467485
     
    483501                #ifdef __CFA_DEBUG__
    484502                // Set new memory to garbage so subsequent uninitialized usages might fail.
    485                 memset( (char *)heapEnd + heapRemaining, '\377', increase );
     503                //memset( (char *)heapEnd + heapRemaining, '\377', increase );
     504                Memset( (char *)heapEnd + heapRemaining, increase );
    486505                #endif // __CFA_DEBUG__
    487506                rem = heapRemaining + increase - size;
     
    557576                #ifdef __CFA_DEBUG__
    558577                // Set new memory to garbage so subsequent uninitialized usages might fail.
    559                 memset( block, '\377', tsize );
     578                //memset( block, '\377', tsize );
     579                Memset( block, tsize );
    560580                #endif // __CFA_DEBUG__
    561581                block->header.kind.real.blockSize = tsize;              // storage size for munmap
     
    606626                #ifdef __CFA_DEBUG__
    607627                // Set free memory to garbage so subsequent usages might fail.
    608                 memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) );
     628                //memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) );
     629                Memset( ((HeapManager.Storage *)header)->data, freeElem->blockSize - sizeof( HeapManager.Storage ) );
    609630                #endif // __CFA_DEBUG__
    610631
     
    935956                        header->kind.real.size = size;                          // reset allocation size
    936957                        if ( unlikely( ozfill ) && size > osize ) {     // previous request zero fill and larger ?
    937                                 memset( (char *)oaddr + osize, (int)'\0', size - osize ); // initialize added storage
     958                                memset( (char *)oaddr + osize, '\0', size - osize ); // initialize added storage
    938959                        } // if
    939960                        return oaddr;
     
    960981                        header->kind.real.blockSize |= 2;                       // mark new request as zero filled
    961982                        if ( size > osize ) {                                           // previous request larger ?
    962                                 memset( (char *)naddr + osize, (int)'\0', size - osize ); // initialize added storage
     983                                memset( (char *)naddr + osize, '\0', size - osize ); // initialize added storage
    963984                        } // if
    964985                } // if
     
    13271348                header->kind.real.blockSize |= 2;                               // mark new request as zero filled
    13281349                if ( size > osize ) {                                                   // previous request larger ?
    1329                         memset( (char *)naddr + osize, (int)'\0', size - osize ); // initialize added storage
     1350                        memset( (char *)naddr + osize, '\0', size - osize ); // initialize added storage
    13301351                } // if
    13311352        } // if
Note: See TracChangeset for help on using the changeset viewer.