|
@@ -715,3 +715,199 @@ extern size_t __copy_user(void *__to, const void *__from, size_t __n);
|
|
|
__cu_to = (to); \
|
|
|
__cu_from = (from); \
|
|
|
__cu_len = (n); \
|
|
|
+ might_fault(); \
|
|
|
+ __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, __cu_len); \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n);
|
|
|
+
|
|
|
+#define __copy_to_user_inatomic(to, from, n) \
|
|
|
+({ \
|
|
|
+ void __user *__cu_to; \
|
|
|
+ const void *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|
|
|
+ __cu_to = (to); \
|
|
|
+ __cu_from = (from); \
|
|
|
+ __cu_len = (n); \
|
|
|
+ __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, __cu_len); \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+#define __copy_from_user_inatomic(to, from, n) \
|
|
|
+({ \
|
|
|
+ void *__cu_to; \
|
|
|
+ const void __user *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|
|
|
+ __cu_to = (to); \
|
|
|
+ __cu_from = (from); \
|
|
|
+ __cu_len = (n); \
|
|
|
+ __cu_len = __invoke_copy_from_user_inatomic(__cu_to, __cu_from, \
|
|
|
+ __cu_len); \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+/*
|
|
|
+ * copy_to_user: - Copy a block of data into user space.
|
|
|
+ * @to: Destination address, in user space.
|
|
|
+ * @from: Source address, in kernel space.
|
|
|
+ * @n: Number of bytes to copy.
|
|
|
+ *
|
|
|
+ * Context: User context only. This function may sleep.
|
|
|
+ *
|
|
|
+ * Copy data from kernel space to user space.
|
|
|
+ *
|
|
|
+ * Returns number of bytes that could not be copied.
|
|
|
+ * On success, this will be zero.
|
|
|
+ */
|
|
|
+#define copy_to_user(to, from, n) \
|
|
|
+({ \
|
|
|
+ void __user *__cu_to; \
|
|
|
+ const void *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|
|
|
+ __cu_to = (to); \
|
|
|
+ __cu_from = (from); \
|
|
|
+ __cu_len = (n); \
|
|
|
+ if (access_ok(VERIFY_WRITE, __cu_to, __cu_len)) { \
|
|
|
+ might_fault(); \
|
|
|
+ __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, \
|
|
|
+ __cu_len); \
|
|
|
+ } \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+#define __invoke_copy_from_user(to, from, n) \
|
|
|
+({ \
|
|
|
+ register void *__cu_to_r __asm__("$4"); \
|
|
|
+ register const void __user *__cu_from_r __asm__("$5"); \
|
|
|
+ register long __cu_len_r __asm__("$6"); \
|
|
|
+ \
|
|
|
+ __cu_to_r = (to); \
|
|
|
+ __cu_from_r = (from); \
|
|
|
+ __cu_len_r = (n); \
|
|
|
+ __asm__ __volatile__( \
|
|
|
+ ".set\tnoreorder\n\t" \
|
|
|
+ __MODULE_JAL(__copy_user) \
|
|
|
+ ".set\tnoat\n\t" \
|
|
|
+ __UA_ADDU "\t$1, %1, %2\n\t" \
|
|
|
+ ".set\tat\n\t" \
|
|
|
+ ".set\treorder" \
|
|
|
+ : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
|
|
|
+ : \
|
|
|
+ : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", \
|
|
|
+ DADDI_SCRATCH, "memory"); \
|
|
|
+ __cu_len_r; \
|
|
|
+})
|
|
|
+
|
|
|
+#define __invoke_copy_from_user_inatomic(to, from, n) \
|
|
|
+({ \
|
|
|
+ register void *__cu_to_r __asm__("$4"); \
|
|
|
+ register const void __user *__cu_from_r __asm__("$5"); \
|
|
|
+ register long __cu_len_r __asm__("$6"); \
|
|
|
+ \
|
|
|
+ __cu_to_r = (to); \
|
|
|
+ __cu_from_r = (from); \
|
|
|
+ __cu_len_r = (n); \
|
|
|
+ __asm__ __volatile__( \
|
|
|
+ ".set\tnoreorder\n\t" \
|
|
|
+ __MODULE_JAL(__copy_user_inatomic) \
|
|
|
+ ".set\tnoat\n\t" \
|
|
|
+ __UA_ADDU "\t$1, %1, %2\n\t" \
|
|
|
+ ".set\tat\n\t" \
|
|
|
+ ".set\treorder" \
|
|
|
+ : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
|
|
|
+ : \
|
|
|
+ : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", \
|
|
|
+ DADDI_SCRATCH, "memory"); \
|
|
|
+ __cu_len_r; \
|
|
|
+})
|
|
|
+
|
|
|
+/*
|
|
|
+ * __copy_from_user: - Copy a block of data from user space, with less checking.
|
|
|
+ * @to: Destination address, in kernel space.
|
|
|
+ * @from: Source address, in user space.
|
|
|
+ * @n: Number of bytes to copy.
|
|
|
+ *
|
|
|
+ * Context: User context only. This function may sleep.
|
|
|
+ *
|
|
|
+ * Copy data from user space to kernel space. Caller must check
|
|
|
+ * the specified block with access_ok() before calling this function.
|
|
|
+ *
|
|
|
+ * Returns number of bytes that could not be copied.
|
|
|
+ * On success, this will be zero.
|
|
|
+ *
|
|
|
+ * If some data could not be copied, this function will pad the copied
|
|
|
+ * data to the requested size using zero bytes.
|
|
|
+ */
|
|
|
+#define __copy_from_user(to, from, n) \
|
|
|
+({ \
|
|
|
+ void *__cu_to; \
|
|
|
+ const void __user *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|
|
|
+ __cu_to = (to); \
|
|
|
+ __cu_from = (from); \
|
|
|
+ __cu_len = (n); \
|
|
|
+ might_fault(); \
|
|
|
+ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
|
|
|
+ __cu_len); \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+/*
|
|
|
+ * copy_from_user: - Copy a block of data from user space.
|
|
|
+ * @to: Destination address, in kernel space.
|
|
|
+ * @from: Source address, in user space.
|
|
|
+ * @n: Number of bytes to copy.
|
|
|
+ *
|
|
|
+ * Context: User context only. This function may sleep.
|
|
|
+ *
|
|
|
+ * Copy data from user space to kernel space.
|
|
|
+ *
|
|
|
+ * Returns number of bytes that could not be copied.
|
|
|
+ * On success, this will be zero.
|
|
|
+ *
|
|
|
+ * If some data could not be copied, this function will pad the copied
|
|
|
+ * data to the requested size using zero bytes.
|
|
|
+ */
|
|
|
+#define copy_from_user(to, from, n) \
|
|
|
+({ \
|
|
|
+ void *__cu_to; \
|
|
|
+ const void __user *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|
|
|
+ __cu_to = (to); \
|
|
|
+ __cu_from = (from); \
|
|
|
+ __cu_len = (n); \
|
|
|
+ if (access_ok(VERIFY_READ, __cu_from, __cu_len)) { \
|
|
|
+ might_fault(); \
|
|
|
+ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
|
|
|
+ __cu_len); \
|
|
|
+ } \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+#define __copy_in_user(to, from, n) \
|
|
|
+({ \
|
|
|
+ void __user *__cu_to; \
|
|
|
+ const void __user *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|
|
|
+ __cu_to = (to); \
|
|
|
+ __cu_from = (from); \
|
|
|
+ __cu_len = (n); \
|
|
|
+ might_fault(); \
|
|
|
+ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
|
|
|
+ __cu_len); \
|
|
|
+ __cu_len; \
|
|
|
+})
|
|
|
+
|
|
|
+#define copy_in_user(to, from, n) \
|
|
|
+({ \
|
|
|
+ void __user *__cu_to; \
|
|
|
+ const void __user *__cu_from; \
|
|
|
+ long __cu_len; \
|
|
|
+ \
|