strncpy_user.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/asm-offsets.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, .Lfault
  30. FEXPORT(__strncpy_from_user_nocheck_asm)
  31. move v0, zero
  32. move v1, a1
  33. .set noreorder
  34. 1: EX(lbu, t0, (v1), .Lfault)
  35. PTR_ADDIU v1, 1
  36. R10KCBARRIER(0(ra))
  37. beqz t0, 2f
  38. sb t0, (a0)
  39. PTR_ADDIU v0, 1
  40. .set reorder
  41. PTR_ADDIU a0, 1
  42. bne v0, a2, 1b
  43. 2: PTR_ADDU t0, a1, v0
  44. xor t0, a1
  45. bltz t0, .Lfault
  46. jr ra # return n
  47. END(__strncpy_from_user_asm)
  48. .Lfault: li v0, -EFAULT
  49. jr ra
  50. .section __ex_table,"a"
  51. PTR 1b, .Lfault
  52. .previous