strncpy_user.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_WD 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. LEAF(__strncpy_from_user_asm)
  29. move t0, zero
  30. move v1, a1
  31. #ifdef CONFIG_EVA
  32. .set push
  33. .set eva
  34. 1: EX(lbue, v0, (v1), .Lfault)
  35. .set pop
  36. #else
  37. 1: EX(lbu, v0, (v1), .Lfault)
  38. #endif
  39. PTR_ADDIU v1, 1
  40. R10KCBARRIER(0(ra))
  41. sb v0, (a0)
  42. beqz v0, 2f
  43. PTR_ADDIU t0, 1
  44. PTR_ADDIU a0, 1
  45. bne t0, a2, 1b
  46. 2: PTR_ADDU v0, a1, t0
  47. xor v0, a1
  48. bltz v0, .Lfault
  49. move v0, t0
  50. jr ra # return n
  51. END(__strncpy_from_user_asm)
  52. .Lfault:
  53. li v0, -EFAULT
  54. jr ra
  55. .section __ex_table,"a"
  56. PTR_WD 1b, .Lfault
  57. .previous
  58. EXPORT_SYMBOL(__strncpy_from_user_asm)