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


C++ Area::GetProtection方法代码示例

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


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

示例1: HandleFault

status_t AddressSpace::HandleFault(unsigned int va, bool write, bool user)
{
	va &= ~(PAGE_SIZE - 1); // Round down to a page boundry.

	fAreaLock.LockRead();
	int lastChangeCount = fChangeCount;
	Area *area = static_cast<Area*>(fAreas.Find(va));
	if (area == 0) {
		fAreaLock.UnlockRead();
		return E_BAD_ADDRESS;
	}

	PageProtection protection = area->GetProtection();
	if ((user && write && !(protection & USER_WRITE))
		|| (user && !write && !(protection & USER_READ))
		|| (!user && write && !(protection & SYSTEM_WRITE))
		|| (!user && !write && !(protection & SYSTEM_READ))) {
		fAreaLock.UnlockRead();
		return E_NOT_ALLOWED;
	}

	PageCache *cache = area->GetPageCache();
	if (cache == 0) {
		fAreaLock.UnlockRead();
		return E_NOT_ALLOWED;
	}

	bool copy = cache->IsCopy();
	cache->AcquireRef();
	fAreaLock.UnlockRead();
	off_t offset = va - area->GetBaseAddress() + area->GetCacheOffset();
	Page *page = cache->GetPage(offset, write && cache->IsCopy());
	cache->ReleaseRef();
	if (page == 0)
		return E_IO;

	fAreaLock.LockRead();
	if (lastChangeCount != fChangeCount) {
		// Changes have occured to this address.  Make sure that
		// the area hasn't changed underneath the fault handler.
		Area *newArea = static_cast<Area*>(fAreas.Find(va));
		if (newArea != area || newArea->GetPageCache() != cache ||
			newArea->GetCacheOffset() != offset)
			fAreaLock.UnlockRead();
			return E_BAD_ADDRESS;
	}

	// If this is a read from copy-on-write page, it is shared with the
	// original cache.  Mark it read only.
	if (copy && !write)
		protection &= ~(USER_WRITE | SYSTEM_WRITE);

	fPhysicalMap->Map(va, page->GetPhysicalAddress(), protection);
	fAreaLock.UnlockRead();
	AtomicAdd(&fFaultCount, 1);
	return E_NO_ERROR;
}
开发者ID:FFalcon,项目名称:jbushOS,代码行数:57,代码来源:AddressSpace.cpp


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