Exemple #1
0
void _WCNEAR *__brk( unsigned brk_value )
{
    unsigned    old_brk_value;
    unsigned    seg_size;
    __segment   segment;

    if( brk_value < _STACKTOP ) {
        _RWD_errno = ENOMEM;
        return( (void _WCNEAR *)-1 );
    }
    seg_size = ( brk_value + 0x0f ) >> 4;
    if( seg_size == 0 ) {
        seg_size = 0x1000;
    }
    /* try setting the block of memory */
    _AccessNHeap();

    segment = _DGroup();
    if( qnx_segment_realloc( segment,((unsigned long)seg_size) << 4) == -1 ) {
        _RWD_errno = ENOMEM;
        _ReleaseNHeap();
        return( (void _WCNEAR *)-1 );
    }

    old_brk_value = _curbrk;        /* return old value of _curbrk */
    _curbrk = brk_value;            /* set new break value */
    _ReleaseNHeap();
    return( (void _WCNEAR *)old_brk_value );
}
_WCRTLINK void _nheapgrow( void )
    {
#if defined( __WINDOWS_286__ ) || !defined( _M_I86 )
        _nfree( _nmalloc( 1 ) );        /* get something into the heap */
#else
        unsigned max_paras;
        unsigned curr_paras;
        unsigned diff_paras;
        unsigned expand;

        _AccessNHeap();
        /* calculate # pages which always has extra slack space (ie. 0x10) */
        curr_paras = (( _curbrk + 0x10 ) & ~0x0f ) >> 4;
        if( curr_paras == 0 ) {
            /* we're already at 64k */
            _ReleaseNHeap();
            return;
        }
#if defined(__QNX__)
        if( qnx_segment_realloc( _DGroup(), 65536L ) == -1 ) {
            _ReleaseNHeap();
            return;
        }
        max_paras = PARAS_IN_64K;
#elif defined(__OS2__)
        if( DosReallocSeg( 0, _DGroup() ) )  {
            _ReleaseNHeap();
            return;
        }
        max_paras = PARAS_IN_64K;
#else
        if( _RWD_osmode != DOS_MODE ) {                     /* 23-apr-91 */
            max_paras = PARAS_IN_64K;
        } else {
            max_paras = TinyMaxSet( _RWD_psp );
            /* subtract off code size */
            max_paras -= _DGroup() - _RWD_psp;
            if( max_paras > PARAS_IN_64K ) {
                max_paras = PARAS_IN_64K;
            }
        }
#endif
        if( max_paras <= curr_paras ) {
            /* '<' -> something is wrong, '==' -> can't change size */
            _ReleaseNHeap();
            return;
        }
        diff_paras = max_paras - curr_paras;
        expand = (( diff_paras + 1 ) << 4 ) - ( _curbrk & 0x0f );
        expand += __LastFree(); /* compensate for _expand's adjustment */
        _ReleaseNHeap();
        _nfree( _nmalloc( expand - ( sizeof( size_t ) + sizeof(frl) ) ) );
#endif
    }
