HelenOS sources
This source file includes following definitions.
- user_create
- user_destroy
- user_is_resizable
- user_is_shareable
- user_page_fault
- user_frame_free
#include <mm/as.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <abi/mm/as.h>
#include <abi/ipc/methods.h>
#include <ipc/sysipc.h>
#include <synch/mutex.h>
#include <typedefs.h>
#include <align.h>
#include <assert.h>
#include <errno.h>
#include <log.h>
#include <str.h>
#include <str_error.h>
static bool user_create(as_area_t *);
static void user_destroy(as_area_t *);
static bool user_is_resizable(as_area_t *);
static bool user_is_shareable(as_area_t *);
static int user_page_fault(as_area_t *, uintptr_t, pf_access_t);
static void user_frame_free(as_area_t *, uintptr_t, uintptr_t);
mem_backend_t user_backend = {
.create = user_create,
.resize = NULL,
.share = NULL,
.destroy = user_destroy,
.is_resizable = user_is_resizable,
.is_shareable = user_is_shareable,
.page_fault = user_page_fault,
.frame_free = user_frame_free,
.create_shared_data = NULL,
.destroy_shared_data = NULL
};
bool user_create(as_area_t *area)
{
return true;
}
void user_destroy(as_area_t *area)
{
return;
}
bool user_is_resizable(as_area_t *area)
{
return false;
}
bool user_is_shareable(as_area_t *area)
{
return false;
}
int user_page_fault(as_area_t *area, uintptr_t upage, pf_access_t access)
{
assert(page_table_locked(AS));
assert(mutex_locked(&area->lock));
assert(IS_ALIGNED(upage, PAGE_SIZE));
if (!as_area_check_access(area, access))
return AS_PF_FAULT;
as_area_pager_info_t *pager_info = &area->backend_data.pager_info;
ipc_data_t data = { };
ipc_set_imethod(&data, IPC_M_PAGE_IN);
ipc_set_arg1(&data, upage - area->base);
ipc_set_arg2(&data, PAGE_SIZE);
ipc_set_arg3(&data, pager_info->id1);
ipc_set_arg4(&data, pager_info->id2);
ipc_set_arg5(&data, pager_info->id3);
errno_t rc = ipc_req_internal(pager_info->pager, &data, (sysarg_t) true);
if (rc != EOK) {
log(LF_USPACE, LVL_FATAL,
"Page-in request for page %#" PRIxPTR
" at pager %p failed with error %s.",
upage, pager_info->pager, str_error_name(rc));
return AS_PF_FAULT;
}
if (ipc_get_retval(&data) != EOK)
return AS_PF_FAULT;
uintptr_t frame = ipc_get_arg1(&data);
page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
if (!used_space_insert(&area->used_space, upage, 1))
panic("Cannot insert used space.");
return AS_PF_OK;
}
void user_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
{
assert(page_table_locked(area->as));
assert(mutex_locked(&area->lock));
pfn_t pfn = ADDR2PFN(frame);
if (find_zone(pfn, 1, 0) != (size_t) -1) {
frame_free(frame, 1);
} else {
}
}
HelenOS homepage, sources at GitHub