This patch removes the global variables who_p and who_e from the

kernel (sys task).  The main reason is that these would have to become
cpu local variables on SMP.  Once the system task is not a task but a
genuine part of the kernel there is even less reason to have these
extra variables as proc_ptr will already contain all neccessary
information. In addition converting who_e to the process pointer and
back again all the time will be avoided.

Although proc_ptr will contain all important information, accessing it
as a cpu local variable will be fairly expensive, hence the value
would be assigned to some on stack local variable. Therefore it is
better to add the 'caller' argument to the syscall handlers to pass
the value on stack anyway. It also clearly denotes on who's behalf is
the syscall being executed.

This patch also ANSIfies the syscall function headers.

Last but not least, it also fixes a potential bug in virtual_copy_f()
in case the check is disabled. So far the function in case of a
failure could possible reuse an old who_p in case this function had
not been called from the system task.

virtual_copy_f() takes the caller as a parameter too. In case the
checking is disabled, the caller must be NULL and non NULL if it is
enabled as we must be able to suspend the caller.
This commit is contained in:
Tomas Hruby
2010-02-03 09:04:48 +00:00
parent 144de8a7b3
commit cca24d06d8
44 changed files with 232 additions and 284 deletions
+3 -4
View File
@@ -18,17 +18,16 @@ struct reg86u reg86;
/*===========================================================================*
* do_int86 *
*===========================================================================*/
PUBLIC int do_int86(m_ptr)
register message *m_ptr; /* pointer to request message */
PUBLIC int do_int86(struct proc * caller, message * m_ptr)
{
data_copy(who_e, (vir_bytes) m_ptr->INT86_REG86,
data_copy(caller->p_endpoint, (vir_bytes) m_ptr->INT86_REG86,
SYSTEM, (vir_bytes) &reg86, sizeof(reg86));
level0(int86);
/* Copy results back to the caller */
data_copy(SYSTEM, (vir_bytes) &reg86,
who_e, (vir_bytes) m_ptr->INT86_REG86, sizeof(reg86));
caller->p_endpoint, (vir_bytes) m_ptr->INT86_REG86, sizeof(reg86));
/* The BIOS call eats interrupts. Call get_randomness to generate some
* entropy. Normally, get_randomness is called from an interrupt handler.
+3 -3
View File
@@ -10,20 +10,20 @@
#include "../../system.h"
#include "../../kernel.h"
#include <minix/endpoint.h>
#include "proto.h"
/*===========================================================================*
* do_iopenable *
*===========================================================================*/
PUBLIC int do_iopenable(m_ptr)
register message *m_ptr; /* pointer to request message */
PUBLIC int do_iopenable(struct proc * caller, message * m_ptr)
{
int proc_nr;
#if 1 /* ENABLE_USERPRIV && ENABLE_USERIOPL */
if (m_ptr->IO_ENDPT == SELF) {
proc_nr = who_p;
proc_nr = _ENDPOINT_P(caller->p_endpoint);
} else if(!isokendpt(m_ptr->IO_ENDPT, &proc_nr))
return(EINVAL);
enable_iop(proc_addr(proc_nr));
+2 -3
View File
@@ -13,8 +13,7 @@
/*===========================================================================*
* do_readbios *
*===========================================================================*/
PUBLIC int do_readbios(m_ptr)
register message *m_ptr; /* pointer to request message */
PUBLIC int do_readbios(struct proc * caller, message * m_ptr)
{
struct vir_addr src, dst;
@@ -25,5 +24,5 @@ register message *m_ptr; /* pointer to request message */
src.proc_nr_e = NONE;
dst.proc_nr_e = m_ptr->m_source;
return virtual_copy_vmcheck(&src, &dst, m_ptr->RDB_SIZE);
return virtual_copy_vmcheck(caller, &src, &dst, m_ptr->RDB_SIZE);
}
+6 -10
View File
@@ -21,9 +21,7 @@
/*===========================================================================*
* do_sdevio *
*===========================================================================*/
PUBLIC int do_sdevio(
register message *m_ptr /* pointer to request message */
)
PUBLIC int do_sdevio(struct proc * caller, message *m_ptr)
{
vir_bytes newoffset;
endpoint_t newep;
@@ -32,7 +30,6 @@ PUBLIC int do_sdevio(
long port = m_ptr->DIO_PORT;
phys_bytes phys_buf;
int i, req_type, req_dir, size, nr_io_range;
struct proc *rp;
struct priv *privp;
struct io_range *iorp;
struct proc *destproc;
@@ -55,7 +52,7 @@ PUBLIC int do_sdevio(
* that initiated the device I/O. Kernel processes, of course, are denied.
*/
if (proc_nr_e == SELF)
proc_nr = who_p;
proc_nr = _ENDPOINT_P(caller->p_endpoint);
else
if(!isokendpt(proc_nr_e, &proc_nr))
return(EINVAL);
@@ -68,7 +65,7 @@ PUBLIC int do_sdevio(
/* Check for 'safe' variants. */
if((m_ptr->DIO_REQUEST & _DIO_SAFEMASK) == _DIO_SAFE) {
/* Map grant address to physical address. */
if(verify_grant(proc_nr_e, who_e,
if(verify_grant(proc_nr_e, caller->p_endpoint,
(vir_bytes) m_ptr->DIO_VEC_ADDR,
count,
req_dir == _DIO_INPUT ? CPF_WRITE : CPF_READ,
@@ -86,10 +83,10 @@ PUBLIC int do_sdevio(
return(EFAULT);
}
} else {
if(proc_nr != who_p)
if(proc_nr != _ENDPOINT_P(caller->p_endpoint))
{
kprintf("do_sdevio: unsafe sdevio by %d in %d denied\n",
who_e, proc_nr_e);
caller->p_endpoint, proc_nr_e);
return EPERM;
}
/* Get and check physical address. */
@@ -110,8 +107,7 @@ PUBLIC int do_sdevio(
default: size= 4; break; /* Be conservative */
}
rp= proc_addr(who_p);
privp= priv(rp);
privp= priv(caller);
if (privp && privp->s_flags & CHECK_IO_PORT)
{
port= m_ptr->DIO_PORT;
+14 -15
View File
@@ -775,7 +775,8 @@ int vm_phys_memset(phys_bytes ph, u8_t c, phys_bytes bytes)
/*===========================================================================*
* virtual_copy_f *
*===========================================================================*/
PUBLIC int virtual_copy_f(src_addr, dst_addr, bytes, vmcheck)
PUBLIC int virtual_copy_f(caller, src_addr, dst_addr, bytes, vmcheck)
struct proc * caller;
struct vir_addr *src_addr; /* source virtual address */
struct vir_addr *dst_addr; /* destination virtual address */
vir_bytes bytes; /* # of bytes to copy */
@@ -791,6 +792,8 @@ int vmcheck; /* if nonzero, can return VMSUSPEND */
struct proc *procs[2];
NOREC_ENTER(virtualcopy);
vmassert((vmcheck && caller) || (!vmcheck && !caller));
/* Check copy count. */
if (bytes <= 0) return(EDOM);
@@ -823,8 +826,8 @@ int vmcheck; /* if nonzero, can return VMSUSPEND */
phys_addr[i] = umap_local(p, seg_index, vir_addr[i]->offset,
bytes);
else
phys_addr[i] = umap_virtual(p, seg_index, vir_addr[i]->offset,
bytes);
phys_addr[i] = umap_virtual(p, seg_index,
vir_addr[i]->offset, bytes);
if(phys_addr[i] == 0) {
kprintf("virtual_copy: map 0x%x failed for %s seg %d, "
"offset %lx, len %d, i %d\n",
@@ -861,11 +864,8 @@ int vmcheck; /* if nonzero, can return VMSUSPEND */
if(vm_running) {
int r;
struct proc *caller;
caller = proc_addr(who_p);
if(RTS_ISSET(caller, RTS_VMREQUEST)) {
if(caller && RTS_ISSET(caller, RTS_VMREQUEST)) {
vmassert(caller->p_vmrequest.vmresult != VMSUSPEND);
RTS_LOCK_UNSET(caller, RTS_VMREQUEST);
if(caller->p_vmrequest.vmresult != OK) {
@@ -884,7 +884,7 @@ int vmcheck; /* if nonzero, can return VMSUSPEND */
phys_bytes lin;
if(r != EFAULT_SRC && r != EFAULT_DST)
minix_panic("lin_lin_copy failed", r);
if(!vmcheck) {
if(!vmcheck || !caller) {
NOREC_RETURN(virtualcopy, r);
}
@@ -909,9 +909,9 @@ int vmcheck; /* if nonzero, can return VMSUSPEND */
#endif
vmassert(proc_ptr->p_endpoint == SYSTEM);
vm_suspend(caller, target, lin, bytes, wr, VMSTYPE_KERNELCALL);
NOREC_RETURN(virtualcopy, VMSUSPEND);
vm_suspend(caller, target, lin, bytes, wr,
VMSTYPE_KERNELCALL);
NOREC_RETURN(virtualcopy, VMSUSPEND);
}
NOREC_RETURN(virtualcopy, OK);
@@ -941,8 +941,7 @@ int vmcheck; /* if nonzero, can return VMSUSPEND */
/*===========================================================================*
* data_copy *
*===========================================================================*/
PUBLIC int data_copy(
endpoint_t from_proc, vir_bytes from_addr,
PUBLIC int data_copy(endpoint_t from_proc, vir_bytes from_addr,
endpoint_t to_proc, vir_bytes to_addr,
size_t bytes)
{
@@ -960,7 +959,7 @@ PUBLIC int data_copy(
/*===========================================================================*
* data_copy_vmcheck *
*===========================================================================*/
PUBLIC int data_copy_vmcheck(
PUBLIC int data_copy_vmcheck(struct proc * caller,
endpoint_t from_proc, vir_bytes from_addr,
endpoint_t to_proc, vir_bytes to_addr,
size_t bytes)
@@ -973,7 +972,7 @@ PUBLIC int data_copy_vmcheck(
src.proc_nr_e = from_proc;
dst.proc_nr_e = to_proc;
return virtual_copy_vmcheck(&src, &dst, bytes);
return virtual_copy_vmcheck(caller, &src, &dst, bytes);
}
/*===========================================================================*