strncpy_from_user.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copy to/from userspace with optional address space checking.
  3. *
  4. * Copyright 2004-2006 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/errno.h>
  11. #include <asm/page.h>
  12. #include <asm/thread_info.h>
  13. #include <asm/asm.h>
  14. /*
  15. * long strncpy_from_user(char *dst, const char *src, long count)
  16. *
  17. * On success, returns the length of the string, not including
  18. * the terminating NUL.
  19. *
  20. * If the string is longer than count, returns count
  21. *
  22. * If userspace access fails, returns -EFAULT
  23. */
  24. .text
  25. .align 1
  26. .global strncpy_from_user
  27. .type strncpy_from_user, "function"
  28. strncpy_from_user:
  29. mov r9, -EFAULT
  30. branch_if_kernel r8, __strncpy_from_user
  31. ret_if_privileged r8, r11, r10, r9
  32. .global __strncpy_from_user
  33. .type __strncpy_from_user, "function"
  34. __strncpy_from_user:
  35. cp.w r10, 0
  36. reteq 0
  37. mov r9, r10
  38. 1: ld.ub r8, r11++
  39. st.b r12++, r8
  40. cp.w r8, 0
  41. breq 2f
  42. sub r9, 1
  43. brne 1b
  44. 2: sub r10, r9
  45. retal r10
  46. .section .fixup, "ax"
  47. .align 1
  48. 3: mov r12, -EFAULT
  49. retal r12
  50. .section __ex_table, "a"
  51. .align 2
  52. .long 1b, 3b