Changeset b4aa1ab for libcfa


Ignore:
Timestamp:
Dec 13, 2020, 10:10:15 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
55885dd
Parents:
4803a901
Message:

fix running nested routines on stacks in the heap

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r4803a901 rb4aa1ab  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 11 07:36:34 2020
    13 // Update Count     : 970
     12// Last Modified On : Sun Dec 13 22:04:10 2020
     13// Update Count     : 984
    1414//
    1515
     
    490490                // If the size requested is bigger than the current remaining storage, increase the size of the heap.
    491491
    492                 size_t increase = ceiling2( size > heapExpand ? size : heapExpand, libAlign() );
     492                size_t increase = ceiling2( size > heapExpand ? size : heapExpand, pageSize );
    493493                if ( sbrk( increase ) == (void *)-1 ) {                 // failed, no memory ?
    494494                        unlock( extlock );
    495495                        abort( NO_MEMORY_MSG, size );                           // give up
     496                } // if
     497                if ( mprotect( (char *)heapEnd + heapRemaining, increase, PROT_READ | PROT_WRITE | PROT_EXEC ) ) {
     498                        enum { BufferSize = 128 };
     499                        char helpText[BufferSize];
     500                        // Do not call strerror( errno ) as it may call malloc.
     501                        int len = snprintf( helpText, BufferSize, "internal error, extend(), mprotect failure, heapEnd:%p size:%zd, errno:%d.", heapEnd, increase, errno );
     502                        __cfaabi_bits_write( STDERR_FILENO, helpText, len );
    496503                } // if
    497504                #ifdef __STATISTICS__
     
    568575                #endif // __STATISTICS__
    569576
    570                 block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
     577                block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
    571578                if ( block == (HeapManager.Storage *)MAP_FAILED ) { // failed ?
    572579                        if ( errno == ENOMEM ) abort( NO_MEMORY_MSG, tsize ); // no memory
    573580                        // Do not call strerror( errno ) as it may call malloc.
    574                         abort( "(HeapManager &)0x%p.doMalloc() : internal error, mmap failure, size:%zu error:%d.", &heapManager, tsize, errno );
     581                        abort( "(HeapManager &)0x%p.doMalloc() : internal error, mmap failure, size:%zu errno:%d.", &heapManager, tsize, errno );
    575582                } //if
    576583                #ifdef __CFA_DEBUG__
     
    669676                for ( HeapManager.Storage * p = freeLists[i].freeList; p != 0p; p = p->header.kind.real.next ) {
    670677                #else
    671                 // for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) {
     678                        for(;;) {
     679//              for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) {
    672680//              for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; /* p = getNext( p )->top */) {
    673                 for ( HeapManager.Storage * p ;; /* p = getNext( p )->top */) {
    674                         HeapManager.Storage * temp = p->header.kind.real.next.top; // FIX ME: direct assignent fails, initialization works`
     681//                      HeapManager.Storage * temp = p->header.kind.real.next.top; // FIX ME: direct assignent fails, initialization works`
    675682//                      typeof(p) temp = (( p )`next)->top;                     // FIX ME: direct assignent fails, initialization works`
    676683//                      p = temp;
     
    716723
    717724        char * end = (char *)sbrk( 0 );
    718         heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, libAlign() ) - end ); // move start of heap to multiple of alignment
     725        heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, pageSize ) - end ); // move start of heap to multiple of alignment
    719726} // HeapManager
    720727
Note: See TracChangeset for help on using the changeset viewer.