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         }
  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  *      Copy kernel to iovec.
  67  */
  68  
  69 void memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  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  *      Copy iovec to kernel.
  88  */
  89  
  90 void memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 }

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