source: trunk/minix/kernel/system/do_copy.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 2.6 KB
Line 
1/* The kernel call implemented in this file:
2 * m_type: SYS_VIRCOPY, SYS_PHYSCOPY
3 *
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
12 */
13
14#include "../system.h"
15#include <minix/type.h>
16
17#if (USE_VIRCOPY || USE_PHYSCOPY)
18
19/*===========================================================================*
20 * do_copy *
21 *===========================================================================*/
22PUBLIC int do_copy(m_ptr)
23register message *m_ptr; /* pointer to request message */
24{
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.
28 */
29 struct vir_addr vir_addr[2]; /* virtual source and destination address */
30 phys_bytes bytes; /* number of bytes to copy */
31 int i;
32
33 /* Dismember the command message. */
34 vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
35 vir_addr[_SRC_].segment = m_ptr->CP_SRC_SPACE;
36 vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
37 vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
38 vir_addr[_DST_].segment = m_ptr->CP_DST_SPACE;
39 vir_addr[_DST_].offset = (vir_bytes) m_ptr->CP_DST_ADDR;
40 bytes = (phys_bytes) m_ptr->CP_NR_BYTES;
41
42 /* Now do some checks for both the source and destination virtual address.
43 * This is done once for _SRC_, then once for _DST_.
44 */
45 for (i=_SRC_; i<=_DST_; i++) {
46 int p;
47 /* Check if process number was given implictly with SELF and is valid. */
48 if (vir_addr[i].proc_nr_e == SELF)
49 vir_addr[i].proc_nr_e = m_ptr->m_source;
50 if (vir_addr[i].segment != PHYS_SEG &&
51 ! isokendpt(vir_addr[i].proc_nr_e, &p))
52 return(EINVAL);
53
54 /* Check if physical addressing is used without SYS_PHYSCOPY. */
55 if ((vir_addr[i].segment & PHYS_SEG) &&
56 m_ptr->m_type != SYS_PHYSCOPY) return(EPERM);
57 }
58
59 /* Check for overflow. This would happen for 64K segments and 16-bit
60 * vir_bytes. Especially copying by the PM on do_fork() is affected.
61 */
62 if (bytes != (vir_bytes) bytes) return(E2BIG);
63
64 /* Now try to make the actual virtual copy. */
65 return( virtual_copy(&vir_addr[_SRC_], &vir_addr[_DST_], bytes) );
66}
67#endif /* (USE_VIRCOPY || USE_PHYSCOPY) */
68
Note: See TracBrowser for help on using the repository browser.