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

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