[4] | 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 | *===========================================================================*/
|
---|
| 22 | PUBLIC int do_copy(m_ptr)
|
---|
| 23 | register 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 = m_ptr->CP_SRC_PROC_NR;
|
---|
| 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 = m_ptr->CP_DST_PROC_NR;
|
---|
| 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 |
|
---|
| 47 | /* Check if process number was given implictly with SELF and is valid. */
|
---|
| 48 | if (vir_addr[i].proc_nr == SELF) vir_addr[i].proc_nr = m_ptr->m_source;
|
---|
| 49 | if (! isokprocn(vir_addr[i].proc_nr) && vir_addr[i].segment != PHYS_SEG)
|
---|
| 50 | return(EINVAL);
|
---|
| 51 |
|
---|
| 52 | /* Check if physical addressing is used without SYS_PHYSCOPY. */
|
---|
| 53 | if ((vir_addr[i].segment & PHYS_SEG) &&
|
---|
| 54 | m_ptr->m_type != SYS_PHYSCOPY) return(EPERM);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /* Check for overflow. This would happen for 64K segments and 16-bit
|
---|
| 58 | * vir_bytes. Especially copying by the PM on do_fork() is affected.
|
---|
| 59 | */
|
---|
| 60 | if (bytes != (vir_bytes) bytes) return(E2BIG);
|
---|
| 61 |
|
---|
| 62 | /* Now try to make the actual virtual copy. */
|
---|
| 63 | return( virtual_copy(&vir_addr[_SRC_], &vir_addr[_DST_], bytes) );
|
---|
| 64 | }
|
---|
| 65 | #endif /* (USE_VIRCOPY || USE_PHYSCOPY) */
|
---|
| 66 |
|
---|