strncpy_user.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1996, 1999 by Ralf Baechle
  7. * Copyright (C) 2011 MIPS Technologies, Inc.
  8. */
  9. #include <linux/errno.h>
  10. #include <asm/asm.h>
  11. #include <asm/asm-offsets.h>
  12. #include <asm/regdef.h>
  13. #define EX(insn,reg,addr,handler) \
  14. 9: insn reg, addr; \
  15. .section __ex_table,"a"; \
  16. PTR 9b, handler; \
  17. .previous
  18. /*
  19. * Returns: -EFAULT if exception before terminator, N if the entire
  20. * buffer filled, else strlen.
  21. */
  22. /*
  23. * Ugly special case have to check: we might get passed a user space
  24. * pointer which wraps into the kernel space. We don't deal with that. If
  25. * it happens at most some bytes of the exceptions handlers will be copied.
  26. */
  27. .macro __BUILD_STRNCPY_ASM func
  28. LEAF(__strncpy_from_\func\()_asm)
  29. LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
  30. and v0, a1
  31. bnez v0, .Lfault\@
  32. FEXPORT(__strncpy_from_\func\()_nocheck_asm)
  33. move t0, zero
  34. move v1, a1
  35. .ifeqs "\func","kernel"
  36. 1: EX(lbu, v0, (v1), .Lfault\@)
  37. .else
  38. 1: EX(lbue, v0, (v1), .Lfault\@)
  39. .endif
  40. PTR_ADDIU v1, 1
  41. R10KCBARRIER(0(ra))
  42. sb v0, (a0)
  43. beqz v0, 2f
  44. PTR_ADDIU t0, 1
  45. PTR_ADDIU a0, 1
  46. bne t0, a2, 1b
  47. 2: PTR_ADDU v0, a1, t0
  48. xor v0, a1
  49. bltz v0, .Lfault\@
  50. move v0, t0
  51. jr ra # return n
  52. END(__strncpy_from_\func\()_asm)
  53. .Lfault\@:
  54. li v0, -EFAULT
  55. jr ra
  56. .section __ex_table,"a"
  57. PTR 1b, .Lfault\@
  58. .previous
  59. .endm
  60. #ifndef CONFIG_EVA
  61. /* Set aliases */
  62. .global __strncpy_from_user_asm
  63. .global __strncpy_from_user_nocheck_asm
  64. .set __strncpy_from_user_asm, __strncpy_from_kernel_asm
  65. .set __strncpy_from_user_nocheck_asm, __strncpy_from_kernel_nocheck_asm
  66. #endif
  67. __BUILD_STRNCPY_ASM kernel
  68. #ifdef CONFIG_EVA
  69. .set push
  70. .set eva
  71. __BUILD_STRNCPY_ASM user
  72. .set pop
  73. #endif