1*433d6423SLionel Sambuc /* The kernel call implemented in this file:
2*433d6423SLionel Sambuc * m_type: SYS_VIRCOPY, SYS_PHYSCOPY
3*433d6423SLionel Sambuc *
4*433d6423SLionel Sambuc * The parameters for this kernel call are:
5*433d6423SLionel Sambuc * m_lsys_krn_sys_copy.src_addr source offset within segment
6*433d6423SLionel Sambuc * m_lsys_krn_sys_copy.src_endpt source process number
7*433d6423SLionel Sambuc * m_lsys_krn_sys_copy.dst_addr destination offset within segment
8*433d6423SLionel Sambuc * m_lsys_krn_sys_copy.dst_endpt destination process number
9*433d6423SLionel Sambuc * m_lsys_krn_sys_copy.nr_bytes number of bytes to copy
10*433d6423SLionel Sambuc * m_lsys_krn_sys_copy.flags
11*433d6423SLionel Sambuc */
12*433d6423SLionel Sambuc
13*433d6423SLionel Sambuc #include "kernel/system.h"
14*433d6423SLionel Sambuc #include "kernel/vm.h"
15*433d6423SLionel Sambuc #include <assert.h>
16*433d6423SLionel Sambuc
17*433d6423SLionel Sambuc #if (USE_VIRCOPY || USE_PHYSCOPY)
18*433d6423SLionel Sambuc
19*433d6423SLionel Sambuc /*===========================================================================*
20*433d6423SLionel Sambuc * do_copy *
21*433d6423SLionel Sambuc *===========================================================================*/
do_copy(struct proc * caller,message * m_ptr)22*433d6423SLionel Sambuc int do_copy(struct proc * caller, message * m_ptr)
23*433d6423SLionel Sambuc {
24*433d6423SLionel Sambuc /* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
25*433d6423SLionel Sambuc * physical addressing. Although a single handler function is used, there
26*433d6423SLionel Sambuc * are two different kernel calls so that permissions can be checked.
27*433d6423SLionel Sambuc */
28*433d6423SLionel Sambuc struct vir_addr vir_addr[2]; /* virtual source and destination address */
29*433d6423SLionel Sambuc phys_bytes bytes; /* number of bytes to copy */
30*433d6423SLionel Sambuc int i;
31*433d6423SLionel Sambuc
32*433d6423SLionel Sambuc #if 0
33*433d6423SLionel Sambuc if (caller->p_endpoint != PM_PROC_NR && caller->p_endpoint != VFS_PROC_NR &&
34*433d6423SLionel Sambuc caller->p_endpoint != RS_PROC_NR && caller->p_endpoint != MEM_PROC_NR &&
35*433d6423SLionel Sambuc caller->p_endpoint != VM_PROC_NR)
36*433d6423SLionel Sambuc {
37*433d6423SLionel Sambuc static int first=1;
38*433d6423SLionel Sambuc if (first)
39*433d6423SLionel Sambuc {
40*433d6423SLionel Sambuc first= 0;
41*433d6423SLionel Sambuc printf(
42*433d6423SLionel Sambuc "do_copy: got request from %d (source %d, destination %d)\n",
43*433d6423SLionel Sambuc caller->p_endpoint,
44*433d6423SLionel Sambuc m_ptr->m_lsys_krn_sys_copy.src_endpt,
45*433d6423SLionel Sambuc m_ptr->m_lsys_krn_sys_copy.dst_endpt);
46*433d6423SLionel Sambuc }
47*433d6423SLionel Sambuc }
48*433d6423SLionel Sambuc #endif
49*433d6423SLionel Sambuc
50*433d6423SLionel Sambuc /* Dismember the command message. */
51*433d6423SLionel Sambuc vir_addr[_SRC_].proc_nr_e = m_ptr->m_lsys_krn_sys_copy.src_endpt;
52*433d6423SLionel Sambuc vir_addr[_DST_].proc_nr_e = m_ptr->m_lsys_krn_sys_copy.dst_endpt;
53*433d6423SLionel Sambuc
54*433d6423SLionel Sambuc vir_addr[_SRC_].offset = m_ptr->m_lsys_krn_sys_copy.src_addr;
55*433d6423SLionel Sambuc vir_addr[_DST_].offset = m_ptr->m_lsys_krn_sys_copy.dst_addr;
56*433d6423SLionel Sambuc bytes = m_ptr->m_lsys_krn_sys_copy.nr_bytes;
57*433d6423SLionel Sambuc
58*433d6423SLionel Sambuc /* Now do some checks for both the source and destination virtual address.
59*433d6423SLionel Sambuc * This is done once for _SRC_, then once for _DST_.
60*433d6423SLionel Sambuc */
61*433d6423SLionel Sambuc for (i=_SRC_; i<=_DST_; i++) {
62*433d6423SLionel Sambuc int p;
63*433d6423SLionel Sambuc /* Check if process number was given implicitly with SELF and is valid. */
64*433d6423SLionel Sambuc if (vir_addr[i].proc_nr_e == SELF)
65*433d6423SLionel Sambuc vir_addr[i].proc_nr_e = caller->p_endpoint;
66*433d6423SLionel Sambuc if (vir_addr[i].proc_nr_e != NONE) {
67*433d6423SLionel Sambuc if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
68*433d6423SLionel Sambuc printf("do_copy: %d: %d not ok endpoint\n", i, vir_addr[i].proc_nr_e);
69*433d6423SLionel Sambuc return(EINVAL);
70*433d6423SLionel Sambuc }
71*433d6423SLionel Sambuc }
72*433d6423SLionel Sambuc }
73*433d6423SLionel Sambuc
74*433d6423SLionel Sambuc /* Check for overflow. This would happen for 64K segments and 16-bit
75*433d6423SLionel Sambuc * vir_bytes. Especially copying by the PM on do_fork() is affected.
76*433d6423SLionel Sambuc */
77*433d6423SLionel Sambuc if (bytes != (phys_bytes) (vir_bytes) bytes) return(E2BIG);
78*433d6423SLionel Sambuc
79*433d6423SLionel Sambuc /* Now try to make the actual virtual copy. */
80*433d6423SLionel Sambuc if(m_ptr->m_lsys_krn_sys_copy.flags & CP_FLAG_TRY) {
81*433d6423SLionel Sambuc int r;
82*433d6423SLionel Sambuc assert(caller->p_endpoint == VFS_PROC_NR);
83*433d6423SLionel Sambuc r = virtual_copy(&vir_addr[_SRC_], &vir_addr[_DST_], bytes);
84*433d6423SLionel Sambuc if(r == EFAULT_SRC || r == EFAULT_DST) return r = EFAULT;
85*433d6423SLionel Sambuc return r;
86*433d6423SLionel Sambuc } else {
87*433d6423SLionel Sambuc return( virtual_copy_vmcheck(caller, &vir_addr[_SRC_],
88*433d6423SLionel Sambuc &vir_addr[_DST_], bytes) );
89*433d6423SLionel Sambuc }
90*433d6423SLionel Sambuc }
91*433d6423SLionel Sambuc #endif /* (USE_VIRCOPY || USE_PHYSCOPY) */
92