45 lines
981 B
C
45 lines
981 B
C
#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);
|
|
|
|
if (status != KERN_OK) {
|
|
kern_handle_close(address_space);
|
|
return __set_errno(__errno_from_kern_status(status));
|
|
}
|
|
|
|
status = address_space_release(
|
|
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);
|
|
}
|