Exemple #3
0
static bool setupscrnbuff( void )
/*******************************/
{
    int                 rows, cols;
    LP_PIXEL            scrn;
    size_t              num;
    int                 i;

    if( console_size( UIConCtrl, UIConsole, 0, 0, &rows, &cols ) != 0 ) {
        return( false );
    }
    UIData->width = cols;
    UIData->height = rows;
    num = UIData->width * UIData->height * 2;
    scrn = UIData->screen.origin;
#if defined( __386__ )
    scrn = realloc( scrn, num );
    if( scrn == NULL )
        return( false );
#else
    {
        unsigned                seg;

        if( scrn == NULL ) {
            seg = qnx_segment_alloc( num );
        } else {
            seg = qnx_segment_realloc( FP_SEG( scrn ), num );
        }
        if( seg == -1 )
            return( false );
        scrn = MK_FP( seg, 0 );
    }
#endif
    num /= 2;
    for( i = 0; i < num; ++i ) {
        scrn[i].ch = ' ';       /* a space with normal attributes */
        scrn[i].attr = 7;       /* a space with normal attributes */
    }
    UIData->screen.origin = scrn;
    UIData->screen.increment = UIData->width;
    return( true );
}
Exemple #4
0
static bool setupscrnbuff( int srows, int scols )
/***********************************************/
{
    LP_PIXEL    scrn;
    int         num;
    int         i;
    int         rows;
    int         cols;

    if( dev_size( UIConHandle, -1, -1, &rows, &cols ) == -1 )
        return( false );
    if( rows == 0 ) {
        rows = srows;
        if( rows == 0 ) {
            rows = lines;
            if( rows == 0 ) {
                rows = 25;
            }
        }
    }
    if( cols == 0 ) {
        cols = scols;
        if( cols == 0 ) {
            cols = columns;
            if( columns == 0 ) {
                cols = 80;
            }
        }
    }

    UIData->width = cols;
    UIData->height = rows;
    UIData->cursor_type = C_NORMAL;

    num = UIData->width * UIData->height * 2;
    scrn = UIData->screen.origin;
#if defined( __386__ )
    scrn = realloc( scrn, num );
    if( scrn == NULL )
        return( false );
    if( (shadow = realloc( shadow, num )) == NULL ) {
        free( scrn );
        return( false );
    }
#else
    {
        unsigned        seg;

        if( scrn == NULL ) {
            seg = qnx_segment_alloc( num );
        } else {
            seg = qnx_segment_realloc( FP_SEG( scrn ), num );
        }
        if( seg == -1 )
            return( false );
        scrn = MK_FP( seg, 0 );
        if( shadow == NULL ) {
            seg = qnx_segment_alloc( num );
        } else {
            seg = qnx_segment_realloc( FP_SEG( shadow ), num );
        }
        if( seg == -1 ) {
            qnx_segment_free( FP_SEG( scrn ) );
            return( false );
        }
        shadow = MK_FP( seg, 0 );
    }
#endif
    save_cursor_type = -1; /* C_NORMAL; */
    num /= 2;
    for( i = 0; i < num; ++i ) {
        scrn[i].ch = ' ';       /* a space with normal attributes */
        scrn[i].attr = 7;       /* a space with normal attributes */
    }
    UIData->screen.origin = scrn;
    UIData->screen.increment = UIData->width;
    return( true );
}
Exemple #5
0
unsigned __GrowSeg( unsigned short seg, unsigned int amount )
    {
        unsigned n;             /* number of paragraphs desired   */
        unsigned int old_heaplen;
        unsigned int old_heap_paras;
        struct heapblk _WCFAR *p;
        struct freelist _WCFAR *pfree;
        struct freelist _WCFAR *pnew;
        tag _WCFAR *last_tag;

        if( !__heap_enabled ) return( 0 );
        p = (struct heapblk _WCFAR *)MK_FP( seg, 0 );
        old_heaplen = p->heaplen;
        if( old_heaplen != 0 ) {                /* if not already 64K */
            amount += TAG_SIZE;                      /* 25-feb-91 */
            if( amount < TAG_SIZE ) amount = ~0;
            if( amount < _amblksiz )  amount = _amblksiz;
            n = ( amount + 0x0f ) >> 4;
            if( n == 0 )  n = PARAS_IN_64K;     /* 23-may-89 */
            old_heap_paras = old_heaplen >> 4;
            n += old_heap_paras;
            /*
                We shouldn't extend segments to 64k if we are not going to
                use the space for this allocation.  In protected-mode
                environments, it should be possible to extend segments
                later on when we know we can use the space.
            */
#if defined(__QNX__)
            if( n > PARAS_IN_64K ) return( 0 );
#elif defined(__OS2__) || defined(__WINDOWS_286__)
            if( n > PARAS_IN_64K ) {
                if( _osmode != DOS_MODE ) {
                    /* protected-mode */
                    return( 0 );
                } else {
                    n = PARAS_IN_64K;
                }
            }
#else
            if( n > PARAS_IN_64K ) n = PARAS_IN_64K;
#endif
#if defined(__OS2__)
            if( DosReallocSeg( n << 4, seg ) != 0 )             return( 0 );
#elif defined(__QNX__)
            if( qnx_segment_realloc( seg, ((long)n) << 4 ) == -1 ) return( 0 );
#elif defined(__WINDOWS_286__)
            if( old_heap_paras < (PARAS_IN_64K-2) && n == PARAS_IN_64K ) {
                n = PARAS_IN_64K - 2;
            } else if( n > ( PARAS_IN_64K - 2 ) ) {
                /*
                  in Standard mode, GlobalRealloc may change selectors
                  if size > 65519 (64k-17)! (p. 4-246 Windows Ref) AFS 23-apr-91
                */
                return( 0 );
            }
            {
                HANDLE hmem;

                hmem = (HANDLE)GlobalHandle( seg );
                if( hmem == NULL ) {
                    return( 0 );
                }
                if( GlobalReAlloc( hmem, ((long)n) << 4,
                        __win_realloc_flags) == NULL ){
                    return( 0 );
                }
            }
#else
            if( TINY_ERROR( TinySetBlock( n, seg ) ) )          return( 0 );
#endif
            p->heaplen = n << 4;        /* put in new heap length */
            pfree = MK_FP( seg, p->freehead.prev );
            if( FP_OFF(pfree) + pfree->len != old_heaplen - TAG_SIZE*2 ) {
                /* last free entry not at end of the heap */
                /* add a new free entry to end of list */
                pnew = MK_FP( seg, old_heaplen - TAG_SIZE*2 );
                pnew->prev = FP_OFF(pfree);
                pnew->next = pfree->next;
                pfree->next = FP_OFF(pnew);
                p->freehead.prev = FP_OFF(pnew);
                p->numfree++;
                pfree = pnew;
            }
            pfree->len = p->heaplen - FP_OFF(pfree) - TAG_SIZE*2;
            if( pfree->len > p->largest_blk )  p->largest_blk = pfree->len;
            last_tag = MK_FP( seg, p->heaplen - TAG_SIZE*2 );
            *last_tag = END_TAG;
            last_tag[1] = 0;            /* link to next piece of near heap */
            return( 1 );                /* indicate segment was grown */
        }