Skip to content

Commit 95604c7

Browse files
committed
vmm: allow changing page attributes after being mapped
1 parent c4cd4c0 commit 95604c7

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/include/kernel/memory.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ int vmmFree(uintptr_t, size_t);
6666
int vmmPageFault(uintptr_t, int); // the platform-specific page fault handler must call this
6767
uintptr_t vmmMMIO(uintptr_t, bool);
6868
int vmmPageStatus(uintptr_t, uintptr_t *);
69+
uintptr_t vmmSetFlags(uintptr_t, size_t, int);
70+
6971
void *sbrk(Thread *, intptr_t);

‎src/memory/virtual.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,26 @@ uintptr_t vmmMMIO(uintptr_t phys, bool cache) {
211211
} else {
212212
return 0;
213213
}
214+
}
215+
216+
/* vmmSetFlags(): sets the flags for a series of pages
217+
* params: base - base address
218+
* params: count - number of pages
219+
* params: flags - page attributes to set
220+
* returns: base address
221+
*/
222+
223+
uintptr_t vmmSetFlags(uintptr_t base, size_t count, int flags) {
224+
uintptr_t phys;
225+
int parsedFlags = PLATFORM_PAGE_PRESENT;
226+
if(flags & VMM_EXEC) parsedFlags |= PLATFORM_PAGE_EXEC;
227+
if(flags & VMM_USER) parsedFlags |= PLATFORM_PAGE_USER;
228+
if(flags & VMM_WRITE) parsedFlags |= PLATFORM_PAGE_WRITE;
229+
230+
for(size_t i = 0; i < count; i++) {
231+
if(vmmPageStatus(base + (i*PAGE_SIZE), &phys) & PLATFORM_PAGE_PRESENT)
232+
platformMapPage(base + (i*PAGE_SIZE), phys, parsedFlags);
233+
}
234+
235+
return base;
214236
}

0 commit comments

Comments
 (0)