2012-12-07 88 views
0

在Linux系统上,哪里定义和实现了函数copy_to_user和copy_from_user?copy_to_user在哪里定义

+1

我推荐使用ctags或cstope。我建议使用ctags vim(或emacs) - 这对我很有帮助。 http://kernelnewbies.org/FAQ/CodeBrowsing,http://0x8086.blogspot.cz/2011/02/gvim-ctags-and-linux-kernel.html,http://courses.cs.washington.edu/ course/cse451/10au/tutorials/tutorial_ctags.html – pevik

回答

4

它在asm/uaccess.h定义,例如,在/usr/src/linux-3.0.6-gentoo/include/asm-generic/uaccess.h

static inline long copy_from_user(void *to, 
       const void __user * from, unsigned long n) 
{ 
     might_sleep(); 
     if (access_ok(VERIFY_READ, from, n)) 
       return __copy_from_user(to, from, n); 
     else 
       return n; 
} 

static inline long copy_to_user(void __user *to, 
       const void *from, unsigned long n) 
{ 
     might_sleep(); 
     if (access_ok(VERIFY_WRITE, to, n)) 
       return __copy_to_user(to, from, n); 
     else 
       return n; 
} 

而且__copy_to_user

#ifndef __copy_to_user 
static inline __must_check long __copy_to_user(void __user *to, 
       const void *from, unsigned long n) 
{ 
     if (__builtin_constant_p(n)) { 
       switch(n) { 
       case 1: 
         *(u8 __force *)to = *(u8 *)from; 
         return 0; 
       case 2: 
         *(u16 __force *)to = *(u16 *)from; 
         return 0; 
       case 4: 
         *(u32 __force *)to = *(u32 *)from; 
         return 0; 
#ifdef CONFIG_64BIT 
       case 8: 
         *(u64 __force *)to = *(u64 *)from; 
         return 0; 
#endif 
       default: 
         break; 
       } 
     } 

     memcpy((void __force *)to, from, n); 
     return 0; 
} 
#endif 
+0

这导致下一个问题:__copy_to_user()定义在哪里:-) –

+0

@ott它在同一个文件中,我包含片段 –