minix/kernel/system/do_copy.c
Tomas Hruby cca24d06d8 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.
2010-02-03 09:04:48 +00:00

93 lines
3.1 KiB
C

/* The kernel call implemented in this file:
* m_type: SYS_VIRCOPY, SYS_PHYSCOPY
*
* The parameters for this kernel call are:
* m5_s1: CP_SRC_SPACE source virtual segment
* m5_l1: CP_SRC_ADDR source offset within segment
* m5_i1: CP_SRC_ENDPT source process number
* m5_s2: CP_DST_SPACE destination virtual segment
* m5_l2: CP_DST_ADDR destination offset within segment
* m5_i2: CP_DST_ENDPT destination process number
* m5_l3: CP_NR_BYTES number of bytes to copy
*/
#include "../system.h"
#include <minix/type.h>
#if (USE_VIRCOPY || USE_PHYSCOPY)
/*===========================================================================*
* do_copy *
*===========================================================================*/
PUBLIC int do_copy(struct proc * caller, message * m_ptr)
{
/* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
* physical addressing. Although a single handler function is used, there
* are two different kernel calls so that permissions can be checked.
*/
struct vir_addr vir_addr[2]; /* virtual source and destination address */
phys_bytes bytes; /* number of bytes to copy */
int i;
#if 0
if (m_ptr->m_source != PM_PROC_NR && m_ptr->m_source != VFS_PROC_NR &&
m_ptr->m_source != RS_PROC_NR && m_ptr->m_source != MEM_PROC_NR &&
m_ptr->m_source != VM_PROC_NR)
{
static int first=1;
if (first)
{
first= 0;
kprintf(
"do_copy: got request from %d (source %d, seg %d, destination %d, seg %d)\n",
m_ptr->m_source,
m_ptr->CP_SRC_ENDPT,
m_ptr->CP_SRC_SPACE,
m_ptr->CP_DST_ENDPT,
m_ptr->CP_DST_SPACE);
}
}
#endif
/* Dismember the command message. */
vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
vir_addr[_SRC_].segment = m_ptr->CP_SRC_SPACE;
vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
vir_addr[_DST_].segment = m_ptr->CP_DST_SPACE;
vir_addr[_DST_].offset = (vir_bytes) m_ptr->CP_DST_ADDR;
bytes = (phys_bytes) m_ptr->CP_NR_BYTES;
/* Now do some checks for both the source and destination virtual address.
* This is done once for _SRC_, then once for _DST_.
*/
for (i=_SRC_; i<=_DST_; i++) {
int p;
/* Check if process number was given implictly with SELF and is valid. */
if (vir_addr[i].proc_nr_e == SELF)
vir_addr[i].proc_nr_e = m_ptr->m_source;
if (vir_addr[i].segment != PHYS_SEG) {
if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
kprintf("do_copy: %d: seg 0x%x, %d not ok endpoint\n",
i, vir_addr[i].segment, vir_addr[i].proc_nr_e);
return(EINVAL);
}
}
/* Check if physical addressing is used without SYS_PHYSCOPY. */
if ((vir_addr[i].segment & PHYS_SEG) &&
m_ptr->m_type != SYS_PHYSCOPY) return(EPERM);
}
/* Check for overflow. This would happen for 64K segments and 16-bit
* vir_bytes. Especially copying by the PM on do_fork() is affected.
*/
if (bytes != (phys_bytes) (vir_bytes) bytes) return(E2BIG);
/* Now try to make the actual virtual copy. */
return( virtual_copy_vmcheck(caller, &vir_addr[_SRC_],
&vir_addr[_DST_], bytes) );
}
#endif /* (USE_VIRCOPY || USE_PHYSCOPY) */