📄 uaccess.h
字号:
})#define __get_user_asm_1(x, ptr, err) \({ \ __asm__ __volatile__ ( " iac 1\n" \ " sr %1,%1\n" \ " la 4,%2\n" \ " sr %0,%0\n" \ " sacf 512\n" \ "0: ic %0,0(4)\n" \ " sacf 0(1)\n" \ "1:\n" \ ".section .fixup,\"ax\"\n" \ "2: sacf 0(1)\n" \ " lhi %1,%h3\n" \ " bras 4,3f\n" \ " .long 1b\n" \ "3: l 4,0(4)\n" \ " br 4\n" \ ".previous\n" \ ".section __ex_table,\"a\"\n" \ " .align 4\n" \ " .long 0b,2b\n" \ ".previous" \ : "=d" (x) , "=&d" (err) \ : "m" (*(__u8*) ptr), "K" (-EFAULT) \ : "1", "4" ); \})#define __get_user(x, ptr) \({ \ int __gu_err; \ switch (sizeof(*(ptr))) { \ case 1: \ __get_user_asm_1(x,ptr,__gu_err); \ break; \ case 2: \ __get_user_asm_2(x,ptr,__gu_err); \ break; \ case 4: \ __get_user_asm_4(x,ptr,__gu_err); \ break; \ default: \ (x) = 0; \ __gu_err = __get_user_bad(); \ break; \ } \ __gu_err; \})#define get_user(x, ptr) \({ \ long __gu_err = -EFAULT; \ __typeof__(ptr) __gu_addr = (ptr); \ __typeof__(x) __x; \ if (__access_ok((long)__gu_addr,sizeof(*(ptr)))) { \ __gu_err = 0; \ __get_user((__x), (__gu_addr)); \ (x) = __x; \ } \ else \ (x) = 0; \ __gu_err; \})extern int __get_user_bad(void);/* * access register are set up, that 4 points to secondary (user) , 2 to primary (kernel) */extern inline unsigned long__copy_to_user_asm(void* to, const void* from, long n){ __asm__ __volatile__ ( " iac 1\n" " lr 2,%2\n" " lr 4,%1\n" " lr 3,%0\n" " lr 5,3\n" " sacf 512\n" "0: mvcle 4,2,0\n" " jo 0b\n" "1: sacf 0(1)\n" " lr %0,3\n" ".section __ex_table,\"a\"\n" " .align 4\n" " .long 0b,1b\n" ".previous" : "+&d" (n) : "d" (to), "d" (from) : "1", "2", "3", "4", "5" ); return n;}#define __copy_to_user(to, from, n) \({ \ __copy_to_user_asm(to,from,n); \})#define copy_to_user(to, from, n) \({ \ long err = 0; \ __typeof__(n) __n = (n); \ if (__access_ok(to,__n)) { \ err = __copy_to_user_asm(to,from,__n); \ } \ else \ err = __n; \ err; \})extern inline unsigned long__copy_from_user_asm(void* to, const void* from, long n){ __asm__ __volatile__ ( " iac 1\n" " lr 2,%1\n" " lr 4,%2\n" " lr 3,%0\n" " lr 5,3\n" " sacf 512\n" "0: mvcle 2,4,0\n" " jo 0b\n" "1: sacf 0(1)\n" " lr %0,3\n" ".section __ex_table,\"a\"\n" " .align 4\n" " .long 0b,1b\n" ".previous" : "+&d" (n) : "d" (to), "d" (from) : "1", "2", "3", "4", "5" ); return n;}#define __copy_from_user(to, from, n) \({ \ __copy_from_user_asm(to,from,n); \})#define copy_from_user(to, from, n) \({ \ long err = 0; \ __typeof__(n) __n = (n); \ if (__access_ok(from,__n)) { \ err = __copy_from_user_asm(to,from,__n); \ } \ else \ err = __n; \ err; \})/* * Copy a null terminated string from userspace. */static inline longstrncpy_from_user(char *dst, const char *src, long count){ int len; __asm__ __volatile__ ( " iac 1\n" " slr %0,%0\n" " lr 2,%1\n" " lr 4,%2\n" " slr 3,3\n" " sacf 512\n" "0: ic 3,0(%0,4)\n" "1: stc 3,0(%0,2)\n" " ltr 3,3\n" " jz 2f\n" " ahi %0,1\n" " clr %0,%3\n" " jl 0b\n" "2: sacf 0(1)\n" ".section .fixup,\"ax\"\n" "3: lhi %0,%h4\n" " basr 3,0\n" " l 3,4f-.(3)\n" " br 3\n" "4: .long 2b\n" ".previous\n" ".section __ex_table,\"a\"\n" " .align 4\n" " .long 0b,3b\n" " .long 1b,3b\n" ".previous" : "=&a" (len) : "a" (dst), "d" (src), "d" (count), "K" (-EFAULT) : "1", "2", "3", "4", "memory" ); return len;}/* * Return the size of a string (including the ending 0) * * Return 0 for error */static inline unsigned longstrnlen_user(const char * src, unsigned long n){ __asm__ __volatile__ (" iac 1\n" " alr %0,%1\n" " slr 0,0\n" " lr 4,%1\n" " sacf 512\n" "0: srst %0,4\n" " jo 0b\n" " slr %0,%1\n" " ahi %0,1\n" " sacf 0(1)\n" "1:\n" ".section .fixup,\"ax\"\n" "2: sacf 0(1)\n" " slr %0,%0\n" " bras 4,3f\n" " .long 1b\n" "3: l 4,0(4)\n" " br 4\n" ".previous\n" ".section __ex_table,\"a\"\n" " .align 4\n" " .long 0b,2b\n" ".previous" : "+&a" (n) : "d" (src) : "cc", "0", "1", "4" ); return n;}#define strlen_user(str) strnlen_user(str, ~0UL)/* * Zero Userspace */static inline unsigned longclear_user(void *to, unsigned long n){ __asm__ __volatile__ ( " iac 1\n" " sacf 512\n" " lr 4,%1\n" " lr 5,%0\n" " sr 2,2\n" " sr 3,3\n" "0: mvcle 4,2,0\n" " jo 0b\n" "1: sacf 0(1)\n" " lr %0,3\n" ".section __ex_table,\"a\"\n" " .align 4\n" " .long 0b,1b\n" ".previous" : "+&a" (n) : "a" (to) : "cc", "1", "2", "3", "4", "5" ); return n;}#endif /* _S390_UACCESS_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -