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