MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / lockReadWriteMemory

Method lockReadWriteMemory

source/kernel/kmemory.cpp:692–713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

690}
691
692U8* KMemory::lockReadWriteMemory(U32 address, U32 len) {
693 U32 pageIndex = address >> K_PAGE_SHIFT;
694 Page* page = data->getPage(pageIndex);
695 U32 offset = address & K_PAGE_MASK;
696
697 // if we cross a page boundry then we will need to make a copy
698 if (len <= K_PAGE_SIZE - offset) {
699 U8* result = page->getRamPtr(&data->mmu[pageIndex], pageIndex, true, true, offset, len);
700 if (result) {
701 return result;
702 }
703 }
704 std::shared_ptr<LockedMemory> p = std::make_shared<LockedMemory>();
705 p->p = new U8[len];
706 p->len = len;
707 p->address = address;
708 p->readOnly = false;
709 memcpy(p->p, address, len);
710 BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(lockedMemoryMutex);
711 lockedMemory.set(p->p, p);
712 return p->p;
713}
714
715void KMemory::unmapNativeMemory(U32 address, U32 size) {
716 unmap(address - K_PAGE_SIZE, size + 2 * K_PAGE_SIZE);

Calls 4

memcpyFunction · 0.85
getPageMethod · 0.45
getRamPtrMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected