OSDN Git Service

lz4: fix wrong compress buffer size for 64-bits
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / uaccess.h
1 #ifndef __LINUX_UACCESS_H__
2 #define __LINUX_UACCESS_H__
3
4 #include <linux/sched.h>
5
6 #define uaccess_kernel() segment_eq(get_fs(), KERNEL_DS)
7
8 #include <asm/uaccess.h>
9
10 static __always_inline void pagefault_disabled_inc(void)
11 {
12         current->pagefault_disabled++;
13 }
14
15 static __always_inline void pagefault_disabled_dec(void)
16 {
17         current->pagefault_disabled--;
18         WARN_ON(current->pagefault_disabled < 0);
19 }
20
21 /*
22  * These routines enable/disable the pagefault handler. If disabled, it will
23  * not take any locks and go straight to the fixup table.
24  *
25  * User access methods will not sleep when called from a pagefault_disabled()
26  * environment.
27  */
28 static inline void pagefault_disable(void)
29 {
30         pagefault_disabled_inc();
31         /*
32          * make sure to have issued the store before a pagefault
33          * can hit.
34          */
35         barrier();
36 }
37
38 static inline void pagefault_enable(void)
39 {
40         /*
41          * make sure to issue those last loads/stores before enabling
42          * the pagefault handler again.
43          */
44         barrier();
45         pagefault_disabled_dec();
46 }
47
48 /*
49  * Is the pagefault handler disabled? If so, user access methods will not sleep.
50  */
51 #define pagefault_disabled() (current->pagefault_disabled != 0)
52
53 /*
54  * The pagefault handler is in general disabled by pagefault_disable() or
55  * when in irq context (via in_atomic()).
56  *
57  * This function should only be used by the fault handlers. Other users should
58  * stick to pagefault_disabled().
59  * Please NEVER use preempt_disable() to disable the fault handler. With
60  * !CONFIG_PREEMPT_COUNT, this is like a NOP. So the handler won't be disabled.
61  * in_atomic() will report different values based on !CONFIG_PREEMPT_COUNT.
62  */
63 #define faulthandler_disabled() (pagefault_disabled() || in_atomic())
64
65 #ifndef ARCH_HAS_NOCACHE_UACCESS
66
67 static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
68                                 const void __user *from, unsigned long n)
69 {
70         return __copy_from_user_inatomic(to, from, n);
71 }
72
73 static inline unsigned long __copy_from_user_nocache(void *to,
74                                 const void __user *from, unsigned long n)
75 {
76         return __copy_from_user(to, from, n);
77 }
78
79 #endif          /* ARCH_HAS_NOCACHE_UACCESS */
80
81 /*
82  * probe_kernel_read(): safely attempt to read from a location
83  * @dst: pointer to the buffer that shall take the data
84  * @src: address to read from
85  * @size: size of the data chunk
86  *
87  * Safely read from address @src to the buffer at @dst.  If a kernel fault
88  * happens, handle that and return -EFAULT.
89  */
90 extern long probe_kernel_read(void *dst, const void *src, size_t size);
91 extern long __probe_kernel_read(void *dst, const void *src, size_t size);
92
93 /*
94  * probe_kernel_write(): safely attempt to write to a location
95  * @dst: address to write to
96  * @src: pointer to the data that shall be written
97  * @size: size of the data chunk
98  *
99  * Safely write to address @dst from the buffer at @src.  If a kernel fault
100  * happens, handle that and return -EFAULT.
101  */
102 extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
103 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
104
105 extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count);
106
107 /**
108  * probe_kernel_address(): safely attempt to read from a location
109  * @addr: address to read from
110  * @retval: read into this variable
111  *
112  * Returns 0 on success, or -EFAULT.
113  */
114 #define probe_kernel_address(addr, retval)              \
115         probe_kernel_read(&retval, addr, sizeof(retval))
116
117 #ifndef user_access_begin
118 #define user_access_begin() do { } while (0)
119 #define user_access_end() do { } while (0)
120 #define unsafe_get_user(x, ptr, err) do { if (unlikely(__get_user(x, ptr))) goto err; } while (0)
121 #define unsafe_put_user(x, ptr, err) do { if (unlikely(__put_user(x, ptr))) goto err; } while (0)
122 #endif
123
124 #endif          /* __LINUX_UACCESS_H__ */