From: Ben Gras Date: Mon, 8 Jun 2009 14:33:15 +0000 (+0000) Subject: quick hack (sorry) for making *sdevio* work to other X-Git-Tag: v3.1.4~2 X-Git-Url: http://zhaoyanbai.com/repos/man.arpaname.html?a=commitdiff_plain;h=01732ffb5e50862f780f1df22808888db91b7bc5;p=minix.git quick hack (sorry) for making *sdevio* work to other processes than the caller.. also disable kernel sanity checks --- diff --git a/kernel/arch/i386/do_sdevio.c b/kernel/arch/i386/do_sdevio.c index 9d0829a3a..65bfd7e49 100644 --- a/kernel/arch/i386/do_sdevio.c +++ b/kernel/arch/i386/do_sdevio.c @@ -32,6 +32,10 @@ register message *m_ptr; /* pointer to request message */ struct proc *rp; struct priv *privp; struct io_range *iorp; + int rem; + static char zero[4096]; + vir_bytes addr; + struct proc *destproc; /* Allow safe copies and accesses to SELF */ if ((m_ptr->DIO_REQUEST & _DIO_SAFEMASK) != _DIO_SAFE && @@ -63,12 +67,26 @@ register message *m_ptr; /* pointer to request message */ /* Check for 'safe' variants. */ if((m_ptr->DIO_REQUEST & _DIO_SAFEMASK) == _DIO_SAFE) { + vir_bytes newoffset; + endpoint_t newep; /* Map grant address to physical address. */ - if ((phys_buf = umap_verify_grant(proc_addr(proc_nr), who_e, + if(verify_grant(proc_nr_e, who_e, (vir_bytes) m_ptr->DIO_VEC_ADDR, - (vir_bytes) m_ptr->DIO_OFFSET, count, - req_dir == _DIO_INPUT ? CPF_WRITE : CPF_READ)) == 0) - return(EPERM); + count, + req_dir == _DIO_INPUT ? CPF_WRITE : CPF_READ, + (vir_bytes) m_ptr->DIO_OFFSET, + &newoffset, &newep) != OK) { + printf("do_sdevio: verify_grant failed\n"); + return EPERM; + } + if(!isokendpt(newep, &proc_nr)) + return(EINVAL); + destproc = proc_addr(proc_nr); + if ((phys_buf = umap_local(destproc, D, + (vir_bytes) newoffset, count)) == 0) { + printf("do_sdevio: umap_local failed\n"); + return(EFAULT); + } } else { if(proc_nr != who_p) { @@ -80,12 +98,24 @@ register message *m_ptr; /* pointer to request message */ if ((phys_buf = umap_local(proc_addr(proc_nr), D, (vir_bytes) m_ptr->DIO_VEC_ADDR, count)) == 0) return(EFAULT); + destproc = proc_addr(proc_nr); } /* current process must be target for phys_* to be OK */ - if(proc_addr(proc_nr) != ptproc) { - kprintf("do_sdevio: wrong process\n"); - return EIO; - } + + vm_set_cr3(destproc); + rem = count; + addr = m_ptr->DIO_VEC_ADDR; + while(rem > 0) { + int r; + int chunk; + chunk = rem > sizeof(zero) ? sizeof(zero) : rem; + if((r=data_copy_vmcheck(SYSTEM, zero, destproc->p_endpoint, + addr, chunk)) != OK) { + return r; + } + addr += chunk; + rem -= chunk; + } switch (io_type) { diff --git a/kernel/arch/i386/memory.c b/kernel/arch/i386/memory.c index 37b88447d..9aa6ec66c 100644 --- a/kernel/arch/i386/memory.c +++ b/kernel/arch/i386/memory.c @@ -37,7 +37,6 @@ PUBLIC u32_t dirtypde; #define HASPT(procptr) ((procptr)->p_seg.p_cr3 != 0) FORWARD _PROTOTYPE( u32_t phys_get32, (vir_bytes v) ); -FORWARD _PROTOTYPE( void vm_set_cr3, (struct proc *pr) ); FORWARD _PROTOTYPE( void set_cr3, (void) ); FORWARD _PROTOTYPE( void vm_enable_paging, (void) ); @@ -212,7 +211,7 @@ phys_bytes addr; PRIVATE u32_t vm_cr3; /* temp arg to level0() func */ -PRIVATE void vm_set_cr3(struct proc *newptproc) +PUBLIC void vm_set_cr3(struct proc *newptproc) { int u = 0; if(!intr_disabled()) { lock; u = 1; } diff --git a/kernel/arch/i386/proto.h b/kernel/arch/i386/proto.h index 0dfb478c9..45fee754a 100644 --- a/kernel/arch/i386/proto.h +++ b/kernel/arch/i386/proto.h @@ -53,6 +53,7 @@ _PROTOTYPE( void i386_updatepde, (int pde, u32_t val)); _PROTOTYPE( void i386_freepde, (int pde)); _PROTOTYPE( void getcr3val, (void)); _PROTOTYPE( void switchedcr3, (void)); +_PROTOTYPE( void vm_set_cr3, (struct proc *)); /* exception.c */ diff --git a/kernel/debug.h b/kernel/debug.h index baa044834..e25605e0c 100644 --- a/kernel/debug.h +++ b/kernel/debug.h @@ -25,10 +25,10 @@ #define DEBUG_TIME_LOCKS 1 /* Runtime sanity checking. */ -#define DEBUG_VMASSERT 1 -#define DEBUG_SCHED_CHECK 1 -#define DEBUG_STACK_CHECK 1 -#define DEBUG_TRACE 1 +#define DEBUG_VMASSERT 0 +#define DEBUG_SCHED_CHECK 0 +#define DEBUG_STACK_CHECK 0 +#define DEBUG_TRACE 0 #if DEBUG_TRACE