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_s1: CP_SRC_SPACE source virtual segment
6 * m5_l1: CP_SRC_ADDR source offset within segment
7 * m5_i1: CP_SRC_ENDPT source process number
8 * m5_s2: CP_DST_SPACE destination virtual segment
9 * m5_l2: CP_DST_ADDR destination offset within segment
10 * m5_i2: CP_DST_ENDPT 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 /*===========================================================================*
21 *===========================================================================*/
22 PUBLIC
int do_copy(struct proc
* caller
, message
* m_ptr
)
24 /* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
25 * physical addressing. Although a single handler function is used, there
26 * are two different kernel calls so that permissions can be checked.
28 struct vir_addr vir_addr
[2]; /* virtual source and destination address */
29 phys_bytes bytes
; /* number of bytes to copy */
33 if (m_ptr
->m_source
!= PM_PROC_NR
&& m_ptr
->m_source
!= VFS_PROC_NR
&&
34 m_ptr
->m_source
!= RS_PROC_NR
&& m_ptr
->m_source
!= MEM_PROC_NR
&&
35 m_ptr
->m_source
!= VM_PROC_NR
)
42 "do_copy: got request from %d (source %d, seg %d, destination %d, seg %d)\n",
52 /* Dismember the command message. */
53 vir_addr
[_SRC_
].proc_nr_e
= m_ptr
->CP_SRC_ENDPT
;
54 vir_addr
[_SRC_
].segment
= m_ptr
->CP_SRC_SPACE
;
55 vir_addr
[_SRC_
].offset
= (vir_bytes
) m_ptr
->CP_SRC_ADDR
;
56 vir_addr
[_DST_
].proc_nr_e
= m_ptr
->CP_DST_ENDPT
;
57 vir_addr
[_DST_
].segment
= m_ptr
->CP_DST_SPACE
;
58 vir_addr
[_DST_
].offset
= (vir_bytes
) m_ptr
->CP_DST_ADDR
;
59 bytes
= (phys_bytes
) m_ptr
->CP_NR_BYTES
;
61 /* Now do some checks for both the source and destination virtual address.
62 * This is done once for _SRC_, then once for _DST_.
64 for (i
=_SRC_
; i
<=_DST_
; i
++) {
66 /* Check if process number was given implictly with SELF and is valid. */
67 if (vir_addr
[i
].proc_nr_e
== SELF
)
68 vir_addr
[i
].proc_nr_e
= m_ptr
->m_source
;
69 if (vir_addr
[i
].segment
!= PHYS_SEG
) {
70 if(! isokendpt(vir_addr
[i
].proc_nr_e
, &p
)) {
71 printf("do_copy: %d: seg 0x%x, %d not ok endpoint\n",
72 i
, vir_addr
[i
].segment
, vir_addr
[i
].proc_nr_e
);
77 /* Check if physical addressing is used without SYS_PHYSCOPY. */
78 if ((vir_addr
[i
].segment
& PHYS_SEG
) &&
79 m_ptr
->m_type
!= SYS_PHYSCOPY
) return(EPERM
);
82 /* Check for overflow. This would happen for 64K segments and 16-bit
83 * vir_bytes. Especially copying by the PM on do_fork() is affected.
85 if (bytes
!= (phys_bytes
) (vir_bytes
) bytes
) return(E2BIG
);
87 /* Now try to make the actual virtual copy. */
88 return( virtual_copy_vmcheck(caller
, &vir_addr
[_SRC_
],
89 &vir_addr
[_DST_
], bytes
) );
91 #endif /* (USE_VIRCOPY || USE_PHYSCOPY) */