Added lance entry to drivers.conf.
[minix3-old.git] / kernel / system / do_copy.c
blob716ec1a85989341d4be829d703ddcd5634e1916d
1 /* The kernel call implemented in this file:
2 * m_type: SYS_VIRCOPY, SYS_PHYSCOPY
4 * The parameters for this kernel call are:
5 * m5_c1: CP_SRC_SPACE source virtual segment
6 * m5_l1: CP_SRC_ADDR source offset within segment
7 * m5_i1: CP_SRC_PROC_NR source process number
8 * m5_c2: CP_DST_SPACE destination virtual segment
9 * m5_l2: CP_DST_ADDR destination offset within segment
10 * m5_i2: CP_DST_PROC_NR destination process number
11 * m5_l3: CP_NR_BYTES number of bytes to copy
14 #include "../system.h"
15 #include <minix/type.h>
17 #if (USE_VIRCOPY || USE_PHYSCOPY)
19 /*===========================================================================*
20 * do_copy *
21 *===========================================================================*/
22 PUBLIC int do_copy(m_ptr)
23 register message *m_ptr; /* pointer to request message */
25 /* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
26 * physical addressing. Although a single handler function is used, there
27 * are two different kernel calls so that permissions can be checked.
29 struct vir_addr vir_addr[2]; /* virtual source and destination address */
30 phys_bytes bytes; /* number of bytes to copy */
31 int i;
33 if (m_ptr->m_source != 0 && m_ptr->m_source != 1 &&
34 m_ptr->m_source != 2 && m_ptr->m_source != 3)
36 static int first=1;
37 if (first)
39 first= 0;
40 kprintf(
41 "do_copy: got request from %d (source %d, seg %d, destination %d, seg %d)\n",
42 m_ptr->m_source,
43 m_ptr->CP_SRC_ENDPT,
44 m_ptr->CP_SRC_SPACE,
45 m_ptr->CP_DST_ENDPT,
46 m_ptr->CP_DST_SPACE);
50 /* Dismember the command message. */
51 vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
52 vir_addr[_SRC_].segment = m_ptr->CP_SRC_SPACE;
53 vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
54 vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
55 vir_addr[_DST_].segment = m_ptr->CP_DST_SPACE;
56 vir_addr[_DST_].offset = (vir_bytes) m_ptr->CP_DST_ADDR;
57 bytes = (phys_bytes) m_ptr->CP_NR_BYTES;
59 /* Now do some checks for both the source and destination virtual address.
60 * This is done once for _SRC_, then once for _DST_.
62 for (i=_SRC_; i<=_DST_; i++) {
63 int p;
64 /* Check if process number was given implictly with SELF and is valid. */
65 if (vir_addr[i].proc_nr_e == SELF)
66 vir_addr[i].proc_nr_e = m_ptr->m_source;
67 if (vir_addr[i].segment != PHYS_SEG &&
68 ! isokendpt(vir_addr[i].proc_nr_e, &p))
69 return(EINVAL);
71 /* Check if physical addressing is used without SYS_PHYSCOPY. */
72 if ((vir_addr[i].segment & PHYS_SEG) &&
73 m_ptr->m_type != SYS_PHYSCOPY) return(EPERM);
76 /* Check for overflow. This would happen for 64K segments and 16-bit
77 * vir_bytes. Especially copying by the PM on do_fork() is affected.
79 if (bytes != (vir_bytes) bytes) return(E2BIG);
81 /* Now try to make the actual virtual copy. */
82 return( virtual_copy(&vir_addr[_SRC_], &vir_addr[_DST_], bytes) );
84 #endif /* (USE_VIRCOPY || USE_PHYSCOPY) */