libc: implement private/shared mapping support

This commit is contained in:
2026-04-21 21:15:27 +01:00
parent 70e990a885
commit 1c6ece7b55
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -25,6 +25,21 @@ static vm_prot_t vm_prot_from_mmap_prot(int prot)
return vm_prot;
}
static vm_flags_t vm_flags_from_mmap_flags(int flags)
{
vm_flags_t out = 0;
if (flags & MAP_PRIVATE) {
out |= VM_PRIVATE;
}
if (flags & (MAP_SHARED | MAP_SHARED_VALIDATE)) {
out |= VM_SHARED;
}
return out;
}
static int get_vmo_anon(
int fd,
int prot,
@@ -109,6 +124,7 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
kern_status_t status = KERN_OK;
kern_handle_t self = KERN_HANDLE_INVALID,
address_space = KERN_HANDLE_INVALID;
vm_flags_t vm_flags = vm_flags_from_mmap_flags(flags);
status = task_self(&self);
if (status != KERN_OK) {
@@ -146,6 +162,7 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
vmo,
offset,
length,
vm_flags,
vm_prot,
&map_address);
} else {
@@ -155,6 +172,7 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
vmo,
offset,
length,
vm_flags,
vm_prot,
&map_address);
}
+1
View File
@@ -79,6 +79,7 @@ static kern_status_t expand_heap(heap_t *heap)
vmo,
0,
HEAP_EXPAND_INCREMENT,
VM_PRIVATE,
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_USER,
&base);