don't need to add a mutex, memory->mutex should be locked when call except for construction and execv (which should only have 1 thread)
| 124 | |
| 125 | // don't need to add a mutex, memory->mutex should be locked when call except for construction and execv (which should only have 1 thread) |
| 126 | void KMemoryData::allocPages(KThread* thread, U32 page, U32 pageCount, U8 permissions, FD fd, U64 offset, const std::shared_ptr<MappedFile>& mappedFile, const RamPage* ramPages) { |
| 127 | #ifdef _DEBUG |
| 128 | if (page + pageCount >= K_NUMBER_OF_PAGES) { |
| 129 | kpanic("KMemoryData::allocPages page out of bound"); |
| 130 | } |
| 131 | if (mappedFile && ramPages) { |
| 132 | kpanic("KMemoryData::allocPages mapped files should not contain ramPages"); |
| 133 | } |
| 134 | #endif |
| 135 | if (ramPages) { |
| 136 | for (U32 i = 0; i < pageCount; i++) { |
| 137 | mmu[page + i].setFlags(permissions); |
| 138 | this->mmu[page + i].setPage(memory, page + i, PageType::Ram, ramPages[i]); |
| 139 | onPageChanged(page + i); |
| 140 | } |
| 141 | } else if (mappedFile) { |
| 142 | if (offset & K_PAGE_MASK) { |
| 143 | kpanic("mmap: wasn't expecting the offset to be in the middle of a page"); |
| 144 | } |
| 145 | |
| 146 | for (U32 i = 0; i < pageCount; i++) { |
| 147 | mmu[page + i].setFlags(permissions); |
| 148 | this->mmu[page + i].setPage(memory, page + i, PageType::File, (RamPage)mappedFile->key); |
| 149 | onPageChanged(page + i); |
| 150 | } |
| 151 | } else { |
| 152 | for (U32 i = 0; i < pageCount; i++) { |
| 153 | mmu[page + i].setFlags(permissions); |
| 154 | this->mmu[page + i].setPage(memory, page + i, PageType::Ram, (RamPage)0); |
| 155 | onPageChanged(page + i); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | bool isAlignedNativePage(U32 page) { |
| 161 | U32 gran = Platform::getPageAllocationGranularity(); |
no test coverage detected