This source file includes following definitions.
- min
- verify_iovec
- memcpy_toiovec
- memcpy_fromiovec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include <linux/config.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/net.h>
21 #include <asm/segment.h>
22
23
24 extern inline int min(int x, int y)
25 {
26 return x>y?y:x;
27 }
28
29 int verify_iovec(struct msghdr *m, struct iovec *iov, char *address, int mode)
30 {
31 int err=0;
32 int len=0;
33 int ct;
34
35 if(m->msg_name!=NULL)
36 {
37 if(mode==VERIFY_READ)
38 err=move_addr_to_kernel(m->msg_name, m->msg_namelen, address);
39 else
40 err=verify_area(mode, m->msg_name, m->msg_namelen);
41 if(err<0)
42 return err;
43 }
44 if(m->msg_accrights!=NULL)
45 {
46 err=verify_area(mode, m->msg_accrights, m->msg_accrightslen);
47 if(err)
48 return err;
49 }
50
51 for(ct=0;ct<m->msg_iovlen;ct++)
52 {
53 err=verify_area(mode, m->msg_iov[ct].iov_base, m->msg_iov[ct].iov_len);
54 if(err)
55 return err;
56 len+=m->msg_iov[ct].iov_len;
57 }
58
59 return len;
60 }
61
62
63
64
65
66 void memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
67 {
68 while(len>0)
69 {
70 if(iov->iov_len)
71 {
72 int copy = min(iov->iov_len,len);
73 memcpy_tofs(iov->iov_base,kdata,copy);
74 kdata+=copy;
75 len-=copy;
76 iov->iov_len-=copy;
77 iov->iov_base+=copy;
78 }
79 iov++;
80 }
81 }
82
83
84
85
86
87 void memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
88 {
89 while(len>0)
90 {
91 if(iov->iov_len)
92 {
93 int copy=min(len,iov->iov_len);
94 memcpy_fromfs(kdata, iov->iov_base, copy);
95 len-=copy;
96 kdata+=copy;
97 iov->iov_base+=copy;
98 iov->iov_len-=copy;
99 }
100 iov++;
101 }
102 }
103