Changeset 1aa6ecb for libcfa/src


Ignore:
Timestamp:
Oct 20, 2019, 11:14:28 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
cafb687
Parents:
fdf4efb
Message:

check for maximum allocation and use macro to get header

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    rfdf4efb r1aa6ecb  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 24 13:12:45 2019
    13 // Update Count     : 550
     12// Last Modified On : Fri Oct 18 07:42:09 2019
     13// Update Count     : 556
    1414//
    1515
     
    541541        // along with the block and is a multiple of the alignment size.
    542542
     543  if ( unlikely( size > ~0ul - sizeof(HeapManager.Storage) ) ) return 0;
    543544        size_t tsize = size + sizeof(HeapManager.Storage);
    544545        if ( likely( tsize < mmapStart ) ) {                            // small size => sbrk
     
    592593                block->header.kind.real.home = freeElem;                // pointer back to free list of apropriate size
    593594        } else {                                                                                        // large size => mmap
     595  if ( unlikely( size > ~0ul - pageSize ) ) return 0;
    594596                tsize = libCeiling( tsize, pageSize );                  // must be multiple of page size
    595597                #ifdef __STATISTICS__
     
    888890        } // realloc
    889891
    890 
    891892        // The obsolete function memalign() allocates size bytes and returns a pointer to the allocated memory. The memory
    892893        // address will be a multiple of alignment, which must be a power of two.
     
    992993        size_t malloc_alignment( void * addr ) {
    993994          if ( unlikely( addr == 0 ) ) return libAlign();       // minimum alignment
    994                 HeapManager.Storage.Header * header = (HeapManager.Storage.Header *)( (char *)addr - sizeof(HeapManager.Storage) );
     995                HeapManager.Storage.Header * header = headerAddr( addr );
    995996                if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ?
    996997                        return header->kind.fake.alignment & -2;        // remove flag from value
     
    10041005        bool malloc_zero_fill( void * addr ) {
    10051006          if ( unlikely( addr == 0 ) ) return false;            // null allocation is not zero fill
    1006 
    1007                 HeapManager.Storage.Header * header = (HeapManager.Storage.Header *)( (char *)addr - sizeof(HeapManager.Storage) );
     1007                HeapManager.Storage.Header * header = headerAddr( addr );
    10081008                if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ?
    10091009                        header = (HeapManager.Storage.Header *)((char *)header - header->kind.fake.offset);
Note: See TracChangeset for help on using the changeset viewer.