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