Esempio n. 1
0
void PatchFsMethods(void)
{
    static uint8_t ucFsMethodsPatched = 0;
    if(!ucFsMethodsPatched)
    {
        ucFsMethodsPatched = 1;
        /* Patch branches to it. */
        int len = sizeof(fs_methods) / sizeof(struct fs_magic_t);
        while (len--) {
            unsigned int real_addr = (unsigned int)fs_methods[len].real;
            unsigned int repl_addr = (unsigned int)fs_methods[len].replacement;

            unsigned int replace_instr = 0x48000002 | (repl_addr & 0x03fffffc);

            if(*(volatile unsigned int *)(0xC1000000 + real_addr) != replace_instr) {
                // in the real function, replace the "mflr r0" instruction by a jump to the replacement function
                *(volatile unsigned int *)(0xC1000000 + real_addr) = replace_instr;
                FlushBlock((0xC1000000 + real_addr));
            }
        }
    }
}
CPLErr GDALArrayBandBlockCache::FlushCache()
{
    FreeDanglingBlocks();

    CPLErr eGlobalErr = poBand->eFlushBlockErr;

/* -------------------------------------------------------------------- */
/*      Flush all blocks in memory ... this case is without subblocking.*/
/* -------------------------------------------------------------------- */
    if( !bSubBlockingActive )
    {
        for( int iY = 0; iY < poBand->nBlocksPerColumn; iY++ )
        {
            for( int iX = 0; iX < poBand->nBlocksPerRow; iX++ )
            {
                if( u.papoBlocks[iX + iY*poBand->nBlocksPerRow] != NULL )
                {
                    CPLErr    eErr;

                    eErr = FlushBlock( iX, iY, eGlobalErr == CE_None );

                    if( eErr != CE_None )
                        eGlobalErr = eErr;
                }
            }
        }
    }

/* -------------------------------------------------------------------- */
/*      With subblocking.  We can short circuit missing subblocks.      */
/* -------------------------------------------------------------------- */
    else
    {
        int iSBX, iSBY;

        for( iSBY = 0; iSBY < nSubBlocksPerColumn; iSBY++ )
        {
            for( iSBX = 0; iSBX < nSubBlocksPerRow; iSBX++ )
            {
                int nSubBlock = iSBX + iSBY * nSubBlocksPerRow;
            
                GDALRasterBlock **papoSubBlockGrid =  u.papapoBlocks[nSubBlock];

                if( papoSubBlockGrid == NULL )
                    continue;

                for( int iY = 0; iY < SUBBLOCK_SIZE; iY++ )
                {
                    for( int iX = 0; iX < SUBBLOCK_SIZE; iX++ )
                    {
                        if( papoSubBlockGrid[iX + iY * SUBBLOCK_SIZE] != NULL )
                        {
                            CPLErr eErr;

                            eErr = FlushBlock( iX + iSBX * SUBBLOCK_SIZE, 
                                            iY + iSBY * SUBBLOCK_SIZE,
                                            eGlobalErr == CE_None );
                            if( eErr != CE_None )
                                eGlobalErr = eErr;
                        }
                    }
                }

                // We might as well get rid of this grid chunk since we know 
                // it is now empty.
                u.papapoBlocks[nSubBlock] = NULL;
                CPLFree( papoSubBlockGrid );
            }
        }
    }

    WaitKeepAliveCounter();

    return( eGlobalErr );
}