This doesn't mean the data can't be changed by another thread, it just means the pointer will stay valid
| 659 | |
| 660 | // This doesn't mean the data can't be changed by another thread, it just means the pointer will stay valid |
| 661 | U8* KMemory::lockReadOnlyMemory(U32 address, U32 len) { |
| 662 | U32 pageIndex = address >> K_PAGE_SHIFT; |
| 663 | Page* page = data->getPage(pageIndex); |
| 664 | U32 offset = address & K_PAGE_MASK; |
| 665 | |
| 666 | // if we cross a page boundry then we will need to make a copy |
| 667 | if (len <= K_PAGE_SIZE - offset) { |
| 668 | return page->getRamPtr(&data->mmu[pageIndex], pageIndex, false, true, offset, len); |
| 669 | } |
| 670 | std::shared_ptr<LockedMemory> p = std::make_shared<LockedMemory>(); |
| 671 | p->p = new U8[len]; |
| 672 | p->len = len; |
| 673 | p->address = address; |
| 674 | p->readOnly = true; |
| 675 | memcpy(p->p, address, len); |
| 676 | BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(lockedMemoryMutex); |
| 677 | lockedMemory.set(p->p, p); |
| 678 | return p->p; |
| 679 | } |
| 680 | |
| 681 | void KMemory::unlockMemory(U8* lockedPointer) { |
| 682 | BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(lockedMemoryMutex); |
no test coverage detected