root/net/core/iovec.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. min
  2. verify_iovec
  3. memcpy_toiovec
  4. memcpy_fromiovec

   1 /*
   2  *      iovec manipulation routines.
   3  *
   4  *
   5  *              This program is free software; you can redistribute it and/or
   6  *              modify it under the terms of the GNU General Public License
   7  *              as published by the Free Software Foundation; either version
   8  *              2 of the License, or (at your option) any later version.
   9  *
  10  *      Fixes:
  11  *              Andrew Lunn     :       Errors in iovec copying.
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25         return x>y?y:x;
  26 }
  27 
  28 int verify_iovec(struct msghdr *m, struct iovec *iov, char *address, int mode)
     /* [previous][next][first][last][top][bottom][index][help] */
  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                 m->msg_name = address;
  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  *      Copy kernel to iovec.
  68  */
  69  
  70 void memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  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  *      Copy iovec to kernel.
  89  */
  90  
  91 void memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 }

/* [previous][next][first][last][top][bottom][index][help] */