mirror of
https://github.com/drasko/codezero.git
synced 2026-01-18 22:03:16 +01:00
User pointer validity checks.
Added routines that check whether a user pointer is accessible by the kernel, and if not ask the pager to map-in those pages. I haven't implemented yet the bit that asks the pager for paging-in.
This commit is contained in:
38
src/generic/space.c
Normal file
38
src/generic/space.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Addess space related routines.
|
||||
*
|
||||
* Copyright (C) 2008 Bahadir Balban
|
||||
*/
|
||||
#include INC_GLUE(memory.h)
|
||||
#include INC_GLUE(memlayout.h)
|
||||
#include INC_ARCH(exception.h)
|
||||
#include <l4/generic/space.h>
|
||||
#include <l4/api/space.h>
|
||||
#include <l4/api/errno.h>
|
||||
|
||||
/*
|
||||
* Checks whether the given user address is a valid userspace address.
|
||||
* If so, whether it is currently mapped into its own address space.
|
||||
* If its not mapped-in, it generates a page-in request to the thread's
|
||||
* pager. If fault hasn't cleared, aborts.
|
||||
*/
|
||||
int check_access(unsigned long vaddr, unsigned long size, unsigned int flags)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Do not allow ridiculously big sizes */
|
||||
if (size >= USER_AREA_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
/* Check if in user range, but this is more up to the pager to decide */
|
||||
if (!(vaddr >= USER_AREA_START && vaddr < USER_AREA_END))
|
||||
return -EINVAL;
|
||||
|
||||
/* If not mapped, ask pager whether this is possible */
|
||||
if (!check_mapping(vaddr, size, flags))
|
||||
if((err = pager_pagein_request(vaddr, size, flags)) < 0)
|
||||
return err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user