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

Method mapNativeMemory

source/kernel/kmemory.cpp:719–742  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

717}
718
719U32 KMemory::mapNativeMemory(void* hostAddress, U32 size) {
720 U32 result = 0;
721 U32 offset = (U32)(((RAM_TYPE)hostAddress) & 0xFFF);
722 // ramPageAllocNative expect host address to be aligned to a page
723 if (offset) {
724 size += offset;
725 hostAddress = (U8*)hostAddress - offset;
726 }
727 U32 pageCount = (size + K_PAGE_SIZE - 1) >> K_PAGE_SHIFT;
728 BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(mutex);
729 if (!data->reserveAddress(ADDRESS_PROCESS_MMAP_START, pageCount + 2, &result, false, true, PAGE_MAPPED)) {
730 return 0;
731 }
732 result++; // guard page
733 for (U32 i = 0; i < pageCount; i++) {
734 MMU& mmu = data->mmu[result + i];
735 mmu.setFlags(PAGE_MAPPED | PAGE_READ | PAGE_WRITE);
736 RamPage ramPage = ramPageAllocNative((U8*)hostAddress + K_PAGE_SIZE * i);
737 mmu.setPage(this, result + i, PageType::Ram, ramPage);
738 data->onPageChanged(result + i);
739 ramPageRelease(ramPage); // setPage retains
740 }
741 return (result << K_PAGE_SHIFT) + offset;
742}
743
744U32 KMemory::ensureContinuousNative_unsafe(U32 page, U32 pageCount) {
745 BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(mutex);

Callers 2

mapBufferRangeFunction · 0.80
mapVkMemoryFunction · 0.80

Calls 6

ramPageAllocNativeFunction · 0.85
ramPageReleaseFunction · 0.85
reserveAddressMethod · 0.80
setPageMethod · 0.80
setFlagsMethod · 0.45
onPageChangedMethod · 0.45

Tested by

no test coverage detected