Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/uaccess.h
Show All 36 Lines | |||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <vm/vm.h> | #include <vm/vm.h> | ||||
#include <vm/vm_extern.h> | #include <vm/vm_extern.h> | ||||
#include <linux/compiler.h> | #include <linux/compiler.h> | ||||
#include <asm/uaccess.h> | |||||
#define VERIFY_READ VM_PROT_READ | #define VERIFY_READ VM_PROT_READ | ||||
#define VERIFY_WRITE VM_PROT_WRITE | #define VERIFY_WRITE VM_PROT_WRITE | ||||
#define __get_user(_x, _p) ({ \ | #define __get_user(_x, _p) ({ \ | ||||
int __err; \ | int __err; \ | ||||
__typeof(*(_p)) __x; \ | __typeof(*(_p)) __x; \ | ||||
__err = linux_copyin((_p), &(__x), sizeof(*(_p))); \ | __err = linux_copyin((_p), &(__x), sizeof(*(_p))); \ | ||||
(_x) = __x; \ | (_x) = __x; \ | ||||
Show All 9 Lines | |||||
#define clear_user(...) linux_clear_user(__VA_ARGS__) | #define clear_user(...) linux_clear_user(__VA_ARGS__) | ||||
#define access_ok(...) linux_access_ok(__VA_ARGS__) | #define access_ok(...) linux_access_ok(__VA_ARGS__) | ||||
extern int linux_copyin(const void *uaddr, void *kaddr, size_t len); | extern int linux_copyin(const void *uaddr, void *kaddr, size_t len); | ||||
extern int linux_copyout(const void *kaddr, void *uaddr, size_t len); | extern int linux_copyout(const void *kaddr, void *uaddr, size_t len); | ||||
extern size_t linux_clear_user(void *uaddr, size_t len); | extern size_t linux_clear_user(void *uaddr, size_t len); | ||||
extern int linux_access_ok(int rw, const 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 | * NOTE: Each pagefault_disable() call must have a corresponding | ||||
* pagefault_enable() call in the same scope. The former creates a new | * pagefault_enable() call in the same scope. The former creates a new | ||||
* block and defines a temporary variable, and the latter uses the | * block and defines a temporary variable, and the latter uses the | ||||
* temporary variable and closes the block. Failure to balance the | * temporary variable and closes the block. Failure to balance the | ||||
* calls will result in a compile-time error. | * calls will result in a compile-time error. | ||||
*/ | */ | ||||
#define pagefault_disable(void) do { \ | #define pagefault_disable(void) do { \ | ||||
int __saved_pflags = \ | int __saved_pflags = \ | ||||
vm_fault_disable_pagefaults() | vm_fault_disable_pagefaults() | ||||
#define pagefault_enable(void) \ | #define pagefault_enable(void) \ | ||||
vm_fault_enable_pagefaults(__saved_pflags); \ | vm_fault_enable_pagefaults(__saved_pflags); \ | ||||
} while (0) | } while (0) | ||||
static inline bool | static inline bool | ||||
pagefault_disabled(void) | pagefault_disabled(void) | ||||
{ | { | ||||
return ((curthread->td_pflags & TDP_NOFAULTING) != 0); | 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_ */ | #endif /* _LINUX_UACCESS_H_ */ |