Index: sys/compat/linuxkpi/common/include/asm/uaccess.h =================================================================== --- sys/compat/linuxkpi/common/include/asm/uaccess.h +++ sys/compat/linuxkpi/common/include/asm/uaccess.h @@ -31,25 +31,32 @@ #ifndef _ASM_UACCESS_H_ #define _ASM_UACCESS_H_ -#include +/* -static inline long -copy_to_user(void *to, const void *from, unsigned long n) -{ - if (linux_copyout(from, to, n) != 0) - return n; - return 0; -} -#define __copy_to_user(...) copy_to_user(__VA_ARGS__) +Disable. Need __{get,put}_user_size() functions... +Use defaults in linux/uaccess.h for now. -static inline long -copy_from_user(void *to, const void *from, unsigned long n) -{ - if (linux_copyin(from, to, n) != 0) - return n; - return 0; -} -#define __copy_from_user(...) copy_from_user(__VA_ARGS__) -#define __copy_in_user(...) copy_from_user(__VA_ARGS__) +#define user_access_begin() stac() +#define user_access_end() clac() + +#define unsafe_put_user(x, ptr, err_label) \ + do { \ + int __error; \ + __typeof__(*(ptr)) __x = (x); \ + __put_user_size(__x, (ptr), sizeof(*(ptr)), \ + __error, -EFAULT); \ + if (unlikely(__error)) goto err_label; \ + } while (0) + +#define unsafe_get_user(x, ptr, err_label) \ + do { \ + int __error; \ + __inttype(*(ptr)) __x; \ + __get_user_size(__x, (ptr), sizeof(*(ptr)), \ + __error, -EFAULT); \ + (x) = (__force __typeof__(*(ptr)))__x; \ + if (unlikely(__error)) goto err_label; \ + } while (0) +*/ #endif /* _ASM_UACCESS_H_ */ Index: sys/compat/linuxkpi/common/include/linux/kernel.h =================================================================== --- sys/compat/linuxkpi/common/include/linux/kernel.h +++ sys/compat/linuxkpi/common/include/linux/kernel.h @@ -88,7 +88,9 @@ #define BUILD_BUG() do { CTASSERT(0); } while (0) #define BUILD_BUG_ON(x) CTASSERT(!(x)) +#ifndef BUILD_BUG_ON_MSG #define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x) +#endif #define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x)) #define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); } @@ -372,6 +374,56 @@ return (0); } +static inline int +kstrtobool(const char *s, bool *res) +{ + if (!s) + return -EINVAL; + + switch (s[0]) { + case 'y': + case 'Y': + case '1': + *res = true; + return 0; + case 'n': + case 'N': + case '0': + *res = false; + return 0; + case 'o': + case 'O': + switch (s[1]) { + case 'n': + case 'N': + *res = true; + return 0; + case 'f': + case 'F': + *res = false; + return 0; + default: + break; + } + default: + break; + } + + return -EINVAL; +} + +static inline int +kstrtobool_from_user(const char __user *s, size_t count, bool *res) +{ + char buf[4]; + + count = min(count, sizeof(buf) - 1); + if (copy_from_user(buf, s, count)) + return -EFAULT; + buf[count] = '\0'; + return kstrtobool(buf, res); +} + #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) Index: sys/compat/linuxkpi/common/include/linux/time.h =================================================================== --- sys/compat/linuxkpi/common/include/linux/time.h +++ sys/compat/linuxkpi/common/include/linux/time.h @@ -40,6 +40,8 @@ #include #include +#define timespec64 timespec + static inline struct timeval ns_to_timeval(const int64_t nsec) { Index: sys/compat/linuxkpi/common/include/linux/timer.h =================================================================== --- sys/compat/linuxkpi/common/include/linux/timer.h +++ sys/compat/linuxkpi/common/include/linux/timer.h @@ -64,7 +64,7 @@ #define setup_timer(timer, func, dat) do { \ (timer)->function = (func); \ (timer)->data = (dat); \ - callout_init(&(timer)->callout, 1); \ + callout_init(&(timer)->callout, 1); \ } while (0) #define __setup_timer(timer, func, dat, flags) do { \ @@ -75,7 +75,7 @@ #define init_timer(timer) do { \ (timer)->function = NULL; \ (timer)->data = 0; \ - callout_init(&(timer)->callout, 1); \ + callout_init(&(timer)->callout, 1); \ } while (0) extern void mod_timer(struct timer_list *, int); Index: sys/compat/linuxkpi/common/include/linux/uaccess.h =================================================================== --- sys/compat/linuxkpi/common/include/linux/uaccess.h +++ sys/compat/linuxkpi/common/include/linux/uaccess.h @@ -42,6 +42,8 @@ #include +#include + #define VERIFY_READ VM_PROT_READ #define VERIFY_WRITE VM_PROT_WRITE @@ -67,6 +69,25 @@ extern size_t linux_clear_user(void *uaddr, size_t len); extern int linux_access_ok(int rw, const void *uaddr, size_t len); +static inline long +copy_to_user(void *to, const void *from, unsigned long n) +{ + if (linux_copyout(from, to, n) != 0) + return n; + return 0; +} +#define __copy_to_user(...) copy_to_user(__VA_ARGS__) + +static inline long +copy_from_user(void *to, const void *from, unsigned long n) +{ + if (linux_copyin(from, to, n) != 0) + return n; + return 0; +} +#define __copy_from_user(...) copy_from_user(__VA_ARGS__) +#define __copy_in_user(...) copy_from_user(__VA_ARGS__) + /* * NOTE: Each pagefault_disable() call must have a corresponding * pagefault_enable() call in the same scope. The former creates a new @@ -88,4 +109,20 @@ return ((curthread->td_pflags & TDP_NOFAULTING) != 0); } +#ifndef user_access_begin +#define user_access_begin() do { } while (0) +#define user_access_end() do { } while (0) + +#define unsafe_get_user(x, ptr, err) do { \ + if (unlikely(__get_user(x, ptr))) \ + goto err; \ + } while (0) + +#define unsafe_put_user(x, ptr, err) do { \ + if (unlikely(__put_user(x, ptr))) \ + goto err; \ + } while (0) + +#endif + #endif /* _LINUX_UACCESS_H_ */