1 | /* The kernel call implemented in this file:
|
---|
2 | * m_type: SYS_VIRVCOPY, SYS_PHYSVCOPY
|
---|
3 | *
|
---|
4 | * The parameters for this kernel call are:
|
---|
5 | * m1_i3: VCP_VEC_SIZE size of copy request vector
|
---|
6 | * m1_p1: VCP_VEC_ADDR address of vector at caller
|
---|
7 | * m1_i2: VCP_NR_OK number of successfull copies
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "../system.h"
|
---|
11 | #include <minix/type.h>
|
---|
12 |
|
---|
13 | #if (USE_VIRVCOPY || USE_PHYSVCOPY)
|
---|
14 |
|
---|
15 | /* Buffer to hold copy request vector from user. */
|
---|
16 | PRIVATE struct vir_cp_req vir_cp_req[VCOPY_VEC_SIZE];
|
---|
17 |
|
---|
18 | /*===========================================================================*
|
---|
19 | * do_vcopy *
|
---|
20 | *===========================================================================*/
|
---|
21 | PUBLIC int do_vcopy(m_ptr)
|
---|
22 | register message *m_ptr; /* pointer to request message */
|
---|
23 | {
|
---|
24 | /* Handle sys_virvcopy() and sys_physvcopy() that pass a vector with copy
|
---|
25 | * requests. Although a single handler function is used, there are two
|
---|
26 | * different kernel calls so that permissions can be checked.
|
---|
27 | */
|
---|
28 | int nr_req;
|
---|
29 | vir_bytes caller_vir;
|
---|
30 | phys_bytes caller_phys;
|
---|
31 | phys_bytes kernel_phys;
|
---|
32 | phys_bytes bytes;
|
---|
33 | int i,s;
|
---|
34 | struct vir_cp_req *req;
|
---|
35 |
|
---|
36 | /* Check if request vector size is ok. */
|
---|
37 | nr_req = (unsigned) m_ptr->VCP_VEC_SIZE;
|
---|
38 | if (nr_req > VCOPY_VEC_SIZE) return(EINVAL);
|
---|
39 | bytes = nr_req * sizeof(struct vir_cp_req);
|
---|
40 |
|
---|
41 | /* Calculate physical addresses and copy (port,value)-pairs from user. */
|
---|
42 | caller_vir = (vir_bytes) m_ptr->VCP_VEC_ADDR;
|
---|
43 | caller_phys = umap_local(proc_addr(who_p), D, caller_vir, bytes);
|
---|
44 | if (0 == caller_phys) return(EFAULT);
|
---|
45 | kernel_phys = vir2phys(vir_cp_req);
|
---|
46 | phys_copy(caller_phys, kernel_phys, (phys_bytes) bytes);
|
---|
47 |
|
---|
48 | /* Assume vector with requests is correct. Try to copy everything. */
|
---|
49 | m_ptr->VCP_NR_OK = 0;
|
---|
50 | for (i=0; i<nr_req; i++) {
|
---|
51 |
|
---|
52 | req = &vir_cp_req[i];
|
---|
53 |
|
---|
54 | /* Check if physical addressing is used without SYS_PHYSVCOPY. */
|
---|
55 | if (((req->src.segment | req->dst.segment) & PHYS_SEG) &&
|
---|
56 | m_ptr->m_type != SYS_PHYSVCOPY) return(EPERM);
|
---|
57 | if ((s=virtual_copy(&req->src, &req->dst, req->count)) != OK)
|
---|
58 | return(s);
|
---|
59 | m_ptr->VCP_NR_OK ++;
|
---|
60 | }
|
---|
61 | return(OK);
|
---|
62 | }
|
---|
63 |
|
---|
64 | #endif /* (USE_VIRVCOPY || USE_PHYSVCOPY) */
|
---|
65 |
|
---|