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

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