当前位置: 首页>>代码示例>>C++>>正文


C++ MemoryRegion::endAddress方法代码示例

本文整理汇总了C++中MemoryRegion::endAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryRegion::endAddress方法的具体用法?C++ MemoryRegion::endAddress怎么用?C++ MemoryRegion::endAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemoryRegion的用法示例。


在下文中一共展示了MemoryRegion::endAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: return

//! Returns true if the address filter overlaps \a region.
bool StExecutableImage::AddressFilter::matchesMemoryRegion(const MemoryRegion &region) const
{
    uint32_t firstByte = region.m_address;   // first byte occupied by this region
    uint32_t lastByte = region.endAddress(); // last used byte in this region
    return (firstByte >= m_fromAddress && firstByte <= m_toAddress) ||
           (lastByte >= m_fromAddress && lastByte <= m_toAddress);
}
开发者ID:UltimateHackingKeyboard,项目名称:KBOOT_2.0.0,代码行数:8,代码来源:StExecutableImage.cpp

示例2: cropRegionToFilter

//! There are several possible cases here:
//!     - No overlap at all. Nothing is done.
//!
//!     - All of the memory region is matched by the \a filter. The region is
//!         removed from #StExecutableImage::m_image and its data memory freed.
//!
//!     - The remaining portion of the region is one contiguous chunk. In this
//!         case, \a region is simply modified.
//!
//!     - The region is split in the middle by the filter. The original \a region
//!         is modified to match the first remaining chunk. And a new #StExecutableImage::MemoryRegion
//!         instance is created to hold the other leftover piece.
void StExecutableImage::cropRegionToFilter(MemoryRegion &region, const AddressFilter &filter)
{
    uint32_t firstByte = region.m_address;   // first byte occupied by this region
    uint32_t lastByte = region.endAddress(); // last used byte in this region

    // compute new address range
    uint32_t cropFrom = filter.m_fromAddress;
    if (cropFrom < firstByte)
    {
        cropFrom = firstByte;
    }

    uint32_t cropTo = filter.m_toAddress;
    if (cropTo > lastByte)
    {
        cropTo = lastByte;
    }

    // is there actually a match?
    if (cropFrom > filter.m_toAddress || cropTo < filter.m_fromAddress)
    {
        // nothing to do, so bail
        return;
    }

    printf("Deleting region 0x%08x-0x%08x\n", cropFrom, cropTo);

    // handle if the entire region is to be deleted
    if (cropFrom == firstByte && cropTo == lastByte)
    {
        delete[] region.m_data;
        region.m_data = NULL;
        m_image.remove(region);
    }

    // there is at least a little of the original region remaining
    uint32_t newLength = cropTo - cropFrom + 1;
    uint32_t leftoverLength = lastByte - cropTo;
    uint8_t *oldData = region.m_data;

    // update the region
    region.m_address = cropFrom;
    region.m_length = newLength;

    // crop data buffer for text regions
    if (region.m_type == TEXT_REGION && oldData)
    {
        region.m_data = new uint8_t[newLength];
        memcpy(region.m_data, &oldData[cropFrom - firstByte], newLength);

        // dispose of old data
        delete[] oldData;
    }

    // create a new region for any part of the original region that was past
    // the crop to address. this will happen if the filter range falls in the
    // middle of the region.
    if (leftoverLength)
    {
        MemoryRegion newRegion;
        newRegion.m_type = region.m_type;
        newRegion.m_flags = region.m_flags;
        newRegion.m_address = cropTo + 1;
        newRegion.m_length = leftoverLength;

        if (region.m_type == TEXT_REGION && oldData)
        {
            newRegion.m_data = new uint8_t[leftoverLength];
            memcpy(newRegion.m_data, &oldData[cropTo - firstByte + 1], leftoverLength);
        }

        insertOrMergeRegion(newRegion);
    }
}
开发者ID:UltimateHackingKeyboard,项目名称:KBOOT_2.0.0,代码行数:86,代码来源:StExecutableImage.cpp


注:本文中的MemoryRegion::endAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。