~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/uaccess.h

Version: ~ [ linux-5.10-rc1 ] ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef __LINUX_UACCESS_H__
  2 #define __LINUX_UACCESS_H__
  3 
  4 #include <linux/preempt.h>
  5 #include <asm/uaccess.h>
  6 
  7 /*
  8  * These routines enable/disable the pagefault handler in that
  9  * it will not take any locks and go straight to the fixup table.
 10  *
 11  * They have great resemblance to the preempt_disable/enable calls
 12  * and in fact they are identical; this is because currently there is
 13  * no other way to make the pagefault handlers do this. So we do
 14  * disable preemption but we don't necessarily care about that.
 15  */
 16 static inline void pagefault_disable(void)
 17 {
 18         inc_preempt_count();
 19         /*
 20          * make sure to have issued the store before a pagefault
 21          * can hit.
 22          */
 23         barrier();
 24 }
 25 
 26 static inline void pagefault_enable(void)
 27 {
 28         /*
 29          * make sure to issue those last loads/stores before enabling
 30          * the pagefault handler again.
 31          */
 32         barrier();
 33         dec_preempt_count();
 34         /*
 35          * make sure we do..
 36          */
 37         barrier();
 38         preempt_check_resched();
 39 }
 40 
 41 #ifndef ARCH_HAS_NOCACHE_UACCESS
 42 
 43 static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
 44                                 const void __user *from, unsigned long n)
 45 {
 46         return __copy_from_user_inatomic(to, from, n);
 47 }
 48 
 49 static inline unsigned long __copy_from_user_nocache(void *to,
 50                                 const void __user *from, unsigned long n)
 51 {
 52         return __copy_from_user(to, from, n);
 53 }
 54 
 55 #endif          /* ARCH_HAS_NOCACHE_UACCESS */
 56 
 57 /**
 58  * probe_kernel_address(): safely attempt to read from a location
 59  * @addr: address to read from - its type is type typeof(retval)*
 60  * @retval: read into this variable
 61  *
 62  * Safely read from address @addr into variable @revtal.  If a kernel fault
 63  * happens, handle that and return -EFAULT.
 64  * We ensure that the __get_user() is executed in atomic context so that
 65  * do_page_fault() doesn't attempt to take mmap_sem.  This makes
 66  * probe_kernel_address() suitable for use within regions where the caller
 67  * already holds mmap_sem, or other locks which nest inside mmap_sem.
 68  * This must be a macro because __get_user() needs to know the types of the
 69  * args.
 70  *
 71  * We don't include enough header files to be able to do the set_fs().  We
 72  * require that the probe_kernel_address() caller will do that.
 73  */
 74 #define probe_kernel_address(addr, retval)              \
 75         ({                                              \
 76                 long ret;                               \
 77                 mm_segment_t old_fs = get_fs();         \
 78                                                         \
 79                 set_fs(KERNEL_DS);                      \
 80                 pagefault_disable();                    \
 81                 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval));            \
 82                 pagefault_enable();                     \
 83                 set_fs(old_fs);                         \
 84                 ret;                                    \
 85         })
 86 
 87 /*
 88  * probe_kernel_read(): safely attempt to read from a location
 89  * @dst: pointer to the buffer that shall take the data
 90  * @src: address to read from
 91  * @size: size of the data chunk
 92  *
 93  * Safely read from address @src to the buffer at @dst.  If a kernel fault
 94  * happens, handle that and return -EFAULT.
 95  */
 96 extern long probe_kernel_read(void *dst, const void *src, size_t size);
 97 extern long __probe_kernel_read(void *dst, const void *src, size_t size);
 98 
 99 /*
100  * probe_kernel_write(): safely attempt to write to a location
101  * @dst: address to write to
102  * @src: pointer to the data that shall be written
103  * @size: size of the data chunk
104  *
105  * Safely write to address @dst from the buffer at @src.  If a kernel fault
106  * happens, handle that and return -EFAULT.
107  */
108 extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
109 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
110 
111 #endif          /* __LINUX_UACCESS_H__ */
112 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp