File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/uaccess.h.tar
Back
usr/src/linux-headers-5.15.0-133/arch/sh/include/asm/uaccess.h 0000644 00000011313 15030235023 0017265 0 ustar 00 /* SPDX-License-Identifier: GPL-2.0 */ #ifndef __ASM_SH_UACCESS_H #define __ASM_SH_UACCESS_H #include <asm/segment.h> #include <asm/extable.h> #define __addr_ok(addr) \ ((unsigned long __force)(addr) < current_thread_info()->addr_limit.seg) /* * __access_ok: Check if address with size is OK or not. * * Uhhuh, this needs 33-bit arithmetic. We have a carry.. * * sum := addr + size; carry? --> flag = true; * if (sum >= addr_limit) flag = true; */ #define __access_ok(addr, size) ({ \ unsigned long __ao_a = (addr), __ao_b = (size); \ unsigned long __ao_end = __ao_a + __ao_b - !!__ao_b; \ __ao_end >= __ao_a && __addr_ok(__ao_end); }) #define access_ok(addr, size) \ (__chk_user_ptr(addr), \ __access_ok((unsigned long __force)(addr), (size))) #define user_addr_max() (current_thread_info()->addr_limit.seg) /* * Uh, these should become the main single-value transfer routines ... * They automatically use the right size if we just have the right * pointer type ... * * As SuperH uses the same address space for kernel and user data, we * can just do these as direct assignments. * * Careful to not * (a) re-use the arguments for side effects (sizeof is ok) * (b) require any knowledge of processes at this stage */ #define put_user(x,ptr) __put_user_check((x), (ptr), sizeof(*(ptr))) #define get_user(x,ptr) __get_user_check((x), (ptr), sizeof(*(ptr))) /* * The "__xxx" versions do not do address space checking, useful when * doing multiple accesses to the same area (the user has to do the * checks by hand with "access_ok()") */ #define __put_user(x,ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr))) #define __get_user(x,ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr))) struct __large_struct { unsigned long buf[100]; }; #define __m(x) (*(struct __large_struct __user *)(x)) #define __get_user_nocheck(x,ptr,size) \ ({ \ long __gu_err; \ unsigned long __gu_val; \ const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ __chk_user_ptr(ptr); \ __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ (x) = (__force __typeof__(*(ptr)))__gu_val; \ __gu_err; \ }) #define __get_user_check(x,ptr,size) \ ({ \ long __gu_err = -EFAULT; \ unsigned long __gu_val = 0; \ const __typeof__(*(ptr)) *__gu_addr = (ptr); \ if (likely(access_ok(__gu_addr, (size)))) \ __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ (x) = (__force __typeof__(*(ptr)))__gu_val; \ __gu_err; \ }) #define __put_user_nocheck(x,ptr,size) \ ({ \ long __pu_err; \ __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ __typeof__(*(ptr)) __pu_val = x; \ __chk_user_ptr(ptr); \ __put_user_size(__pu_val, __pu_addr, (size), __pu_err); \ __pu_err; \ }) #define __put_user_check(x,ptr,size) \ ({ \ long __pu_err = -EFAULT; \ __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ __typeof__(*(ptr)) __pu_val = x; \ if (likely(access_ok(__pu_addr, size))) \ __put_user_size(__pu_val, __pu_addr, (size), \ __pu_err); \ __pu_err; \ }) # include <asm/uaccess_32.h> extern long strncpy_from_user(char *dest, const char __user *src, long count); extern __must_check long strnlen_user(const char __user *str, long n); /* Generic arbitrary sized copy. */ /* Return the number of bytes NOT copied */ __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n); static __always_inline unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n) { return __copy_user(to, (__force void *)from, n); } static __always_inline unsigned long __must_check raw_copy_to_user(void __user *to, const void *from, unsigned long n) { return __copy_user((__force void *)to, from, n); } #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER /* * Clear the area and return remaining number of bytes * (on failure. Usually it's 0.) */ __kernel_size_t __clear_user(void *addr, __kernel_size_t size); #define clear_user(addr,n) \ ({ \ void __user * __cl_addr = (addr); \ unsigned long __cl_size = (n); \ \ if (__cl_size && access_ok(__cl_addr, __cl_size)) \ __cl_size = __clear_user(__cl_addr, __cl_size); \ \ __cl_size; \ }) extern void *set_exception_table_vec(unsigned int vec, void *handler); static inline void *set_exception_table_evt(unsigned int evt, void *handler) { return set_exception_table_vec(evt >> 5, handler); } struct mem_access { unsigned long (*from)(void *dst, const void __user *src, unsigned long cnt); unsigned long (*to)(void __user *dst, const void *src, unsigned long cnt); }; int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs, struct mem_access *ma, int, unsigned long address); #endif /* __ASM_SH_UACCESS_H */ usr/src/linux-headers-5.15.0-133/arch/arc/include/asm/uaccess.h 0000644 00000041173 15030272422 0017433 0 ustar 00 /* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) * * vineetg: June 2010 * -__clear_user( ) called multiple times during elf load was byte loop * converted to do as much word clear as possible. * * vineetg: Dec 2009 * -Hand crafted constant propagation for "constant" copy sizes * -stock kernel shrunk by 33K at -O3 * * vineetg: Sept 2009 * -Added option to (UN)inline copy_(to|from)_user to reduce code sz * -kernel shrunk by 200K even at -O3 (gcc 4.2.1) * -Enabled when doing -Os * * Amit Bhor, Sameer Dhavale: Codito Technologies 2004 */ #ifndef _ASM_ARC_UACCESS_H #define _ASM_ARC_UACCESS_H #include <linux/string.h> /* for generic string functions */ #define __kernel_ok (uaccess_kernel()) /* * Algorithmically, for __user_ok() we want do: * (start < TASK_SIZE) && (start+len < TASK_SIZE) * where TASK_SIZE could either be retrieved from thread_info->addr_limit or * emitted directly in code. * * This can however be rewritten as follows: * (len <= TASK_SIZE) && (start+len < TASK_SIZE) * * Because it essentially checks if buffer end is within limit and @len is * non-ngeative, which implies that buffer start will be within limit too. * * The reason for rewriting being, for majority of cases, @len is generally * compile time constant, causing first sub-expression to be compile time * subsumed. * * The second part would generate weird large LIMMs e.g. (0x6000_0000 - 0x10), * so we check for TASK_SIZE using get_fs() since the addr_limit load from mem * would already have been done at this call site for __kernel_ok() * */ #define __user_ok(addr, sz) (((sz) <= TASK_SIZE) && \ ((addr) <= (get_fs() - (sz)))) #define __access_ok(addr, sz) (unlikely(__kernel_ok) || \ likely(__user_ok((addr), (sz)))) /*********** Single byte/hword/word copies ******************/ #define __get_user_fn(sz, u, k) \ ({ \ long __ret = 0; /* success by default */ \ switch (sz) { \ case 1: __arc_get_user_one(*(k), u, "ldb", __ret); break; \ case 2: __arc_get_user_one(*(k), u, "ldw", __ret); break; \ case 4: __arc_get_user_one(*(k), u, "ld", __ret); break; \ case 8: __arc_get_user_one_64(*(k), u, __ret); break; \ } \ __ret; \ }) /* * Returns 0 on success, -EFAULT if not. * @ret already contains 0 - given that errors will be less likely * (hence +r asm constraint below). * In case of error, fixup code will make it -EFAULT */ #define __arc_get_user_one(dst, src, op, ret) \ __asm__ __volatile__( \ "1: "op" %1,[%2]\n" \ "2: ;nop\n" \ " .section .fixup, \"ax\"\n" \ " .align 4\n" \ "3: # return -EFAULT\n" \ " mov %0, %3\n" \ " # zero out dst ptr\n" \ " mov %1, 0\n" \ " j 2b\n" \ " .previous\n" \ " .section __ex_table, \"a\"\n" \ " .align 4\n" \ " .word 1b,3b\n" \ " .previous\n" \ \ : "+r" (ret), "=r" (dst) \ : "r" (src), "ir" (-EFAULT)) #define __arc_get_user_one_64(dst, src, ret) \ __asm__ __volatile__( \ "1: ld %1,[%2]\n" \ "4: ld %R1,[%2, 4]\n" \ "2: ;nop\n" \ " .section .fixup, \"ax\"\n" \ " .align 4\n" \ "3: # return -EFAULT\n" \ " mov %0, %3\n" \ " # zero out dst ptr\n" \ " mov %1, 0\n" \ " mov %R1, 0\n" \ " j 2b\n" \ " .previous\n" \ " .section __ex_table, \"a\"\n" \ " .align 4\n" \ " .word 1b,3b\n" \ " .word 4b,3b\n" \ " .previous\n" \ \ : "+r" (ret), "=r" (dst) \ : "r" (src), "ir" (-EFAULT)) #define __put_user_fn(sz, u, k) \ ({ \ long __ret = 0; /* success by default */ \ switch (sz) { \ case 1: __arc_put_user_one(*(k), u, "stb", __ret); break; \ case 2: __arc_put_user_one(*(k), u, "stw", __ret); break; \ case 4: __arc_put_user_one(*(k), u, "st", __ret); break; \ case 8: __arc_put_user_one_64(*(k), u, __ret); break; \ } \ __ret; \ }) #define __arc_put_user_one(src, dst, op, ret) \ __asm__ __volatile__( \ "1: "op" %1,[%2]\n" \ "2: ;nop\n" \ " .section .fixup, \"ax\"\n" \ " .align 4\n" \ "3: mov %0, %3\n" \ " j 2b\n" \ " .previous\n" \ " .section __ex_table, \"a\"\n" \ " .align 4\n" \ " .word 1b,3b\n" \ " .previous\n" \ \ : "+r" (ret) \ : "r" (src), "r" (dst), "ir" (-EFAULT)) #define __arc_put_user_one_64(src, dst, ret) \ __asm__ __volatile__( \ "1: st %1,[%2]\n" \ "4: st %R1,[%2, 4]\n" \ "2: ;nop\n" \ " .section .fixup, \"ax\"\n" \ " .align 4\n" \ "3: mov %0, %3\n" \ " j 2b\n" \ " .previous\n" \ " .section __ex_table, \"a\"\n" \ " .align 4\n" \ " .word 1b,3b\n" \ " .word 4b,3b\n" \ " .previous\n" \ \ : "+r" (ret) \ : "r" (src), "r" (dst), "ir" (-EFAULT)) static inline unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n) { long res = 0; char val; unsigned long tmp1, tmp2, tmp3, tmp4; unsigned long orig_n = n; if (n == 0) return 0; /* unaligned */ if (((unsigned long)to & 0x3) || ((unsigned long)from & 0x3)) { unsigned char tmp; __asm__ __volatile__ ( " mov.f lp_count, %0 \n" " lpnz 2f \n" "1: ldb.ab %1, [%3, 1] \n" " stb.ab %1, [%2, 1] \n" " sub %0,%0,1 \n" "2: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "3: j 2b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 1b, 3b \n" " .previous \n" : "+r" (n), /* * Note as an '&' earlyclobber operand to make sure the * temporary register inside the loop is not the same as * FROM or TO. */ "=&r" (tmp), "+r" (to), "+r" (from) : : "lp_count", "memory"); return n; } /* * Hand-crafted constant propagation to reduce code sz of the * laddered copy 16x,8,4,2,1 */ if (__builtin_constant_p(orig_n)) { res = orig_n; if (orig_n / 16) { orig_n = orig_n % 16; __asm__ __volatile__( " lsr lp_count, %7,4 \n" " lp 3f \n" "1: ld.ab %3, [%2, 4] \n" "11: ld.ab %4, [%2, 4] \n" "12: ld.ab %5, [%2, 4] \n" "13: ld.ab %6, [%2, 4] \n" " st.ab %3, [%1, 4] \n" " st.ab %4, [%1, 4] \n" " st.ab %5, [%1, 4] \n" " st.ab %6, [%1, 4] \n" " sub %0,%0,16 \n" "3: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 3b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 1b, 4b \n" " .word 11b,4b \n" " .word 12b,4b \n" " .word 13b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1), "=r"(tmp2), "=r"(tmp3), "=r"(tmp4) : "ir"(n) : "lp_count", "memory"); } if (orig_n / 8) { orig_n = orig_n % 8; __asm__ __volatile__( "14: ld.ab %3, [%2,4] \n" "15: ld.ab %4, [%2,4] \n" " st.ab %3, [%1,4] \n" " st.ab %4, [%1,4] \n" " sub %0,%0,8 \n" "31: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 31b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 14b,4b \n" " .word 15b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1), "=r"(tmp2) : : "memory"); } if (orig_n / 4) { orig_n = orig_n % 4; __asm__ __volatile__( "16: ld.ab %3, [%2,4] \n" " st.ab %3, [%1,4] \n" " sub %0,%0,4 \n" "32: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 32b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 16b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1) : : "memory"); } if (orig_n / 2) { orig_n = orig_n % 2; __asm__ __volatile__( "17: ldw.ab %3, [%2,2] \n" " stw.ab %3, [%1,2] \n" " sub %0,%0,2 \n" "33: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 33b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 17b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1) : : "memory"); } if (orig_n & 1) { __asm__ __volatile__( "18: ldb.ab %3, [%2,2] \n" " stb.ab %3, [%1,2] \n" " sub %0,%0,1 \n" "34: ; nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 34b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 18b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1) : : "memory"); } } else { /* n is NOT constant, so laddered copy of 16x,8,4,2,1 */ __asm__ __volatile__( " mov %0,%3 \n" " lsr.f lp_count, %3,4 \n" /* 16x bytes */ " lpnz 3f \n" "1: ld.ab %5, [%2, 4] \n" "11: ld.ab %6, [%2, 4] \n" "12: ld.ab %7, [%2, 4] \n" "13: ld.ab %8, [%2, 4] \n" " st.ab %5, [%1, 4] \n" " st.ab %6, [%1, 4] \n" " st.ab %7, [%1, 4] \n" " st.ab %8, [%1, 4] \n" " sub %0,%0,16 \n" "3: and.f %3,%3,0xf \n" /* stragglers */ " bz 34f \n" " bbit0 %3,3,31f \n" /* 8 bytes left */ "14: ld.ab %5, [%2,4] \n" "15: ld.ab %6, [%2,4] \n" " st.ab %5, [%1,4] \n" " st.ab %6, [%1,4] \n" " sub.f %0,%0,8 \n" "31: bbit0 %3,2,32f \n" /* 4 bytes left */ "16: ld.ab %5, [%2,4] \n" " st.ab %5, [%1,4] \n" " sub.f %0,%0,4 \n" "32: bbit0 %3,1,33f \n" /* 2 bytes left */ "17: ldw.ab %5, [%2,2] \n" " stw.ab %5, [%1,2] \n" " sub.f %0,%0,2 \n" "33: bbit0 %3,0,34f \n" "18: ldb.ab %5, [%2,1] \n" /* 1 byte left */ " stb.ab %5, [%1,1] \n" " sub.f %0,%0,1 \n" "34: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 34b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 1b, 4b \n" " .word 11b,4b \n" " .word 12b,4b \n" " .word 13b,4b \n" " .word 14b,4b \n" " .word 15b,4b \n" " .word 16b,4b \n" " .word 17b,4b \n" " .word 18b,4b \n" " .previous \n" : "=r" (res), "+r"(to), "+r"(from), "+r"(n), "=r"(val), "=r"(tmp1), "=r"(tmp2), "=r"(tmp3), "=r"(tmp4) : : "lp_count", "memory"); } return res; } static inline unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n) { long res = 0; char val; unsigned long tmp1, tmp2, tmp3, tmp4; unsigned long orig_n = n; if (n == 0) return 0; /* unaligned */ if (((unsigned long)to & 0x3) || ((unsigned long)from & 0x3)) { unsigned char tmp; __asm__ __volatile__( " mov.f lp_count, %0 \n" " lpnz 3f \n" " ldb.ab %1, [%3, 1] \n" "1: stb.ab %1, [%2, 1] \n" " sub %0, %0, 1 \n" "3: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 3b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 1b, 4b \n" " .previous \n" : "+r" (n), /* Note as an '&' earlyclobber operand to make sure the * temporary register inside the loop is not the same as * FROM or TO. */ "=&r" (tmp), "+r" (to), "+r" (from) : : "lp_count", "memory"); return n; } if (__builtin_constant_p(orig_n)) { res = orig_n; if (orig_n / 16) { orig_n = orig_n % 16; __asm__ __volatile__( " lsr lp_count, %7,4 \n" " lp 3f \n" " ld.ab %3, [%2, 4] \n" " ld.ab %4, [%2, 4] \n" " ld.ab %5, [%2, 4] \n" " ld.ab %6, [%2, 4] \n" "1: st.ab %3, [%1, 4] \n" "11: st.ab %4, [%1, 4] \n" "12: st.ab %5, [%1, 4] \n" "13: st.ab %6, [%1, 4] \n" " sub %0, %0, 16 \n" "3:;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 3b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 1b, 4b \n" " .word 11b,4b \n" " .word 12b,4b \n" " .word 13b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1), "=r"(tmp2), "=r"(tmp3), "=r"(tmp4) : "ir"(n) : "lp_count", "memory"); } if (orig_n / 8) { orig_n = orig_n % 8; __asm__ __volatile__( " ld.ab %3, [%2,4] \n" " ld.ab %4, [%2,4] \n" "14: st.ab %3, [%1,4] \n" "15: st.ab %4, [%1,4] \n" " sub %0, %0, 8 \n" "31:;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 31b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 14b,4b \n" " .word 15b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1), "=r"(tmp2) : : "memory"); } if (orig_n / 4) { orig_n = orig_n % 4; __asm__ __volatile__( " ld.ab %3, [%2,4] \n" "16: st.ab %3, [%1,4] \n" " sub %0, %0, 4 \n" "32:;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 32b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 16b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1) : : "memory"); } if (orig_n / 2) { orig_n = orig_n % 2; __asm__ __volatile__( " ldw.ab %3, [%2,2] \n" "17: stw.ab %3, [%1,2] \n" " sub %0, %0, 2 \n" "33:;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 33b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 17b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1) : : "memory"); } if (orig_n & 1) { __asm__ __volatile__( " ldb.ab %3, [%2,1] \n" "18: stb.ab %3, [%1,1] \n" " sub %0, %0, 1 \n" "34: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 34b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 18b,4b \n" " .previous \n" : "+r" (res), "+r"(to), "+r"(from), "=r"(tmp1) : : "memory"); } } else { /* n is NOT constant, so laddered copy of 16x,8,4,2,1 */ __asm__ __volatile__( " mov %0,%3 \n" " lsr.f lp_count, %3,4 \n" /* 16x bytes */ " lpnz 3f \n" " ld.ab %5, [%2, 4] \n" " ld.ab %6, [%2, 4] \n" " ld.ab %7, [%2, 4] \n" " ld.ab %8, [%2, 4] \n" "1: st.ab %5, [%1, 4] \n" "11: st.ab %6, [%1, 4] \n" "12: st.ab %7, [%1, 4] \n" "13: st.ab %8, [%1, 4] \n" " sub %0, %0, 16 \n" "3: and.f %3,%3,0xf \n" /* stragglers */ " bz 34f \n" " bbit0 %3,3,31f \n" /* 8 bytes left */ " ld.ab %5, [%2,4] \n" " ld.ab %6, [%2,4] \n" "14: st.ab %5, [%1,4] \n" "15: st.ab %6, [%1,4] \n" " sub.f %0, %0, 8 \n" "31: bbit0 %3,2,32f \n" /* 4 bytes left */ " ld.ab %5, [%2,4] \n" "16: st.ab %5, [%1,4] \n" " sub.f %0, %0, 4 \n" "32: bbit0 %3,1,33f \n" /* 2 bytes left */ " ldw.ab %5, [%2,2] \n" "17: stw.ab %5, [%1,2] \n" " sub.f %0, %0, 2 \n" "33: bbit0 %3,0,34f \n" " ldb.ab %5, [%2,1] \n" /* 1 byte left */ "18: stb.ab %5, [%1,1] \n" " sub.f %0, %0, 1 \n" "34: ;nop \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "4: j 34b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 1b, 4b \n" " .word 11b,4b \n" " .word 12b,4b \n" " .word 13b,4b \n" " .word 14b,4b \n" " .word 15b,4b \n" " .word 16b,4b \n" " .word 17b,4b \n" " .word 18b,4b \n" " .previous \n" : "=r" (res), "+r"(to), "+r"(from), "+r"(n), "=r"(val), "=r"(tmp1), "=r"(tmp2), "=r"(tmp3), "=r"(tmp4) : : "lp_count", "memory"); } return res; } static inline unsigned long __arc_clear_user(void __user *to, unsigned long n) { long res = n; unsigned char *d_char = to; __asm__ __volatile__( " bbit0 %0, 0, 1f \n" "75: stb.ab %2, [%0,1] \n" " sub %1, %1, 1 \n" "1: bbit0 %0, 1, 2f \n" "76: stw.ab %2, [%0,2] \n" " sub %1, %1, 2 \n" "2: asr.f lp_count, %1, 2 \n" " lpnz 3f \n" "77: st.ab %2, [%0,4] \n" " sub %1, %1, 4 \n" "3: bbit0 %1, 1, 4f \n" "78: stw.ab %2, [%0,2] \n" " sub %1, %1, 2 \n" "4: bbit0 %1, 0, 5f \n" "79: stb.ab %2, [%0,1] \n" " sub %1, %1, 1 \n" "5: \n" " .section .fixup, \"ax\" \n" " .align 4 \n" "3: j 5b \n" " .previous \n" " .section __ex_table, \"a\" \n" " .align 4 \n" " .word 75b, 3b \n" " .word 76b, 3b \n" " .word 77b, 3b \n" " .word 78b, 3b \n" " .word 79b, 3b \n" " .previous \n" : "+r"(d_char), "+r"(res) : "i"(0) : "lp_count", "memory"); return res; } #ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE #define INLINE_COPY_TO_USER #define INLINE_COPY_FROM_USER #define __clear_user(d, n) __arc_clear_user(d, n) #else extern unsigned long arc_clear_user_noinline(void __user *to, unsigned long n); #define __clear_user(d, n) arc_clear_user_noinline(d, n) #endif #include <asm/segment.h> #include <asm-generic/uaccess.h> #endif usr/src/linux-headers-5.15.0-133/arch/parisc/include/asm/uaccess.h 0000644 00000014155 15030273506 0020153 0 ustar 00 /* SPDX-License-Identifier: GPL-2.0 */ #ifndef __PARISC_UACCESS_H #define __PARISC_UACCESS_H /* * User space memory access functions */ #include <asm/page.h> #include <asm/cache.h> #include <linux/bug.h> #include <linux/string.h> /* * Note that since kernel addresses are in a separate address space on * parisc, we don't need to do anything for access_ok(). * We just let the page fault handler do the right thing. This also means * that put_user is the same as __put_user, etc. */ #define access_ok(uaddr, size) \ ( (uaddr) == (uaddr) ) #define put_user __put_user #define get_user __get_user #if !defined(CONFIG_64BIT) #define LDD_USER(sr, val, ptr) __get_user_asm64(sr, val, ptr) #define STD_USER(sr, x, ptr) __put_user_asm64(sr, x, ptr) #else #define LDD_USER(sr, val, ptr) __get_user_asm(sr, val, "ldd", ptr) #define STD_USER(sr, x, ptr) __put_user_asm(sr, "std", x, ptr) #endif /* * The exception table contains two values: the first is the relative offset to * the address of the instruction that is allowed to fault, and the second is * the relative offset to the address of the fixup routine. Since relative * addresses are used, 32bit values are sufficient even on 64bit kernel. */ #define ARCH_HAS_RELATIVE_EXTABLE struct exception_table_entry { int insn; /* relative address of insn that is allowed to fault. */ int fixup; /* relative address of fixup routine */ }; #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\ ".section __ex_table,\"aw\"\n" \ ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \ ".previous\n" /* * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry * (with lowest bit set) for which the fault handler in fixup_exception() will * load -EFAULT into %r8 for a read or write fault, and zeroes the target * register in case of a read fault in get_user(). */ #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\ ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1) #define __get_user_internal(sr, val, ptr) \ ({ \ register long __gu_err __asm__ ("r8") = 0; \ \ switch (sizeof(*(ptr))) { \ case 1: __get_user_asm(sr, val, "ldb", ptr); break; \ case 2: __get_user_asm(sr, val, "ldh", ptr); break; \ case 4: __get_user_asm(sr, val, "ldw", ptr); break; \ case 8: LDD_USER(sr, val, ptr); break; \ default: BUILD_BUG(); \ } \ \ __gu_err; \ }) #define __get_user(val, ptr) \ ({ \ __get_user_internal("%%sr3,", val, ptr); \ }) #define __get_user_asm(sr, val, ldx, ptr) \ { \ register long __gu_val; \ \ __asm__("1: " ldx " 0(" sr "%2),%0\n" \ "9:\n" \ ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ : "=r"(__gu_val), "=r"(__gu_err) \ : "r"(ptr), "1"(__gu_err)); \ \ (val) = (__force __typeof__(*(ptr))) __gu_val; \ } #define HAVE_GET_KERNEL_NOFAULT #define __get_kernel_nofault(dst, src, type, err_label) \ { \ type __z; \ long __err; \ __err = __get_user_internal("%%sr0,", __z, (type *)(src)); \ if (unlikely(__err)) \ goto err_label; \ else \ *(type *)(dst) = __z; \ } #if !defined(CONFIG_64BIT) #define __get_user_asm64(sr, val, ptr) \ { \ union { \ unsigned long long l; \ __typeof__(*(ptr)) t; \ } __gu_tmp; \ \ __asm__(" copy %%r0,%R0\n" \ "1: ldw 0(" sr "%2),%0\n" \ "2: ldw 4(" sr "%2),%R0\n" \ "9:\n" \ ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ : "=&r"(__gu_tmp.l), "=r"(__gu_err) \ : "r"(ptr), "1"(__gu_err)); \ \ (val) = __gu_tmp.t; \ } #endif /* !defined(CONFIG_64BIT) */ #define __put_user_internal(sr, x, ptr) \ ({ \ register long __pu_err __asm__ ("r8") = 0; \ __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \ \ switch (sizeof(*(ptr))) { \ case 1: __put_user_asm(sr, "stb", __x, ptr); break; \ case 2: __put_user_asm(sr, "sth", __x, ptr); break; \ case 4: __put_user_asm(sr, "stw", __x, ptr); break; \ case 8: STD_USER(sr, __x, ptr); break; \ default: BUILD_BUG(); \ } \ \ __pu_err; \ }) #define __put_user(x, ptr) \ ({ \ __put_user_internal("%%sr3,", x, ptr); \ }) #define __put_kernel_nofault(dst, src, type, err_label) \ { \ type __z = *(type *)(src); \ long __err; \ __err = __put_user_internal("%%sr0,", __z, (type *)(dst)); \ if (unlikely(__err)) \ goto err_label; \ } /* * The "__put_user/kernel_asm()" macros tell gcc they read from memory * instead of writing. This is because they do not write to any memory * gcc knows about, so there are no aliasing issues. These macros must * also be aware that fixups are executed in the context of the fault, * and any registers used there must be listed as clobbers. * r8 is already listed as err. */ #define __put_user_asm(sr, stx, x, ptr) \ __asm__ __volatile__ ( \ "1: " stx " %2,0(" sr "%1)\n" \ "9:\n" \ ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ : "=r"(__pu_err) \ : "r"(ptr), "r"(x), "0"(__pu_err)) #if !defined(CONFIG_64BIT) #define __put_user_asm64(sr, __val, ptr) do { \ __asm__ __volatile__ ( \ "1: stw %2,0(" sr "%1)\n" \ "2: stw %R2,4(" sr "%1)\n" \ "9:\n" \ ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ : "=r"(__pu_err) \ : "r"(ptr), "r"(__val), "0"(__pu_err)); \ } while (0) #endif /* !defined(CONFIG_64BIT) */ /* * Complex access routines -- external declarations */ extern long strncpy_from_user(char *, const char __user *, long); extern __must_check unsigned lclear_user(void __user *, unsigned long); extern __must_check long strnlen_user(const char __user *src, long n); /* * Complex access routines -- macros */ #define clear_user lclear_user #define __clear_user lclear_user unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src, unsigned long len); unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src, unsigned long len); #define INLINE_COPY_TO_USER #define INLINE_COPY_FROM_USER struct pt_regs; int fixup_exception(struct pt_regs *regs); #endif /* __PARISC_UACCESS_H */ usr/src/linux-headers-5.15.0-133/arch/mips/include/asm/uaccess.h 0000644 00000040102 15030275723 0017634 0 ustar 00 /* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03, 04 by Ralf Baechle * Copyright (C) 1999, 2000 Silicon Graphics, Inc. * Copyright (C) 2007 Maciej W. Rozycki * Copyright (C) 2014, Imagination Technologies Ltd. */ #ifndef _ASM_UACCESS_H #define _ASM_UACCESS_H #include <linux/kernel.h> #include <linux/string.h> #include <asm/asm-eva.h> #include <asm/extable.h> #ifdef CONFIG_32BIT #define __UA_LIMIT 0x80000000UL #define __UA_ADDR ".word" #define __UA_LA "la" #define __UA_ADDU "addu" #define __UA_t0 "$8" #define __UA_t1 "$9" #endif /* CONFIG_32BIT */ #ifdef CONFIG_64BIT extern u64 __ua_limit; #define __UA_LIMIT __ua_limit #define __UA_ADDR ".dword" #define __UA_LA "dla" #define __UA_ADDU "daddu" #define __UA_t0 "$12" #define __UA_t1 "$13" #endif /* CONFIG_64BIT */ /* * Is a address valid? This does a straightforward calculation rather * than tests. * * Address valid if: * - "addr" doesn't have any high-bits set * - AND "size" doesn't have any high-bits set * - AND "addr+size" doesn't have any high-bits set * - OR we are in kernel mode. * * __ua_size() is a trick to avoid runtime checking of positive constant * sizes; for those we already know at compile time that the size is ok. */ #define __ua_size(size) \ ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size)) /* * access_ok: - Checks if a user space pointer is valid * @addr: User space pointer to start of block to check * @size: Size of block to check * * Context: User context only. This function may sleep if pagefaults are * enabled. * * Checks if a pointer to a block of memory in user space is valid. * * Returns true (nonzero) if the memory block may be valid, false (zero) * if it is definitely invalid. * * Note that, depending on architecture, this function probably just * checks that the pointer is in the user space range - after calling * this function, memory access functions may still return -EFAULT. */ static inline int __access_ok(const void __user *p, unsigned long size) { unsigned long addr = (unsigned long)p; unsigned long end = addr + size - !!size; return (__UA_LIMIT & (addr | end | __ua_size(size))) == 0; } #define access_ok(addr, size) \ likely(__access_ok((addr), (size))) /* * put_user: - Write a simple value into user space. * @x: Value to copy to user space. * @ptr: Destination address, in user space. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * This macro copies a single simple value from kernel space to user * space. It supports simple types like char and int, but not larger * data types like structures or arrays. * * @ptr must have pointer-to-simple-variable type, and @x must be assignable * to the result of dereferencing @ptr. * * Returns zero on success, or -EFAULT on error. */ #define put_user(x, ptr) \ ({ \ __typeof__(*(ptr)) __user *__p = (ptr); \ \ might_fault(); \ access_ok(__p, sizeof(*__p)) ? __put_user((x), __p) : -EFAULT; \ }) /* * get_user: - Get a simple variable from user space. * @x: Variable to store result. * @ptr: Source address, in user space. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * This macro copies a single simple variable from user space to kernel * space. It supports simple types like char and int, but not larger * data types like structures or arrays. * * @ptr must have pointer-to-simple-variable type, and the result of * dereferencing @ptr must be assignable to @x without a cast. * * Returns zero on success, or -EFAULT on error. * On error, the variable @x is set to zero. */ #define get_user(x, ptr) \ ({ \ const __typeof__(*(ptr)) __user *__p = (ptr); \ \ might_fault(); \ access_ok(__p, sizeof(*__p)) ? __get_user((x), __p) : \ ((x) = 0, -EFAULT); \ }) /* * __put_user: - Write a simple value into user space, with less checking. * @x: Value to copy to user space. * @ptr: Destination address, in user space. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * This macro copies a single simple value from kernel space to user * space. It supports simple types like char and int, but not larger * data types like structures or arrays. * * @ptr must have pointer-to-simple-variable type, and @x must be assignable * to the result of dereferencing @ptr. * * Caller must check the pointer with access_ok() before calling this * function. * * Returns zero on success, or -EFAULT on error. */ #define __put_user(x, ptr) \ ({ \ __typeof__(*(ptr)) __user *__pu_ptr = (ptr); \ __typeof__(*(ptr)) __pu_val = (x); \ int __pu_err = 0; \ \ __chk_user_ptr(__pu_ptr); \ switch (sizeof(*__pu_ptr)) { \ case 1: \ __put_data_asm(user_sb, __pu_ptr); \ break; \ case 2: \ __put_data_asm(user_sh, __pu_ptr); \ break; \ case 4: \ __put_data_asm(user_sw, __pu_ptr); \ break; \ case 8: \ __PUT_DW(user_sd, __pu_ptr); \ break; \ default: \ BUILD_BUG(); \ } \ \ __pu_err; \ }) /* * __get_user: - Get a simple variable from user space, with less checking. * @x: Variable to store result. * @ptr: Source address, in user space. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * This macro copies a single simple variable from user space to kernel * space. It supports simple types like char and int, but not larger * data types like structures or arrays. * * @ptr must have pointer-to-simple-variable type, and the result of * dereferencing @ptr must be assignable to @x without a cast. * * Caller must check the pointer with access_ok() before calling this * function. * * Returns zero on success, or -EFAULT on error. * On error, the variable @x is set to zero. */ #define __get_user(x, ptr) \ ({ \ const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ int __gu_err = 0; \ \ __chk_user_ptr(__gu_ptr); \ switch (sizeof(*__gu_ptr)) { \ case 1: \ __get_data_asm((x), user_lb, __gu_ptr); \ break; \ case 2: \ __get_data_asm((x), user_lh, __gu_ptr); \ break; \ case 4: \ __get_data_asm((x), user_lw, __gu_ptr); \ break; \ case 8: \ __GET_DW((x), user_ld, __gu_ptr); \ break; \ default: \ BUILD_BUG(); \ } \ \ __gu_err; \ }) struct __large_struct { unsigned long buf[100]; }; #define __m(x) (*(struct __large_struct __user *)(x)) #ifdef CONFIG_32BIT #define __GET_DW(val, insn, ptr) __get_data_asm_ll32(val, insn, ptr) #endif #ifdef CONFIG_64BIT #define __GET_DW(val, insn, ptr) __get_data_asm(val, insn, ptr) #endif #define __get_data_asm(val, insn, addr) \ { \ long __gu_tmp; \ \ __asm__ __volatile__( \ "1: "insn("%1", "%3")" \n" \ "2: \n" \ " .insn \n" \ " .section .fixup,\"ax\" \n" \ "3: li %0, %4 \n" \ " move %1, $0 \n" \ " j 2b \n" \ " .previous \n" \ " .section __ex_table,\"a\" \n" \ " "__UA_ADDR "\t1b, 3b \n" \ " .previous \n" \ : "=r" (__gu_err), "=r" (__gu_tmp) \ : "0" (0), "o" (__m(addr)), "i" (-EFAULT)); \ \ (val) = (__typeof__(*(addr))) __gu_tmp; \ } /* * Get a long long 64 using 32 bit registers. */ #define __get_data_asm_ll32(val, insn, addr) \ { \ union { \ unsigned long long l; \ __typeof__(*(addr)) t; \ } __gu_tmp; \ \ __asm__ __volatile__( \ "1: " insn("%1", "(%3)")" \n" \ "2: " insn("%D1", "4(%3)")" \n" \ "3: \n" \ " .insn \n" \ " .section .fixup,\"ax\" \n" \ "4: li %0, %4 \n" \ " move %1, $0 \n" \ " move %D1, $0 \n" \ " j 3b \n" \ " .previous \n" \ " .section __ex_table,\"a\" \n" \ " " __UA_ADDR " 1b, 4b \n" \ " " __UA_ADDR " 2b, 4b \n" \ " .previous \n" \ : "=r" (__gu_err), "=&r" (__gu_tmp.l) \ : "0" (0), "r" (addr), "i" (-EFAULT)); \ \ (val) = __gu_tmp.t; \ } #define HAVE_GET_KERNEL_NOFAULT #define __get_kernel_nofault(dst, src, type, err_label) \ do { \ int __gu_err; \ \ switch (sizeof(type)) { \ case 1: \ __get_data_asm(*(type *)(dst), kernel_lb, \ (__force type *)(src)); \ break; \ case 2: \ __get_data_asm(*(type *)(dst), kernel_lh, \ (__force type *)(src)); \ break; \ case 4: \ __get_data_asm(*(type *)(dst), kernel_lw, \ (__force type *)(src)); \ break; \ case 8: \ __GET_DW(*(type *)(dst), kernel_ld, \ (__force type *)(src)); \ break; \ default: \ BUILD_BUG(); \ break; \ } \ if (unlikely(__gu_err)) \ goto err_label; \ } while (0) /* * Yuck. We need two variants, one for 64bit operation and one * for 32 bit mode and old iron. */ #ifdef CONFIG_32BIT #define __PUT_DW(insn, ptr) __put_data_asm_ll32(insn, ptr) #endif #ifdef CONFIG_64BIT #define __PUT_DW(insn, ptr) __put_data_asm(insn, ptr) #endif #define __put_data_asm(insn, ptr) \ { \ __asm__ __volatile__( \ "1: "insn("%z2", "%3")" # __put_data_asm \n" \ "2: \n" \ " .insn \n" \ " .section .fixup,\"ax\" \n" \ "3: li %0, %4 \n" \ " j 2b \n" \ " .previous \n" \ " .section __ex_table,\"a\" \n" \ " " __UA_ADDR " 1b, 3b \n" \ " .previous \n" \ : "=r" (__pu_err) \ : "0" (0), "Jr" (__pu_val), "o" (__m(ptr)), \ "i" (-EFAULT)); \ } #define __put_data_asm_ll32(insn, ptr) \ { \ __asm__ __volatile__( \ "1: "insn("%2", "(%3)")" # __put_data_asm_ll32 \n" \ "2: "insn("%D2", "4(%3)")" \n" \ "3: \n" \ " .insn \n" \ " .section .fixup,\"ax\" \n" \ "4: li %0, %4 \n" \ " j 3b \n" \ " .previous \n" \ " .section __ex_table,\"a\" \n" \ " " __UA_ADDR " 1b, 4b \n" \ " " __UA_ADDR " 2b, 4b \n" \ " .previous" \ : "=r" (__pu_err) \ : "0" (0), "r" (__pu_val), "r" (ptr), \ "i" (-EFAULT)); \ } #define __put_kernel_nofault(dst, src, type, err_label) \ do { \ type __pu_val; \ int __pu_err = 0; \ \ __pu_val = *(__force type *)(src); \ switch (sizeof(type)) { \ case 1: \ __put_data_asm(kernel_sb, (type *)(dst)); \ break; \ case 2: \ __put_data_asm(kernel_sh, (type *)(dst)); \ break; \ case 4: \ __put_data_asm(kernel_sw, (type *)(dst)) \ break; \ case 8: \ __PUT_DW(kernel_sd, (type *)(dst)); \ break; \ default: \ BUILD_BUG(); \ break; \ } \ if (unlikely(__pu_err)) \ goto err_label; \ } while (0) /* * We're generating jump to subroutines which will be outside the range of * jump instructions */ #ifdef MODULE #define __MODULE_JAL(destination) \ ".set\tnoat\n\t" \ __UA_LA "\t$1, " #destination "\n\t" \ "jalr\t$1\n\t" \ ".set\tat\n\t" #else #define __MODULE_JAL(destination) \ "jal\t" #destination "\n\t" #endif #if defined(CONFIG_CPU_DADDI_WORKAROUNDS) || (defined(CONFIG_EVA) && \ defined(CONFIG_CPU_HAS_PREFETCH)) #define DADDI_SCRATCH "$3" #else #define DADDI_SCRATCH "$0" #endif extern size_t __raw_copy_from_user(void *__to, const void *__from, size_t __n); extern size_t __raw_copy_to_user(void *__to, const void *__from, size_t __n); static inline unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long 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(__raw_copy_from_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"); return __cu_len_r; } static inline unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n) { register void __user *__cu_to_r __asm__("$4"); register const void *__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__( __MODULE_JAL(__raw_copy_to_user) : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) : : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", DADDI_SCRATCH, "memory"); return __cu_len_r; } #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER extern __kernel_size_t __bzero(void __user *addr, __kernel_size_t size); /* * __clear_user: - Zero a block of memory in user space, with less checking. * @to: Destination address, in user space. * @n: Number of bytes to zero. * * Zero a block of memory in user space. Caller must check * the specified block with access_ok() before calling this function. * * Returns number of bytes that could not be cleared. * On success, this will be zero. */ static inline __kernel_size_t __clear_user(void __user *addr, __kernel_size_t size) { __kernel_size_t res; #ifdef CONFIG_CPU_MICROMIPS /* micromips memset / bzero also clobbers t7 & t8 */ #define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$15", "$24", "$31" #else #define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$31" #endif /* CONFIG_CPU_MICROMIPS */ might_fault(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, $0\n\t" "move\t$6, %2\n\t" __MODULE_JAL(__bzero) "move\t%0, $6" : "=r" (res) : "r" (addr), "r" (size) : bzero_clobbers); return res; } #define clear_user(addr,n) \ ({ \ void __user * __cl_addr = (addr); \ unsigned long __cl_size = (n); \ if (__cl_size && access_ok(__cl_addr, __cl_size)) \ __cl_size = __clear_user(__cl_addr, __cl_size); \ __cl_size; \ }) extern long __strncpy_from_user_asm(char *__to, const char __user *__from, long __len); /* * strncpy_from_user: - Copy a NUL terminated string from userspace. * @dst: Destination address, in kernel space. This buffer must be at * least @count bytes long. * @src: Source address, in user space. * @count: Maximum number of bytes to copy, including the trailing NUL. * * Copies a NUL-terminated string from userspace to kernel space. * * On success, returns the length of the string (not including the trailing * NUL). * * If access to userspace fails, returns -EFAULT (some data may have been * copied). * * If @count is smaller than the length of the string, copies @count bytes * and returns @count. */ static inline long strncpy_from_user(char *__to, const char __user *__from, long __len) { long res; if (!access_ok(__from, __len)) return -EFAULT; might_fault(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, %2\n\t" "move\t$6, %3\n\t" __MODULE_JAL(__strncpy_from_user_asm) "move\t%0, $2" : "=r" (res) : "r" (__to), "r" (__from), "r" (__len) : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory"); return res; } extern long __strnlen_user_asm(const char __user *s, long n); /* * strnlen_user: - Get the size of a string in user space. * @str: The string to measure. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * Get the size of a NUL-terminated string in user space. * * Returns the size of the string INCLUDING the terminating NUL. * On exception, returns 0. * If the string is too long, returns a value greater than @n. */ static inline long strnlen_user(const char __user *s, long n) { long res; if (!access_ok(s, 1)) return 0; might_fault(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, %2\n\t" __MODULE_JAL(__strnlen_user_asm) "move\t%0, $2" : "=r" (res) : "r" (s), "r" (n) : "$2", "$4", "$5", __UA_t0, "$31"); return res; } #endif /* _ASM_UACCESS_H */ usr/src/linux-headers-5.15.0-133/arch/microblaze/include/asm/uaccess.h 0000644 00000017671 15030327435 0021030 0 ustar 00 /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> * Copyright (C) 2008-2009 PetaLogix * Copyright (C) 2006 Atmark Techno, Inc. */ #ifndef _ASM_MICROBLAZE_UACCESS_H #define _ASM_MICROBLAZE_UACCESS_H #include <linux/kernel.h> #include <asm/mmu.h> #include <asm/page.h> #include <linux/pgtable.h> #include <asm/extable.h> #include <linux/string.h> /* * On Microblaze the fs value is actually the top of the corresponding * address space. * * The fs value determines whether argument validity checking should be * performed or not. If get_fs() == USER_DS, checking is performed, with * get_fs() == KERNEL_DS, checking is bypassed. * * For historical reasons, these macros are grossly misnamed. * * For non-MMU arch like Microblaze, KERNEL_DS and USER_DS is equal. */ # define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) # define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) # define USER_DS MAKE_MM_SEG(TASK_SIZE - 1) # define get_fs() (current_thread_info()->addr_limit) # define set_fs(val) (current_thread_info()->addr_limit = (val)) # define user_addr_max() get_fs().seg # define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg) static inline int __access_ok(unsigned long addr, unsigned long size) { unsigned long limit = user_addr_max(); return (size <= limit) && (addr <= (limit - size)); } #define access_ok(addr, size) __access_ok((unsigned long)addr, size) # define __FIXUP_SECTION ".section .fixup,\"ax\"\n" # define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n" extern unsigned long __copy_tofrom_user(void __user *to, const void __user *from, unsigned long size); /* Return: number of not copied bytes, i.e. 0 if OK or non-zero if fail. */ static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n) { /* normal memset with two words to __ex_table */ __asm__ __volatile__ ( \ "1: sb r0, %1, r0;" \ " addik %0, %0, -1;" \ " bneid %0, 1b;" \ " addik %1, %1, 1;" \ "2: " \ __EX_TABLE_SECTION \ ".word 1b,2b;" \ ".previous;" \ : "=r"(n), "=r"(to) \ : "0"(n), "1"(to) ); return n; } static inline unsigned long __must_check clear_user(void __user *to, unsigned long n) { might_fault(); if (unlikely(!access_ok(to, n))) return n; return __clear_user(to, n); } /* put_user and get_user macros */ extern long __user_bad(void); #define __get_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ ({ \ __asm__ __volatile__ ( \ "1:" insn " %1, %2, r0;" \ " addk %0, r0, r0;" \ "2: " \ __FIXUP_SECTION \ "3: brid 2b;" \ " addik %0, r0, %3;" \ ".previous;" \ __EX_TABLE_SECTION \ ".word 1b,3b;" \ ".previous;" \ : "=&r"(__gu_err), "=r"(__gu_val) \ : "r"(__gu_ptr), "i"(-EFAULT) \ ); \ }) /** * get_user: - Get a simple variable from user space. * @x: Variable to store result. * @ptr: Source address, in user space. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * This macro copies a single simple variable from user space to kernel * space. It supports simple types like char and int, but not larger * data types like structures or arrays. * * @ptr must have pointer-to-simple-variable type, and the result of * dereferencing @ptr must be assignable to @x without a cast. * * Returns zero on success, or -EFAULT on error. * On error, the variable @x is set to zero. */ #define get_user(x, ptr) ({ \ const typeof(*(ptr)) __user *__gu_ptr = (ptr); \ access_ok(__gu_ptr, sizeof(*__gu_ptr)) ? \ __get_user(x, __gu_ptr) : -EFAULT; \ }) #define __get_user(x, ptr) \ ({ \ long __gu_err; \ switch (sizeof(*(ptr))) { \ case 1: \ __get_user_asm("lbu", (ptr), x, __gu_err); \ break; \ case 2: \ __get_user_asm("lhu", (ptr), x, __gu_err); \ break; \ case 4: \ __get_user_asm("lw", (ptr), x, __gu_err); \ break; \ case 8: { \ __u64 __x = 0; \ __gu_err = raw_copy_from_user(&__x, ptr, 8) ? \ -EFAULT : 0; \ (x) = (typeof(x))(typeof((x) - (x)))__x; \ break; \ } \ default: \ /* __gu_val = 0; __gu_err = -EINVAL;*/ __gu_err = __user_bad();\ } \ __gu_err; \ }) #define __put_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ ({ \ __asm__ __volatile__ ( \ "1:" insn " %1, %2, r0;" \ " addk %0, r0, r0;" \ "2: " \ __FIXUP_SECTION \ "3: brid 2b;" \ " addik %0, r0, %3;" \ ".previous;" \ __EX_TABLE_SECTION \ ".word 1b,3b;" \ ".previous;" \ : "=&r"(__gu_err) \ : "r"(__gu_val), "r"(__gu_ptr), "i"(-EFAULT) \ ); \ }) #define __put_user_asm_8(__gu_ptr, __gu_val, __gu_err) \ ({ \ __asm__ __volatile__ (" lwi %0, %1, 0;" \ "1: swi %0, %2, 0;" \ " lwi %0, %1, 4;" \ "2: swi %0, %2, 4;" \ " addk %0, r0, r0;" \ "3: " \ __FIXUP_SECTION \ "4: brid 3b;" \ " addik %0, r0, %3;" \ ".previous;" \ __EX_TABLE_SECTION \ ".word 1b,4b,2b,4b;" \ ".previous;" \ : "=&r"(__gu_err) \ : "r"(&__gu_val), "r"(__gu_ptr), "i"(-EFAULT) \ ); \ }) /** * put_user: - Write a simple value into user space. * @x: Value to copy to user space. * @ptr: Destination address, in user space. * * Context: User context only. This function may sleep if pagefaults are * enabled. * * This macro copies a single simple value from kernel space to user * space. It supports simple types like char and int, but not larger * data types like structures or arrays. * * @ptr must have pointer-to-simple-variable type, and @x must be assignable * to the result of dereferencing @ptr. * * Returns zero on success, or -EFAULT on error. */ #define put_user(x, ptr) \ __put_user_check((x), (ptr), sizeof(*(ptr))) #define __put_user_check(x, ptr, size) \ ({ \ typeof(*(ptr)) volatile __pu_val = x; \ typeof(*(ptr)) __user *__pu_addr = (ptr); \ int __pu_err = 0; \ \ if (access_ok(__pu_addr, size)) { \ switch (size) { \ case 1: \ __put_user_asm("sb", __pu_addr, __pu_val, \ __pu_err); \ break; \ case 2: \ __put_user_asm("sh", __pu_addr, __pu_val, \ __pu_err); \ break; \ case 4: \ __put_user_asm("sw", __pu_addr, __pu_val, \ __pu_err); \ break; \ case 8: \ __put_user_asm_8(__pu_addr, __pu_val, __pu_err);\ break; \ default: \ __pu_err = __user_bad(); \ break; \ } \ } else { \ __pu_err = -EFAULT; \ } \ __pu_err; \ }) #define __put_user(x, ptr) \ ({ \ __typeof__(*(ptr)) volatile __gu_val = (x); \ long __gu_err = 0; \ switch (sizeof(__gu_val)) { \ case 1: \ __put_user_asm("sb", (ptr), __gu_val, __gu_err); \ break; \ case 2: \ __put_user_asm("sh", (ptr), __gu_val, __gu_err); \ break; \ case 4: \ __put_user_asm("sw", (ptr), __gu_val, __gu_err); \ break; \ case 8: \ __put_user_asm_8((ptr), __gu_val, __gu_err); \ break; \ default: \ /*__gu_err = -EINVAL;*/ __gu_err = __user_bad(); \ } \ __gu_err; \ }) static inline unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n) { return __copy_tofrom_user((__force void __user *)to, from, n); } static inline unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n) { return __copy_tofrom_user(to, (__force const void __user *)from, n); } #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER /* * Copy a null terminated string from userspace. */ __must_check long strncpy_from_user(char *dst, const char __user *src, long count); /* * Return the size of a string (including the ending 0) * * Return 0 on exception, a value greater than N if too long */ __must_check long strnlen_user(const char __user *sstr, long len); #endif /* _ASM_MICROBLAZE_UACCESS_H */
| ver. 1.4 |
Github
|
.
| PHP 8.2.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings