2012-12-07 89 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它在同一個文件中,我包含片段 –