本文整理汇总了C++中envid2env函数的典型用法代码示例。如果您正苦于以下问题:C++ envid2env函数的具体用法?C++ envid2env怎么用?C++ envid2env使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了envid2env函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
int r;
struct Env* env;
struct Env* dstenv;
pte_t* pte;
struct Page* page;
if ((r=envid2env(srcenvid,&env,1))<0)
return -E_BAD_ENV;
if ((r=envid2env(dstenvid,&dstenv,1))<0)
return -E_BAD_ENV;
if ((uint32_t)srcva>=UTOP || (uint32_t)dstva>=UTOP || srcva!=ROUNDUP(srcva,PGSIZE) || dstva!=ROUNDUP(dstva,PGSIZE))
return -E_INVAL;
if ((perm&(PTE_U|PTE_P))!=(PTE_U|PTE_P))
return -E_INVAL;
if ((page=page_lookup(env->env_pgdir,srcva,&pte))==NULL)
return -E_INVAL;
if ((perm&PTE_W)!=0 && (((*pte)&PTE_W)==0))
return -E_INVAL;
if ((r=page_insert(dstenv->env_pgdir,page,dstva,perm))<0)
return -E_NO_MEM;
return 0;
// panic("sys_page_map not implemented");
}
开发者ID:binghe2001021,项目名称:joslabs,代码行数:51,代码来源:syscall.c
示例2: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Return 0 on success, < 0 on error.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
struct Env *es, *ed;
struct Page *p;
pte_t *pte;
int r;
if ((r = envid2env(srcenvid, &es, 1)) < 0 || (r = envid2env(dstenvid, &ed, 1)) < 0)
return r;
if ((uintptr_t)srcva >= UTOP || (uintptr_t)srcva % PGSIZE ||
(uintptr_t)dstva >= UTOP || (uintptr_t)dstva % PGSIZE)
return -E_INVAL;
if ((!(perm & (PTE_U + PTE_P))) || perm & ~PTE_USER)
return -E_INVAL;
if (!(p = page_lookup(es->env_pgdir, srcva, &pte)))
return -E_INVAL;
if (((perm & PTE_W) && !(*pte & PTE_W)))
return -E_INVAL;
if ((r = page_insert(ed->env_pgdir, p, dstva, perm)) < 0)
return r;
return 0;
}
开发者ID:liuyuan,项目名称:kludgeos,代码行数:32,代码来源:syscall.c
示例3: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
if (srcva >= (void *)UTOP || dstva >= (void *)UTOP || (perm & 0x5) != 0x5 ||
PGOFF(srcva) || PGOFF(dstva) || (perm & (~PTE_SYSCALL)))
return -E_INVAL;
struct Env *src_env, *dst_env;
envid2env(srcenvid, &src_env, 1);
envid2env(dstenvid, &dst_env, 1);
if (!src_env || !dst_env) {
return -E_BAD_ENV;
}
pte_t *pte;
struct Page *page = page_lookup(src_env->env_pgdir, srcva, &pte);
if (!page || (!(*pte & PTE_W) && (perm & PTE_W))) {
return -E_INVAL;
}
if (page_insert(dst_env->env_pgdir, page, dstva, perm)) {
return -E_NO_MEM;
}
return 0;
// panic("sys_page_map not implemented");
}
开发者ID:130B848,项目名称:JOS-labs,代码行数:51,代码来源:syscall.c
示例4: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
int ret;
pte_t *src_pte;
struct Page *pp;
struct Env *srcenv, *dstenv;
if((uintptr_t)srcva >= UTOP || (uintptr_t)dstva >= UTOP)
return -E_INVAL;
if((uintptr_t)srcva % PGSIZE || (uintptr_t)dstva % PGSIZE)
return -E_INVAL;
if((perm & ~PTE_SYSCALL) || !(perm & PTE_P) || !(perm & PTE_U))
return -E_INVAL;
if((ret = envid2env(srcenvid, &srcenv, 1)) < 0)
return ret;
if((ret = envid2env(dstenvid, &dstenv, 1)) < 0)
return ret;
if((pp = page_lookup(srcenv->env_pgdir, srcva, &src_pte)) == NULL)
return -E_INVAL;
if((perm & PTE_W) && !(*src_pte & PTE_W))
return -E_INVAL;
if((ret = page_insert(dstenv->env_pgdir, pp, dstva, perm)) < 0);
return ret;
return 0;
// panic("sys_page_map not implemented");
}
开发者ID:ldaochen,项目名称:JOS2011,代码行数:51,代码来源:syscall.c
示例5: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
int rslt;
struct Env *src, *dst;
pte_t *srcpte;
struct PageInfo *pg;
if((rslt = envid2env(srcenvid, &src, 1)) != 0)
return rslt;
if((rslt = envid2env(dstenvid, &dst, 1)) != 0)
return rslt;
if(srcva >= (void *)UTOP || (((size_t)srcva % PGSIZE) != 0))
return -E_INVAL;
if(dstva >= (void *)UTOP || (((size_t)dstva % PGSIZE) != 0))
return -E_INVAL;
if((pg = page_lookup(src->env_pgdir, srcva, &srcpte)) == NULL || !(*srcpte & PTE_P))
return -E_INVAL;
if((perm & (PTE_U | PTE_P)) != (PTE_U | PTE_P))
return -E_INVAL;
if((perm & PTE_W) && !(*srcpte & PTE_W))
return -E_INVAL;
rslt = page_insert(dst->env_pgdir, pg, dstva, perm);
return rslt;
//panic("sys_page_map not implemented");
}
开发者ID:liuxu1005,项目名称:Operating-System-Engineering,代码行数:49,代码来源:syscall.c
示例6: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
//
// TODO: after finishing lab6 refactor this function (and any other
// funcs that are defined here;
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
// page_lookup returns page that is mapped at particular va addr
// page_insert does the actual page mapping
uint32_t src = (uint32_t)srcva;
uint32_t dst = (uint32_t)dstva;
int mask = ~(PTE_U | PTE_P | PTE_AVAIL | PTE_W);
int ret = -1;
bool write_perm = perm & PTE_W;
struct Env *srcenv, *dstenv;
pte_t *pte;
struct PageInfo *p;
if (!(perm & (PTE_U | PTE_P)) || (mask & perm)) {
return -E_INVAL;
}
if (src % PGSIZE != 0 || dst % PGSIZE != 0 ||
(uint32_t)src >= UTOP || (uint32_t)dst >= UTOP) {
return -E_INVAL;
}
ret = envid2env(srcenvid, &srcenv, 0);
if (ret < 0) {
return ret;
}
ret = envid2env(dstenvid, &dstenv, 0);
if (ret < 0) {
return ret;
}
// get source page that will be mapped onto dstenv
p = page_lookup(srcenv->env_pgdir, srcva, &pte);
if (!p) {
return -E_INVAL;
}
if (!(*pte & PTE_W) && write_perm) {
return -E_INVAL;
}
ret = page_insert(dstenv->env_pgdir, p, dstva, perm);
if (ret < 0) {
return ret;
}
return 0;
}
开发者ID:macfij,项目名称:macfij_jos,代码行数:76,代码来源:syscall.c
示例7: sys_ipc_try_send
// Try to send 'value' to the target env 'envid'.
// If srcva < UTOP, then also send page currently mapped at 'srcva',
// so that receiver gets a duplicate mapping of the same page.
//
// The send fails with a return value of -E_IPC_NOT_RECV if the
// target is not blocked, waiting for an IPC.
//
// The send also can fail for the other reasons listed below.
//
// Otherwise, the send succeeds, and the target's ipc fields are
// updated as follows:
// env_ipc_recving is set to 0 to block future sends;
// env_ipc_from is set to the sending envid;
// env_ipc_value is set to the 'value' parameter;
// env_ipc_perm is set to 'perm' if a page was transferred, 0 otherwise.
// The target environment is marked runnable again, returning 0
// from the paused sys_ipc_recv system call. (Hint: does the
// sys_ipc_recv function ever actually return?)
//
// If the sender wants to send a page but the receiver isn't asking for one,
// then no page mapping is transferred, but no error occurs.
// The ipc only happens when no errors occur.
//
// Returns 0 on success, < 0 on error.
// Errors are:
// -E_BAD_ENV if environment envid doesn't currently exist.
// (No need to check permissions.)
// -E_IPC_NOT_RECV if envid is not currently blocked in sys_ipc_recv,
// or another environment managed to send first.
// -E_INVAL if srcva < UTOP but srcva is not page-aligned.
// -E_INVAL if srcva < UTOP and perm is inappropriate
// (see sys_page_alloc).
// -E_INVAL if srcva < UTOP but srcva is not mapped in the caller's
// address space.
// -E_INVAL if (perm & PTE_W), but srcva is read-only in the
// current environment's address space.
// -E_NO_MEM if there's not enough memory to map srcva in envid's
// address space.
static int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, unsigned perm)
{
// LAB 4: Your code here.
// aj-code
struct Env *dstenv, *srcenv;
int r;
pte_t *pte_ptr;
if ((r=envid2env(envid, &dstenv, 0)) < 0) {
cprintf("\nReached dest env bad environment");
return -E_BAD_ENV;
}
if ((r=envid2env(0, &srcenv, 0)) < 0) {
return -E_BAD_ENV;
}
if (dstenv->env_ipc_recving == 0)
return -E_IPC_NOT_RECV;
dstenv->env_ipc_recving = 0;
dstenv->env_ipc_from = curenv->env_id;
dstenv->env_ipc_value = value;
// page transfer
if ((uintptr_t)srcva<UTOP) {
struct Page *src_page;
struct Page *dst_page;
pte_t *src_pte;
pte_t *dst_pte;
src_page = page_lookup(srcenv->env_pml4e, srcva, &src_pte);
if (!src_page) {
return -E_INVAL;
}
int result_dst = page_insert(dstenv->env_pml4e, src_page, dstenv->env_ipc_dstva, perm);
if (result_dst) {
return -E_NO_MEM;
}
dstenv->env_ipc_perm = perm;
} else {
//not a page transfer
dstenv->env_ipc_perm = 0;
}
dstenv->env_status = ENV_RUNNABLE;
return 0;
panic("sys_ipc_try_send not implemented");
}
开发者ID:ajsbu,项目名称:cse506,代码行数:94,代码来源:syscall.c
示例8: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
int result_src, result_dst;
struct Env *src_env = NULL, *dst_env = NULL;
result_src = envid2env(srcenvid, &src_env, 1);
result_dst = envid2env(dstenvid, &dst_env, 1);
if (result_src || result_dst) {
return -E_BAD_ENV;
}
if ((uintptr_t)srcva>=UTOP || ROUNDUP(srcva, PGSIZE) != srcva || (uintptr_t)dstva>=UTOP || ROUNDUP(dstva, PGSIZE) != dstva) {
return -E_INVAL;
}
struct Page *src_page;
struct Page *dst_page;
pte_t *src_pte;
pte_t *dst_pte;
src_page = page_lookup(src_env->env_pml4e, srcva, &src_pte);
if (!src_page) {
return -E_INVAL;
}
/*
uint64_t src_permission = *src_pte & 0xfff;
int source_page_readonly = (src_permission & PTE_W)==0;
if (((perm & (PTE_U|PTE_P)) != (PTE_U|PTE_P)) || ((perm & (~PTE_SYSCALL)) != 0) || ((perm & PTE_W) && source_page_readonly)) {
return -E_INVAL;
}
*/
result_dst = page_insert(dst_env->env_pml4e, src_page, dstva, perm);
if (result_dst) {
return -E_NO_MEM;
}
return result_dst;
panic("sys_page_map not implemented");
}
开发者ID:ajsbu,项目名称:cse506,代码行数:71,代码来源:syscall.c
示例9: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
struct Env *srcenv;
struct Env *dstenv;
pte_t *pte;
struct Page *pp;
// Env Ids valid and caller has perms to access them
if (envid2env(srcenvid, &srcenv, 1) < 0 ||
envid2env(dstenvid, &dstenv, 1) < 0) {
return -E_BAD_ENV;
}
// VAs below UTOP and page aligned
if ((uintptr_t)srcva >= UTOP || (uintptr_t)srcva % PGSIZE ||
(uintptr_t)dstva >= UTOP || (uintptr_t)dstva % PGSIZE) {
return -E_INVAL;
}
if ((pp = page_lookup(srcenv->env_pgdir, srcva, &pte)) == NULL) {
return -E_INVAL;
}
// PTE_U | PTE_P must be set
if ((perm & PTE_U) == 0 || (perm & PTE_P) == 0) {
return -E_INVAL;
}
// Only U, P, W and AVAIL can be set
if ((perm & ~(PTE_U | PTE_P | PTE_W | PTE_AVAIL)) != 0) {
return -E_INVAL;
}
// Dest page writable but source isn't
if ((perm & PTE_W) && ((*pte & PTE_W) == 0)) {
return -E_INVAL;
}
if (page_insert(dstenv->env_pgdir, pp, dstva, perm) < 0) {
return -E_NO_MEM;
}
return 0;
}
开发者ID:bosswissam,项目名称:djos,代码行数:70,代码来源:syscall.c
示例10: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
/* lj */
struct Env *senv = NULL, *denv = NULL;
int ret = 0;
struct Page *p = NULL;
pte_t *spte = NULL, *dpte = NULL;
//cprintf("0 0x%x 0x%x 0x%x 0x%x \n",srcenvid, srcva, dstenvid, dstva);
if((ret = envid2env(srcenvid, &senv, 1)) < 0) {
return ret;
}
if((ret = envid2env(dstenvid, &denv, 1)) < 0) {
return ret;
}
else if((size_t)dstva > UTOP || (size_t)srcva > UTOP) {
return -E_INVAL;
}
else if(((size_t)dstva & (PGSIZE-1)) || ((size_t)srcva & (PGSIZE - 1))) {
return -E_INVAL;
}
else if(NULL == (p = page_lookup(senv->env_pgdir, srcva, &spte))) {
return -E_INVAL;
}
else if(0 == (perm & (PTE_U | PTE_P))) {
return -E_INVAL;
}
else if(perm & ~(PTE_U | PTE_P | PTE_W | PTE_AVAIL)) {
return -E_INVAL;
}
else if((perm & PTE_W) && !(*spte & PTE_W)) {
return -E_INVAL;
}
assert(senv);
assert(denv);
assert(*spte & PTE_P);
if((ret = page_insert(denv->env_pgdir, p, dstva, perm)) < 0) {
}
return ret;
//panic("sys_page_map not implemented");
}
开发者ID:dannoy,项目名称:JOS,代码行数:70,代码来源:syscall.c
示例11: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate the new page,
// or to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
int errno;
pte_t *pte;
struct Page *page;
struct Env *srcEnv, *dstEnv;
if (((uint32_t)srcva >= UTOP) || ((uint32_t)srcva % PGSIZE) ||
((uint32_t)dstva >= UTOP) || ((uint32_t)dstva % PGSIZE)) {
dbg_print("invalid address");
return -E_INVAL;
}
if ((errno = envid2env(srcenvid, &srcEnv, 1)) < 0) {
dbg_print("env %d does not exist", srcenvid);
return errno;
}
if ((errno = envid2env(dstenvid, &dstEnv, 1)) < 0) {
dbg_print("env %d does not exist", dstenvid);
return errno;
}
if (!(perm & PTE_U) || !(perm & PTE_P)) {
dbg_print("invalid perm 0x%08x", perm);
return -E_INVAL;
}
page = page_lookup(srcEnv->env_pgdir, srcva, &pte);
if (!page || ((perm & PTE_W) && !(*pte & PTE_W))) {
dbg_print("invalid page 0x%p, perm=0x%08x, *pte=0x%08x", page, perm, *pte);
return -E_INVAL;
}
if ((errno = page_insert(dstEnv->env_pgdir, page, dstva, perm)) < 0) {
dbg_print("Env %d page_insert error: va=0x%08x");
page_free(page);
return errno;
}
return 0;
//panic("sys_page_map not implemented");
}
开发者ID:cutecheng,项目名称:zcjos,代码行数:70,代码来源:syscall.c
示例12: sys_page_map
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
struct Env *srcenv=NULL;
struct Env *destenv=NULL;
struct Page *p=NULL;
if(envid2env(srcenvid,&srcenv,1)<0 || envid2env(dstenvid,&destenv,1)<0)
return -E_BAD_ENV;
if(srcva>= (void *)UTOP || dstva>= (void *)UTOP || ((uint32_t)srcva)%PGSIZE!=0 ||((uint32_t)dstva)%PGSIZE!=0)
return -E_INVAL;
pte_t *srcPageToMap=NULL;
p = page_lookup(srcenv->env_pgdir,srcva,&srcPageToMap);
if(p==NULL)
return -E_INVAL;
else
{
if( (perm & PTE_P)!=0 && (perm & PTE_U)!=0)
{
if((perm & ((~(PTE_USER)) & 0xFFF))!=0)
return -E_INVAL;
}
else
return -E_INVAL;
int srcperm = (*(srcPageToMap) & 0xFFF);
if ((srcperm & PTE_W) == 0)
{
if((perm & PTE_W)!=0)
return -E_INVAL;
}
//else
{
if (page_insert(destenv->env_pgdir,p,dstva,perm)<0)
return -E_NO_MEM;
else return 0;
}
}
return -E_NO_MEM;
}
开发者ID:Insecurity-plan15,项目名称:JOS-Microkernel,代码行数:52,代码来源:syscall.c
示例13: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
struct Env *env1,*env2;
struct PageInfo *pg;
pte_t *pte;
int ret;
ret = envid2env(srcenvid, &env1, 1);
if(ret < 0){
cprintf("sys page map error in screnvid \n");
return -E_BAD_ENV;
}
ret = envid2env(dstenvid, &env2, 1);
if(ret < 0){
cprintf("sys page map error in dstenvid \n");
return -E_BAD_ENV;
}else if((uint64_t)srcva >= UTOP || ((uint64_t)srcva)%PGSIZE != 0){
cprintf("sys page map error. srcva is > utop or srcva is not alligned \n");
return -E_INVAL;
}else if((uint64_t)dstva >= UTOP || ((uint64_t)dstva)%PGSIZE != 0){
cprintf("sys page map error. dstva is > utop or dstva is not alligned \n");
return -E_INVAL;
}else if(!(perm & PTE_U) && !(perm & PTE_P) && (perm & ~PTE_SYSCALL)){ //now unchanged in the end
cprintf("sys page map error. permission mismatch \n");
return -E_INVAL;
}
if(!(pg = page_lookup(env1->env_pml4e, srcva, &pte))){
cprintf("sys page map error. Page lookup failed for env1 \n");
return -E_INVAL;
}else if(((perm & PTE_W) != 0) && ((*pte & PTE_W) == 0)){
cprintf("sys page map error. Write permission error \n");
return -E_INVAL;
}else if(page_insert(env2->env_pml4e, pg, dstva, perm)){
cprintf("sys page map error. Page insert failed for env2 \n");
page_free(pg);
return -E_NO_MEM;
}
return 0;
// panic("sys_page_map not implemented");
}
开发者ID:deepakkumar-b,项目名称:JOS-Labs_Project,代码行数:68,代码来源:syscall.c
示例14: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
struct Env *srcenv, *dstenv;
int r1 = envid2env(srcenvid, &srcenv, 1);
int r2 = envid2env(dstenvid, &dstenv, 1);
/* Proper envid check*/
if (r1 < 0 || r2 < 0) {
cprintf("\n envid2env error %e, %e sys_page_map\n", r1, r2);
return -E_BAD_ENV;
}
/*Address range check*/
if((uintptr_t)srcva >= UTOP || (uintptr_t)dstva >= UTOP || PGOFF(srcva) || PGOFF(dstva)) {
cprintf("\n envid2env error %e sys_page_map\n", -E_INVAL);
return -E_INVAL;
}
/*Correct page request check*/
struct PageInfo *map;
pte_t *p_entry;
map = page_lookup(srcenv->env_pml4e, srcva, &p_entry);
if(!map) {
cprintf("\n No page available or not mapped properly SYS_PAGE_ALLOC %e \n", -E_NO_MEM);
return -E_NO_MEM;
}
/*Proper Permission check*/
int map_perm = PTE_P | PTE_U;
if ((perm & map_perm) != map_perm || (perm & ~PTE_SYSCALL)) {
cprintf("\n permission error %e sys_page_map\n", -E_INVAL);
return -E_INVAL;
}
if((perm & PTE_W) && !(*p_entry & PTE_W)) {
cprintf("\n permission error %e sys_page_map\n", -E_INVAL);
return -E_INVAL;
}
/*Page insert check*/
if(page_insert(dstenv->env_pml4e, map, dstva, perm) < 0) {
cprintf("\n No memory to allocate page SYS_PAGE_MAP %e \n", -E_NO_MEM);
return -E_NO_MEM;
}
return 0;
// LAB 4: Your code here.
//panic("sys_page_map not implemented");
}
开发者ID:scau,项目名称:JOS,代码行数:66,代码来源:syscall.c
示例15: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// -E_INVAL is srcva is not mapped in srcenvid's address space.
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
// -E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
struct Env *se, *de;
int ret = envid2env(srcenvid, &se, 1);
if (ret) return ret; //bad_env
ret = envid2env(dstenvid, &de, 1);
if (ret) return ret; //bad_env
// cprintf("src env: %x, dst env: %x, src va: %x, dst va: %x\n",
// se->env_id, de->env_id, srcva, dstva);
// -E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
if (srcva>=(void*)UTOP || dstva>=(void*)UTOP ||
ROUNDDOWN(srcva,PGSIZE)!=srcva || ROUNDDOWN(dstva,PGSIZE)!=dstva)
return -E_INVAL;
// -E_INVAL is srcva is not mapped in srcenvid's address space.
pte_t *pte;
struct PageInfo *pg = page_lookup(se->env_pgdir, srcva, &pte);
if (!pg) return -E_INVAL;
// -E_INVAL if perm is inappropriate (see sys_page_alloc).
int flag = PTE_U|PTE_P;
if ((perm & flag) != flag) return -E_INVAL;
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
if (((*pte&PTE_W) == 0) && (perm&PTE_W)) return -E_INVAL;
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
ret = page_insert(de->env_pgdir, pg, dstva, perm);
// cprintf("map done %x\n", ret);
return ret;
panic("sys_page_map not implemented");
}
开发者ID:1060351485,项目名称:jos,代码行数:65,代码来源:syscall.c
示例16: sys_page_map
// Map the page of memory at 'srcva' in srcenvid's address space
// at 'dstva' in dstenvid's address space with permission 'perm'.
// Perm has the same restrictions as in sys_page_alloc, except
// that it also must not grant write access to a read-only
// page.
//
// Return 0 on success, < 0 on error. Errors are:
// --E_BAD_ENV if srcenvid and/or dstenvid doesn't currently exist,
// or the caller doesn't have permission to change one of them.
// --E_INVAL if srcva >= UTOP or srcva is not page-aligned,
// or dstva >= UTOP or dstva is not page-aligned.
// --E_INVAL is srcva is not mapped in srcenvid's address space.
// --E_INVAL if perm is inappropriate (see sys_page_alloc).
// -E_INVAL if (perm & PTE_W), but srcva is read-only in srcenvid's
// address space.
// -E_NO_MEM if there's no memory to allocate any necessary page tables.
static int
sys_page_map(envid_t srcenvid, void *srcva,
envid_t dstenvid, void *dstva, int perm)
{
// Hint: This function is a wrapper around page_lookup() and
// page_insert() from kern/pmap.c.
// Again, most of the new code you write should be to check the
// parameters for correctness.
// Use the third argument to page_lookup() to
// check the current permissions on the page.
// LAB 4: Your code here.
// Lab 4 ex 7
// To do lab 4 check perm
int returnVal;
struct Page *pageVal;
struct Env *srcEnv,*destEnv;
pte_t *srcPt,*destPt;
if((uint64_t)srcva>UTOP)return -E_INVAL;
if((uint64_t)dstva>UTOP)return -E_INVAL;
if((uint64_t)srcva>(uint64_t)ROUNDDOWN(srcva,PGSIZE))return -E_INVAL;
if((uint64_t)dstva>(uint64_t)ROUNDDOWN(dstva,PGSIZE))return -E_INVAL;
if((perm & PTE_U) == 0) return -E_INVAL;
if((perm & PTE_P) == 0) return -E_INVAL;
if((perm & ~PTE_SYSCALL) != 0) return -E_INVAL;
returnVal = envid2env(srcenvid,&srcEnv,0);
if(returnVal!=0) return -E_BAD_ENV;
returnVal = envid2env(dstenvid,&destEnv,0);
if(returnVal!=0) return -E_BAD_ENV;
pageVal = page_lookup(srcEnv->env_pml4e,srcva,&srcPt);
if(pageVal == NULL) return -E_INVAL;
if(!(perm & PTE_U) && !(perm & PTE_P)) return -E_INVAL;
if(((perm & PTE_W) != 0) && ((*srcPt & PTE_W) == 0)) return -E_INVAL;
returnVal = page_insert(destEnv->env_pml4e,pageVal,dstva,perm);
if(returnVal != 0) return -E_INVAL;
return returnVal;
}
开发者ID:sid9211,项目名称:OSProject,代码行数:65,代码来源:syscall.c
示例17: sys_page_alloc
// Allocate a page of memory and map it at 'va' with permission
// 'perm' in the address space of 'envid'.
// The page's contents are set to 0.
// If a page is already mapped at 'va', that page is unmapped as a
// side effect.
//
// perm -- PTE_U | PTE_P must be set, PTE_AVAIL | PTE_W may or may not be set,
// but no other bits may be set. See PTE_SYSCALL in inc/mmu.h.
//
// Return 0 on success, < 0 on error. Errors are:
// -E_BAD_ENV if environment envid doesn't currently exist,
// or the caller doesn't have permission to change envid.
// -E_INVAL if va >= UTOP, or va is not page-aligned.
// -E_INVAL if perm is inappropriate (see above).
// -E_NO_MEM if there's no memory to allocate the new page,
// or to allocate any necessary page tables.
static int
sys_page_alloc(envid_t envid, void *va, int perm)
{
// Hint: This function is a wrapper around page_alloc() and
// page_insert() from kern/pmap.c.
// Most of the new code you write should be to check the
// parameters for correctness.
// If page_insert() fails, remember to free the page you
// allocated!
// LAB 4: Your code here.
//panic("sys_page_alloc not implemented");
struct Env *e;
struct Page *p;
int r;
//cprintf("[sys_page_alloc]:perm is %d\n",perm);
if( va >=(void *)UTOP || (perm & 5) != 5 || PGOFF(va)!=0 || (perm & (~PTE_SYSCALL))!=0)
return -E_INVAL;
r = envid2env(envid, &e, 1);
if(r < 0)
return -E_BAD_ENV;
p = page_alloc(ALLOC_ZERO);
if(p == NULL)
return -E_NO_MEM;
r = page_insert(e->env_pgdir, p, va, perm);
if(r < 0){
page_free(p);
return -E_NO_MEM;
}
memset(page2kva(p), 0, PGSIZE);
return 0;
}
开发者ID:rinascere,项目名称:Jos,代码行数:48,代码来源:syscall.c
示例18: sys_ipc_try_send
// Try to send 'value' to the target env 'envid'.
// If va != 0, then also send page currently mapped at 'va',
// so that receiver gets a duplicate mapping of the same page.
//
// The send fails with a return value of -E_IPC_NOT_RECV if the
// target has not requested IPC with sys_ipc_recv.
//
// Otherwise, the send succeeds, and the target's ipc fields are
// updated as follows:
// env_ipc_recving is set to 0 to block future sends;
// env_ipc_from is set to the sending envid;
// env_ipc_value is set to
|
请发表评论