^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_IA64_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_IA64_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file defines various macros to transfer memory areas across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * the user/kernel boundary. This needs to be done carefully because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * this code is executed in kernel mode and uses user-specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * addresses. Thus, we need to be careful not to let the user to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * trick us into accessing kernel memory that would normally be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * inaccessible. This code is also fairly performance sensitive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * so we want to spend as little time doing safety checks as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * To make matters a bit more interesting, these macros sometimes also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * called from within the kernel itself, in which case the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * validity check must be skipped. The get_fs() macro tells us what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * to do: if get_fs()==USER_DS, checking is performed, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * get_fs()==KERNEL_DS, checking is bypassed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Note that even if the memory area specified by the user is in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * valid address range, it is still possible that we'll get a page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * fault while accessing it. This is handled by filling out an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * exception handler fixup entry for each instruction that has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * potential to fault. When such a fault occurs, the page fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * handler checks to see whether the faulting instruction has a fixup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * associated and, if so, sets r8 to -EFAULT and clears r9 to 0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * then resumes execution at the continuation point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Based on <asm-alpha/uaccess.h>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Copyright (C) 1998, 1999, 2001-2004 Hewlett-Packard Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * David Mosberger-Tang <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/page-flags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/intrinsics.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * For historical reasons, the following macros are grossly misnamed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define KERNEL_DS ((mm_segment_t) { ~0UL }) /* cf. access_ok() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define USER_DS ((mm_segment_t) { TASK_SIZE-1 }) /* cf. access_ok() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define get_fs() (current_thread_info()->addr_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define set_fs(x) (current_thread_info()->addr_limit = (x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * When accessing user memory, we need to make sure the entire area really is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * user-level space. In order to do this efficiently, we make sure that the page at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * address TASK_SIZE is never valid. We also need to make sure that the address doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * point inside the virtually mapped linear page table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static inline int __access_ok(const void __user *p, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned long addr = (unsigned long)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned long seg = get_fs().seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return likely(addr <= seg) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) (seg == KERNEL_DS.seg || likely(REGION_OFFSET(addr) < RGN_MAP_LIMIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define access_ok(addr, size) __access_ok((addr), (size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * These are the main single-value transfer routines. They automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * use the right size if we just have the right pointer type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * Careful to not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * (a) re-use the arguments for side effects (sizeof/typeof is ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * (b) require any knowledge of processes at this stage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define put_user(x, ptr) __put_user_check((__typeof__(*(ptr))) (x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * The "__xxx" versions do not do address space checking, useful when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * doing multiple accesses to the same area (the programmer has to do the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * checks by hand with "access_ok()")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define __put_user(x, ptr) __put_user_nocheck((__typeof__(*(ptr))) (x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #ifdef ASM_SUPPORTED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct __large_struct { unsigned long buf[100]; };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) # define __m(x) (*(struct __large_struct __user *)(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* We need to declare the __ex_table section before we can use it in .xdata. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) asm (".section \"__ex_table\", \"a\"\n\t.previous");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) # define __get_user_size(val, addr, n, err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) register long __gu_r8 asm ("r8") = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) register long __gu_r9 asm ("r9"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) asm ("\n[1:]\tld"#n" %0=%2%P2\t// %0 and %1 get overwritten by exception handler\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) "\t.xdata4 \"__ex_table\", 1b-., 1f-.+4\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) "[1:]" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) : "=r"(__gu_r9), "=r"(__gu_r8) : "m"(__m(addr)), "1"(__gu_r8)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) (err) = __gu_r8; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) (val) = __gu_r9; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * The "__put_user_size()" macro tells gcc it reads from memory instead of writing it. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * is because they do not write to any memory gcc knows about, so there are no aliasing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) # define __put_user_size(val, addr, n, err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) register long __pu_r8 asm ("r8") = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) asm volatile ("\n[1:]\tst"#n" %1=%r2%P1\t// %0 gets overwritten by exception handler\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) "\t.xdata4 \"__ex_table\", 1b-., 1f-.\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) "[1:]" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) : "=r"(__pu_r8) : "m"(__m(addr)), "rO"(val), "0"(__pu_r8)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) (err) = __pu_r8; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #else /* !ASM_SUPPORTED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) # define RELOC_TYPE 2 /* ip-rel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) # define __get_user_size(val, addr, n, err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __ld_user("__ex_table", (unsigned long) addr, n, RELOC_TYPE); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) (err) = ia64_getreg(_IA64_REG_R8); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) (val) = ia64_getreg(_IA64_REG_R9); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) # define __put_user_size(val, addr, n, err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) __st_user("__ex_table", (unsigned long) addr, n, RELOC_TYPE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) (__force unsigned long) (val)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) (err) = ia64_getreg(_IA64_REG_R8); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif /* !ASM_SUPPORTED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern void __get_user_unknown (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * Evaluating arguments X, PTR, SIZE, and SEGMENT may involve subroutine-calls, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * could clobber r8 and r9 (among others). Thus, be careful not to evaluate it while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * using r8/r9.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define __do_get_user(check, x, ptr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __typeof__ (size) __gu_size = (size); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) long __gu_err = -EFAULT; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) unsigned long __gu_val = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!check || __access_ok(__gu_ptr, size)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) switch (__gu_size) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case 1: __get_user_size(__gu_val, __gu_ptr, 1, __gu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) case 2: __get_user_size(__gu_val, __gu_ptr, 2, __gu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) case 4: __get_user_size(__gu_val, __gu_ptr, 4, __gu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) case 8: __get_user_size(__gu_val, __gu_ptr, 8, __gu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) default: __get_user_unknown(); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) (x) = (__force __typeof__(*(__gu_ptr))) __gu_val; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __gu_err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #define __get_user_nocheck(x, ptr, size) __do_get_user(0, x, ptr, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define __get_user_check(x, ptr, size) __do_get_user(1, x, ptr, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) extern void __put_user_unknown (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Evaluating arguments X, PTR, SIZE, and SEGMENT may involve subroutine-calls, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * could clobber r8 (among others). Thus, be careful not to evaluate them while using r8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define __do_put_user(check, x, ptr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) __typeof__ (x) __pu_x = (x); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) __typeof__ (*(ptr)) __user *__pu_ptr = (ptr); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) __typeof__ (size) __pu_size = (size); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) long __pu_err = -EFAULT; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!check || __access_ok(__pu_ptr, __pu_size)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) switch (__pu_size) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) case 1: __put_user_size(__pu_x, __pu_ptr, 1, __pu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) case 2: __put_user_size(__pu_x, __pu_ptr, 2, __pu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) case 4: __put_user_size(__pu_x, __pu_ptr, 4, __pu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) case 8: __put_user_size(__pu_x, __pu_ptr, 8, __pu_err); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) default: __put_user_unknown(); break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) __pu_err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define __put_user_nocheck(x, ptr, size) __do_put_user(0, x, ptr, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define __put_user_check(x, ptr, size) __do_put_user(1, x, ptr, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * Complex access routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) extern unsigned long __must_check __copy_user (void __user *to, const void __user *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) raw_copy_to_user(void __user *to, const void *from, unsigned long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return __copy_user(to, (__force void __user *) from, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) raw_copy_from_user(void *to, const void __user *from, unsigned long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return __copy_user((__force void __user *) to, from, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define INLINE_COPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define INLINE_COPY_TO_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) extern unsigned long __do_clear_user (void __user *, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define __clear_user(to, n) __do_clear_user(to, n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define clear_user(to, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) unsigned long __cu_len = (n); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (__access_ok(to, __cu_len)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) __cu_len = __do_clear_user(to, __cu_len); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) __cu_len; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Returns: -EFAULT if exception before terminator, N if the entire buffer filled, else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * strlen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) extern long __must_check __strncpy_from_user (char *to, const char __user *from, long to_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define strncpy_from_user(to, from, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) const char __user * __sfu_from = (from); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) long __sfu_ret = -EFAULT; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (__access_ok(__sfu_from, 0)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) __sfu_ret = __strncpy_from_user((to), __sfu_from, (n)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) __sfu_ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * Returns: 0 if exception before NUL or reaching the supplied limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * (N), a value greater than N if the limit would be exceeded, else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * strlen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) extern unsigned long __strnlen_user (const char __user *, long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define strnlen_user(str, len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) const char __user *__su_str = (str); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned long __su_ret = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (__access_ok(__su_str, 0)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) __su_ret = __strnlen_user(__su_str, len); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) __su_ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #define ARCH_HAS_TRANSLATE_MEM_PTR 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static __inline__ void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) xlate_dev_mem_ptr(phys_addr_t p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) page = pfn_to_page(p >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (PageUncached(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ptr = (void *)p + __IA64_UNCACHED_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ptr = __va(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Convert a virtual cached kernel memory pointer to an uncached pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static __inline__ void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) xlate_dev_kmem_ptr(void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) void *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) page = virt_to_page((unsigned long)p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (PageUncached(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ptr = (void *)__pa(p) + __IA64_UNCACHED_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ptr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif /* _ASM_IA64_UACCESS_H */