strncpy_user.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. */
  8. #include <linux/errno.h>
  9. #include <asm/asm.h>
  10. #include <asm/offset.h>
  11. #include <asm/regdef.h>
  12. #define EX(insn,reg,addr,handler) \
  13. 9: insn reg, addr; \
  14. .section __ex_table,"a"; \
  15. PTR 9b, handler; \
  16. .previous
  17. /*
  18. * Returns: -EFAULT if exception before terminator, N if the entire
  19. * buffer filled, else strlen.
  20. */
  21. /*
  22. * Ugly special case have to check: we might get passed a user space
  23. * pointer which wraps into the kernel space. We don't deal with that. If
  24. * it happens at most some bytes of the exceptions handlers will be copied.
  25. */
  26. LEAF(__strncpy_from_user_asm)
  27. LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
  28. and v0, a1
  29. bnez v0, fault
  30. FEXPORT(__strncpy_from_user_nocheck_asm)
  31. move v0, zero
  32. move v1, a1
  33. .set noreorder
  34. 1: EX(lbu, t0, (v1), fault)
  35. PTR_ADDIU v1, 1
  36. beqz t0, 2f
  37. sb t0, (a0)
  38. PTR_ADDIU v0, 1
  39. bne v0, a2, 1b
  40. PTR_ADDIU a0, 1
  41. .set reorder
  42. 2: PTR_ADDU t0, a1, v0
  43. xor t0, a1
  44. bltz t0, fault
  45. jr ra # return n
  46. END(__strncpy_from_user_asm)
  47. fault: li v0, -EFAULT
  48. jr ra
  49. .section __ex_table,"a"
  50. PTR 1b, fault
  51. .previous