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                         m->msg_name = 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(VERIFY_READ, &m->msg_iov[ct], sizeof(struct iovec));
  54                 if(err)
  55                         return err;
  56                 memcpy_fromfs(&iov[ct], &m->msg_iov[ct], sizeof(struct iovec));
  57                 err=verify_area(mode, iov[ct].iov_base, iov[ct].iov_len);
  58                 if(err)
  59                         return err;
  60                 len+=iov[ct].iov_len;
  61         }
  62         m->msg_iov=&iov[0];
  63         return len;
  64 }
  65 
  66 
  67 
  68 
  69  
  70 void memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
     
  71 {
  72         while(len>0)
  73         {
  74                 if(iov->iov_len)
  75                 {
  76                         int copy = min(iov->iov_len,len);
  77                         memcpy_tofs(iov->iov_base,kdata,copy);
  78                         kdata+=copy;
  79                         len-=copy;
  80                         iov->iov_len-=copy;
  81                         iov->iov_base+=copy;
  82                 }
  83                 iov++;
  84         }
  85 }
  86 
  87 
  88 
  89 
  90  
  91 void memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
     
  92 {
  93         while(len>0)
  94         {
  95                 if(iov->iov_len)
  96                 {
  97                         int copy=min(len,iov->iov_len);
  98                         memcpy_fromfs(kdata, iov->iov_base, copy);
  99                         len-=copy;
 100                         kdata+=copy;
 101                         iov->iov_base+=copy;
 102                         iov->iov_len-=copy;
 103                 }
 104                 iov++;
 105         }
 106 }