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

Method mprotect

source/kernel/kmemory.cpp:186–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186U32 KMemory::mprotect(KThread* thread, U32 address, U32 len, U32 prot) {
187 bool read = (prot & K_PROT_READ) != 0;
188 bool write = (prot & K_PROT_WRITE) != 0;
189 bool exec = (prot & K_PROT_EXEC) != 0;
190 U32 pageStart = address >> K_PAGE_SHIFT;
191 U32 pageCount = (len + K_PAGE_SIZE - 1) >> K_PAGE_SHIFT;
192 U32 permissions = 0;
193
194 if (write)
195 permissions |= PAGE_WRITE;
196 if (read)
197 permissions |= PAGE_READ;
198 if (exec)
199 permissions |= PAGE_EXEC;
200
201 for (U32 i = pageStart; i < pageStart + pageCount; i++) {
202 if (!isPageMapped(i)) {
203 return -K_ENOMEM;
204 }
205 }
206 BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(mutex);
207 for (U32 i = pageStart; i < pageStart + pageCount; i++) {
208 this->data->protectPage(thread, i, permissions);
209 }
210 return 0;
211}
212
213U32 KMemory::mremap(KThread* thread, U32 oldaddress, U32 oldsize, U32 newsize, U32 flags) {
214 if (flags > 1) {

Callers 2

syscall_mprotectFunction · 0.80
setupStackMethod · 0.80

Calls 1

protectPageMethod · 0.80

Tested by

no test coverage detected