lib: c: implement munmap()
This commit is contained in:
@@ -41,5 +41,6 @@ extern void *mmap(
|
||||
int flags,
|
||||
int fd,
|
||||
off_t offset);
|
||||
extern int munmap(void *addr, size_t length);
|
||||
|
||||
#endif
|
||||
|
||||
34
lib/libc/io/unistd/munmap.c
Normal file
34
lib/libc/io/unistd/munmap.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/vm.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
int munmap(void *addr, size_t length)
|
||||
{
|
||||
kern_status_t status = KERN_OK;
|
||||
kern_handle_t self = KERN_HANDLE_INVALID,
|
||||
address_space = KERN_HANDLE_INVALID;
|
||||
|
||||
status = task_self(&self);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(EPERM);
|
||||
}
|
||||
|
||||
status = task_get_address_space(self, &address_space);
|
||||
kern_handle_close(self);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(EPERM);
|
||||
}
|
||||
|
||||
status = address_space_unmap(address_space, (virt_addr_t)addr, length);
|
||||
|
||||
kern_handle_close(address_space);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
return __set_errno(SUCCESS);
|
||||
}
|
||||
Reference in New Issue
Block a user