本文整理汇总了C++中MemoryContext::findFree方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryContext::findFree方法的具体用法?C++ MemoryContext::findFree怎么用?C++ MemoryContext::findFree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryContext
的用法示例。
在下文中一共展示了MemoryContext::findFree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: map
IO::Result IO::map(Address phys, Size size, Memory::Access access)
{
m_range.virt = 0;
m_range.phys = phys;
m_range.access = access;
m_range.size = size;
if (!isKernel)
{
if (VMCtl(SELF, Map, &m_range) != API::Success)
return MapFailure;
}
else
{
m_range.access &= ~Memory::User;
MemoryContext *ctx = MemoryContext::getCurrent();
if (!ctx)
return MapFailure;
if (ctx->findFree(size, MemoryMap::KernelPrivate, &m_range.virt) != MemoryContext::Success)
return OutOfMemory;
if (ctx->map(m_range.virt, phys, m_range.access) != MemoryContext::Success)
return MapFailure;
}
m_base = m_range.virt;
return Success;
}
示例2: VMCopyHandler
Error VMCopyHandler(ProcessID procID, API::Operation how, Address ours,
Address theirs, Size sz)
{
ProcessManager *procs = Kernel::instance->getProcessManager();
Process *proc;
Address paddr, vaddr;
Size bytes = 0, pageOff, total = 0;
// Find the corresponding Process
if (procID == SELF)
proc = procs->current();
else if (!(proc = procs->get(procID)))
return API::NotFound;
// TODO: Verify memory addresses
MemoryContext *local = procs->current()->getMemoryContext();
MemoryContext *remote = proc->getMemoryContext();
// Keep on going until all memory is processed
while (total < sz)
{
/* Update variables. */
if (how == API::ReadPhys)
paddr = theirs & PAGEMASK;
else if (remote->lookup(theirs, &paddr) != MemoryContext::Success)
return API::AccessViolation;
pageOff = theirs & ~PAGEMASK;
bytes = (PAGESIZE - pageOff) < (sz - total) ?
(PAGESIZE - pageOff) : (sz - total);
/* Valid address? */
if (!paddr) break;
// Map their address into our local address space
if (local->findFree(PAGESIZE, MemoryMap::KernelPrivate, &vaddr) != MemoryContext::Success)
return API::RangeError;
local->map(vaddr, paddr, Memory::Readable | Memory::Writable);
/* Process the action appropriately. */
switch (how)
{
case API::Read:
case API::ReadPhys:
MemoryBlock::copy((void *)ours, (void *)(vaddr + pageOff), bytes);
break;
case API::Write:
MemoryBlock::copy((void *)(vaddr + pageOff), (void *)ours, bytes);
break;
default:
;
}
// Unmap
local->unmap(vaddr);
// Update counters
ours += bytes;
theirs += bytes;
total += bytes;
}
return total;
}