strncpy_user.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/export.h>
  13. #include <asm/regdef.h>
  14. #define EX(insn,reg,addr,handler) \
  15. 9: insn reg, addr; \
  16. .section __ex_table,"a"; \
  17. PTR 9b, handler; \
  18. .previous
  19. /*
  20. * Returns: -EFAULT if exception before terminator, N if the entire
  21. * buffer filled, else strlen.
  22. */
  23. /*
  24. * Ugly special case have to check: we might get passed a user space
  25. * pointer which wraps into the kernel space. We don't deal with that. If
  26. * it happens at most some bytes of the exceptions handlers will be copied.
  27. */
  28. .macro __BUILD_STRNCPY_ASM func
  29. LEAF(__strncpy_from_\func\()_asm)
  30. LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
  31. and v0, a1
  32. bnez v0, .Lfault\@
  33. FEXPORT(__strncpy_from_\func\()_nocheck_asm)
  34. move t0, zero
  35. move v1, a1
  36. .ifeqs "\func","kernel"
  37. 1: EX(lbu, v0, (v1), .Lfault\@)
  38. .else
  39. 1: EX(lbue, v0, (v1), .Lfault\@)
  40. .endif
  41. PTR_ADDIU v1, 1
  42. R10KCBARRIER(0(ra))
  43. sb v0, (a0)
  44. beqz v0, 2f
  45. PTR_ADDIU t0, 1
  46. PTR_ADDIU a0, 1
  47. bne t0, a2, 1b
  48. 2: PTR_ADDU v0, a1, t0
  49. xor v0, a1
  50. bltz v0, .Lfault\@
  51. move v0, t0
  52. jr ra # return n
  53. END(__strncpy_from_\func\()_asm)
  54. .Lfault\@:
  55. li v0, -EFAULT
  56. jr ra
  57. .section __ex_table,"a"
  58. PTR 1b, .Lfault\@
  59. .previous
  60. .endm
  61. #ifndef CONFIG_EVA
  62. /* Set aliases */
  63. .global __strncpy_from_user_asm
  64. .global __strncpy_from_user_nocheck_asm
  65. .set __strncpy_from_user_asm, __strncpy_from_kernel_asm
  66. .set __strncpy_from_user_nocheck_asm, __strncpy_from_kernel_nocheck_asm
  67. EXPORT_SYMBOL(__strncpy_from_user_asm)
  68. EXPORT_SYMBOL(__strncpy_from_user_nocheck_asm)
  69. #endif
  70. __BUILD_STRNCPY_ASM kernel
  71. EXPORT_SYMBOL(__strncpy_from_kernel_asm)
  72. EXPORT_SYMBOL(__strncpy_from_kernel_nocheck_asm)
  73. #ifdef CONFIG_EVA
  74. .set push
  75. .set eva
  76. __BUILD_STRNCPY_ASM user
  77. .set pop
  78. EXPORT_SYMBOL(__strncpy_from_user_asm)
  79. EXPORT_SYMBOL(__strncpy_from_user_nocheck_asm)
  80. #endif