Improved kernel mmap support
This commit is contained in:
parent
e1b917e4c2
commit
4115a2099b
@ -1,5 +1,7 @@
|
||||
#include <memory.h>
|
||||
#include <debug.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
|
||||
static long _brk = KERNEL_BRK0;
|
||||
static long _mmap = KERNEL_MMAP;
|
||||
@ -33,14 +35,22 @@ long k_mmap(
|
||||
|
||||
if(fd != -1)
|
||||
PANIC("Unknown mmap request\n");
|
||||
long retval = _mmap;
|
||||
while(length > 0) {
|
||||
long pos = (flags & MAP_FIXED) ? addr : _mmap;
|
||||
long retval = pos;
|
||||
uint64_t p;
|
||||
while(length >= 0) {
|
||||
p = pmm_alloc();
|
||||
vmm_set_page(kernel_P4,
|
||||
_mmap, pmm_alloc(),
|
||||
pos, p,
|
||||
PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT
|
||||
);
|
||||
_mmap += PAGE_SIZE;
|
||||
if(flags & MAP_ANONYMOUS) {
|
||||
memset((void *)pos, 0, PAGE_SIZE);
|
||||
}
|
||||
pos += PAGE_SIZE;
|
||||
length -= PAGE_SIZE;
|
||||
}
|
||||
if(!(flags & MAP_FIXED))
|
||||
_mmap = pos;
|
||||
return retval;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user