本文整理汇总了C++中MemoryContext类的典型用法代码示例。如果您正苦于以下问题:C++ MemoryContext类的具体用法?C++ MemoryContext怎么用?C++ MemoryContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemoryContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: FATAL
Kernel::Result Kernel::loadBootProcess(BootImage *image, Address imagePAddr, Size index)
{
Address imageVAddr = (Address) image, args;
Size args_size = ARGV_SIZE;
BootSymbol *program;
BootSegment *segment;
Process *proc;
char *vaddr;
Arch::MemoryMap map;
// Point to the program and segments table
program = &((BootSymbol *) (imageVAddr + image->symbolTableOffset))[index];
segment = &((BootSegment *) (imageVAddr + image->segmentsTableOffset))[program->segmentsOffset];
// Ignore non-BootProgram entries
if (program->type != BootProgram)
return InvalidBootImage;
// Create process
proc = m_procs->create(program->entry, map);
if (!proc)
{
FATAL("failed to create boot program: " << program->name);
return ProcessError;
}
proc->setState(Process::Ready);
// Obtain process memory
MemoryContext *mem = proc->getMemoryContext();
// Map program segment into it's virtual memory
for (Size i = 0; i < program->segmentsCount; i++)
{
for (Size j = 0; j < segment[i].size; j += PAGESIZE)
{
mem->map(segment[i].virtualAddress + j,
imagePAddr + segment[i].offset + j,
Memory::User |
Memory::Readable |
Memory::Writable |
Memory::Executable);
}
}
// Map program arguments into the process
// TODO: move into the high memory???
m_alloc->allocateLow(args_size, &args);
mem->map(ARGV_ADDR, args, Memory::User | Memory::Readable | Memory::Writable);
// Copy program arguments
vaddr = (char *) m_alloc->toVirtual(args);
MemoryBlock::set(vaddr, 0, PAGESIZE);
MemoryBlock::copy(vaddr, program->name, ARGV_SIZE);
// Done
NOTICE("loaded: " << program->name);
return Success;
}
示例3: writeRemoveLog
LsnType MRecords::writeRemoveLog(Session *session, LogType logType, TrxId txnId, LsnType preLsn, RowId rid, RowId rollBackId, u8 tableIndex) {
LsnType lsn = 0;
MemoryContext *ctx = session->getMemoryContext();
McSavepoint msp(ctx);
size_t size = sizeof(txnId) + sizeof(preLsn) + sizeof(rid) + sizeof(rollBackId) + sizeof(tableIndex);
byte *buf = (byte *)ctx->alloc(size);
Stream s(buf, size);
s.write(txnId);
s.write(preLsn);
s.writeRid(rid);
s.writeRid(rollBackId);
s.write(tableIndex);
lsn = session->getTrans()->writeTNTLog(logType, (*m_tableDef)->m_id, buf, s.getSize());
return lsn;
}
示例4: InitializeMemoryContext
bool WindowsOperatingSystem::InitializeMemoryContext(MemoryContext& rMemCtxt) const
{
// TODO: create a fake _TEB/_PEB
if (rMemCtxt.AllocateMemory(0x7fdf0000, 0x1000, nullptr) == false)
return false;
return true;
}
示例5: writeUpdateLog
LsnType MRecords::writeUpdateLog(Session *session, LogType logType, TrxId txnId, LsnType preLsn, RowId rid, RowId rollBackId, u8 tableIndex, SubRecord *update) {
LsnType lsn = 0;
MemoryContext *ctx = session->getMemoryContext();
McSavepoint msp(ctx);
size_t size = sizeof(txnId) + sizeof(preLsn) + sizeof(rid) + sizeof(rollBackId) + sizeof(tableIndex);
size += RecordOper::getSubRecordSerializeSize(*m_tableDef, update, false);
byte *buf = (byte *)ctx->alloc(size);
Stream s(buf, size);
s.write(txnId);
s.write(preLsn);
s.writeRid(rid);
s.writeRid(rollBackId);
s.write(tableIndex);
RecordOper::serializeSubRecordMNR(&s, *m_tableDef, update, false);
lsn = session->getTrans()->writeTNTLog(logType, (*m_tableDef)->m_id, buf, s.getSize());
return lsn;
}
示例6: unmap
IO::Result IO::unmap()
{
if (!isKernel)
{
if (VMCtl(SELF, UnMap, &m_range) != API::Success)
return MapFailure;
}
else
{
MemoryContext *ctx = MemoryContext::getCurrent();
if (!ctx)
return MapFailure;
if (ctx->unmapRange(&m_range) != MemoryContext::Success)
return MapFailure;
}
return Success;
}
示例7:
template<> TIterator5<sc_type, sc_type, Addr, sc_type, sc_type>::TIterator5(MemoryContext const & context, sc_type const & p1, sc_type const & p2, Addr const & p3, sc_type const & p4, sc_type const & p5)
{
mIterator = sc_iterator5_a_a_f_a_a_new(context.getRealContext(), p1, p2, p3.mRealAddr, p4, p5);
}
示例8: pool
void MemoryContextTestCase::testMemoryContextUsePool() {
uint poolSize = 4096;
uint reservedPages = 1;
PagePool pool(1, NTSE_PAGE_SIZE);
CommonMemPool commonMemPool(poolSize, &pool);
pool.registerUser(&commonMemPool);
pool.init();
MemoryContext *mc = new MemoryContext(&commonMemPool, reservedPages);
u64 firstSavepoint = mc->setSavepoint();
int chunkSize = 700;
void *first = mc->alloc(chunkSize);
memset(first, 0, chunkSize); // 便于valgrind检测有无越界写问题
for (int i = 0; i < 12; i++) {
void *chunk = mc->alloc(chunkSize);
memset(chunk, 0, chunkSize);
}
u64 savepoint = mc->setSavepoint();
void *firstAfterSavepoint = mc->alloc(chunkSize);
for (int i = 0; i < 12; i++) {
void *chunk = mc->alloc(chunkSize);
memset(chunk, 0, chunkSize);
}
// 分配超出页面大小的块
for (int i = 0; i < 3; i++)
NTSE_ASSERT(NULL == mc->alloc(NTSE_PAGE_SIZE + 1));
mc->resetToSavepoint(savepoint);
CPPUNIT_ASSERT(mc->setSavepoint() == savepoint);
CPPUNIT_ASSERT(mc->alloc(chunkSize) == firstAfterSavepoint);
// 测试内存池内存不足
mc->reset();
for (int i = 0; i < poolSize; i++) {
int cs = NTSE_PAGE_SIZE / 2 + 100;
void *data = mc->alloc(cs);
NTSE_ASSERT(NULL != data);
memset(data, 0, cs);
}
NTSE_ASSERT(poolSize == commonMemPool.getCurrentSize());
for (int i = 0; i < 10; i++) {
int cs = NTSE_PAGE_SIZE / 2 + 100;
void *data = mc->alloc(cs);
NTSE_ASSERT(NULL == data);
NTSE_ASSERT(poolSize == commonMemPool.getCurrentSize());
}
mc->reset();
CPPUNIT_ASSERT(mc->setSavepoint() == firstSavepoint);
CPPUNIT_ASSERT(mc->alloc(chunkSize) == first); // 第一页始终保持因此地址不变
mc->resetToSavepoint(0);
CPPUNIT_ASSERT(mc->setSavepoint() == firstSavepoint);
CPPUNIT_ASSERT(mc->alloc(chunkSize) == first);
// 测试getMemUsage
{
mc->reset();
for (int i = 0; i < 12; i++)
mc->alloc(chunkSize);
CPPUNIT_ASSERT(mc->getMemUsage() > chunkSize * 12);
u64 muBak = mc->getMemUsage();
u64 savepoint = mc->setSavepoint();
for (int i = 0; i < 12; i++)
mc->alloc(chunkSize);
CPPUNIT_ASSERT(mc->getMemUsage() > chunkSize * 24);
mc->resetToSavepoint(savepoint);
CPPUNIT_ASSERT(mc->getMemUsage() == muBak);
mc->reset();
CPPUNIT_ASSERT(mc->getMemUsage() < muBak);
}
delete mc;
mc = NULL;
// 测试预留页面数
for (uint i = 1; i <= 10; i++) {
mc = new MemoryContext(&commonMemPool, i);
uint lastUsedPages = commonMemPool.getCurrentSize();
for (uint j = 0; j < i; j++) {
int cs = NTSE_PAGE_SIZE / 2 + 100;
void *data = mc->alloc(cs);
memset(data, 0, cs);
}
NTSE_ASSERT(lastUsedPages == commonMemPool.getCurrentSize());
mc->reset();
delete mc;
mc = NULL;
}
}
示例9: MemoryContext
void MemoryContextTestCase::testMemoryContext() {
MemoryContext *mc = new MemoryContext(4096, 1);
CPPUNIT_ASSERT(mc->setSavepoint() == 0);
int chunkSize = 700;
for (int i = 0; i < 12; i++) {
void *chunk = mc->alloc(chunkSize);
memset(chunk, 0, chunkSize);
}
u64 savepoint = mc->setSavepoint();
CPPUNIT_ASSERT(savepoint == 12);
for (int i = 0; i < 12; i++) {
void *chunk = mc->alloc(chunkSize);
memset(chunk, 0, chunkSize);
}
mc->resetToSavepoint(savepoint);
CPPUNIT_ASSERT(mc->setSavepoint() == savepoint);
mc->reset();
CPPUNIT_ASSERT(mc->setSavepoint() == 0);
mc->alloc(chunkSize);
mc->resetToSavepoint(0);
CPPUNIT_ASSERT(mc->setSavepoint() == 0);
// 测试getMemUsage
{
mc->reset();
for (int i = 0; i < 12; i++)
mc->alloc(chunkSize);
CPPUNIT_ASSERT(mc->getMemUsage() == chunkSize * 12);
u64 muBak = mc->getMemUsage();
u64 savepoint = mc->setSavepoint();
for (int i = 0; i < 12; i++)
mc->alloc(chunkSize);
CPPUNIT_ASSERT(mc->getMemUsage() == chunkSize * 24);
mc->resetToSavepoint(savepoint);
CPPUNIT_ASSERT(mc->getMemUsage() == muBak);
mc->reset();
CPPUNIT_ASSERT(mc->getMemUsage() == 0);
}
delete mc;
}
示例10: 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;
}