Example #1
0
/*
 * checkPointMem - checkpoint up to max bytes of memory
 */
static bool checkPointMem( unsigned max )
{
    dos_mem_block       *mem, *start, *end, *next, *chk;
    unsigned            size, psp;

    if( max == 0 ) {
        return( false );
    }
    psp = TinyGetPSP();
    start = MK_FP( psp - 1, 0 );
    if( start->chain == END_OF_CHAIN ) {
        return( false );
    }
    start = NEXT_BLOCK( start );
    mem = start;
    for( ;; ) {
        if( mem->owner == 0 && mem->size >= max ) {
            return( false );
        }
        if( mem->chain == END_OF_CHAIN ) {
            break;
        }
        mem = NEXT_BLOCK( mem );
    }
    end = NEXT_BLOCK( mem );
    size = FP_SEG( end ) - FP_SEG( start );
    if( size < 0x100 ) {
        return( false );
    }

    if( size > max ) {
        size = max;
    }
    chk = MK_FP( FP_SEG( end ) - size - 1, 0 );
    mem = start;
    for( ;; ) {
        next = NEXT_BLOCK( mem );
        if( FP_SEG( next ) > FP_SEG( chk ) ) {
            break;
        }
        mem = next;
    }

    savePtrMem = mem;
    memcpy( &saveMem, mem, sizeof( dos_mem_block ) );
    savePtrChk = chk;

    next = chk;
    while( FP_SEG( next ) < FP_SEG( end ) ) {
        size = FP_SEG( end ) - FP_SEG( next );
        if( !chkWrite( next, &size ) ) {
            cleanUp();
            return( false );
        }
        next = MK_FP( FP_SEG( next ) + size, 0 );
    }
    chkClose();
    mem->chain = MEMORY_BLOCK;
    mem->size = FP_SEG( chk ) - FP_SEG( mem ) - 1;
    chk->size = FP_SEG( end ) - FP_SEG( chk ) - 1;
    chk->chain = END_OF_CHAIN;
    chk->owner = 0;
    return( true );
}
Example #2
0
bool CheckPointMem( unsigned max, char *f_buff )
{
    dos_mem_block   *mem;
    dos_mem_block   *start;
    dos_mem_block   *end;
    dos_mem_block   *next;
    dos_mem_block   *chk;
    tiny_ret_t      rc;
    tiny_handle_t   hdl;
    unsigned        size;
    unsigned        bytes;
    unsigned        psp;
    char            *p;

    if( max == 0 ) return( FALSE );
    ChkFile = f_buff;
    psp = TinyGetPSP();
    start = MK_FP( psp - 1, 0 );
    while( start->owner == psp ) {
        if( start->chain == END_OF_CHAIN ) return( FALSE );
//        start = NEXT_BLOCK( start );
        start = MK_FP( (FP_SEG( start ) + (start)->size + 1), 0 );
    }
    mem = start;
    for( ;; ) {
        if( mem->owner == 0 && mem->size >= max ) return( FALSE );
        if(  mem->chain == END_OF_CHAIN ) break;
//        mem = NEXT_BLOCK( mem );
        mem = MK_FP( (FP_SEG( mem ) + (mem)->size + 1), 0 );
    }
//    end = NEXT_BLOCK( mem );
      end = MK_FP( (FP_SEG( mem ) + (mem)->size + 1), 0 );
    size = FP_SEG( end ) - FP_SEG( start );
    if( size < 0x1000 ) return( FALSE );
    *f_buff++ = TinyGetCurrDrive() + 'A';
    *f_buff++ = ':';
    *f_buff++ = '\\';
    rc = TinyFarGetCWDir( (char __far *)f_buff, 0 );
    if( TINY_ERROR( rc ) )
        return( FALSE );
    while( *f_buff != 0 ) ++f_buff;
    if( f_buff[-1] == '\\' ) {
        --f_buff;
    } else {
        *f_buff++ = '\\';
    }
    for( p = CHECK_FILE; *f_buff = *p; ++p, ++f_buff ) {}
    rc = TinyCreate( ChkFile, TIO_NORMAL );
    if( TINY_ERROR( rc ) )
        return( FALSE );
    hdl = TINY_INFO( rc );
    if( size > max ) size = max;
    chk = MK_FP( FP_SEG( end ) - size - 1, 0 );
    mem = start;
    for( ;; ) {
//        next = NEXT_BLOCK( mem );
        next = MK_FP( (FP_SEG( mem ) + (mem)->size + 1), 0 );
        if( FP_SEG( next ) > FP_SEG( chk ) ) break;
        mem = next;
    }
    if( !PUT_ITEM( mem ) || !PUT_ITEM( *mem ) || !PUT_ITEM( chk ) ) {
        TinyClose( hdl );
        Cleanup();
        return( FALSE );
    }
    next = chk;
    while( FP_SEG( next ) < FP_SEG( end ) ) {
        size = FP_SEG( end ) - FP_SEG( next );
        if( size >= 0x1000 ) size = 0x0800;
        bytes = size << 4;
        if( TinyWrite( hdl, next, bytes ) != bytes ) {
            TinyClose( hdl );
            Cleanup();
            return( FALSE );
        }
        next = MK_FP( FP_SEG( next ) + size, 0 );
    }
    TinyClose( hdl );
    mem->chain = MEMORY_BLOCK;
    mem->size = FP_SEG( chk ) - FP_SEG( mem ) - 1;
    chk->size = FP_SEG( end ) - FP_SEG( chk ) - 1;
    chk->chain = END_OF_CHAIN;
    chk->owner = 0;
    return( TRUE );
}