strncpy_user.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. LEAF(__strncpy_from_user_asm)
  28. LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
  29. and v0, a1
  30. bnez v0, .Lfault
  31. FEXPORT(__strncpy_from_user_nocheck_asm)
  32. .set noreorder
  33. move t0, zero
  34. move v1, a1
  35. 1: EX(lbu, v0, (v1), .Lfault)
  36. PTR_ADDIU v1, 1
  37. R10KCBARRIER(0(ra))
  38. beqz v0, 2f
  39. sb v0, (a0)
  40. PTR_ADDIU t0, 1
  41. bne t0, a2, 1b
  42. PTR_ADDIU a0, 1
  43. 2: PTR_ADDU v0, a1, t0
  44. xor v0, a1
  45. bltz v0, .Lfault
  46. nop
  47. jr ra # return n
  48. move v0, t0
  49. END(__strncpy_from_user_asm)
  50. .Lfault: jr ra
  51. li v0, -EFAULT
  52. .section __ex_table,"a"
  53. PTR 1b, .Lfault
  54. .previous