strncpy_from_user.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Just like strncpy() except that if a fault occurs during copying,
  3. * -EFAULT is returned.
  4. *
  5. * Inputs:
  6. * in0: address of destination buffer
  7. * in1: address of string to be copied
  8. * in2: length of buffer in bytes
  9. * Outputs:
  10. * r8: -EFAULT in case of fault or number of bytes copied if no fault
  11. *
  12. * Copyright (C) 1998-2001 Hewlett-Packard Co
  13. * Copyright (C) 1998-2001 David Mosberger-Tang <davidm@hpl.hp.com>
  14. *
  15. * 00/03/06 D. Mosberger Fixed to return proper return value (bug found by
  16. * by Andreas Schwab <schwab@suse.de>).
  17. */
  18. #include <asm/asmmacro.h>
  19. #include <asm/export.h>
  20. GLOBAL_ENTRY(__strncpy_from_user)
  21. alloc r2=ar.pfs,3,0,0,0
  22. mov r8=0
  23. mov r9=in1
  24. ;;
  25. add r10=in1,in2
  26. cmp.eq p6,p0=r0,in2
  27. (p6) br.ret.spnt.many rp
  28. // XXX braindead copy loop---this needs to be optimized
  29. .Loop1:
  30. EX(.Lexit, ld1 r8=[in1],1)
  31. ;;
  32. EX(.Lexit, st1 [in0]=r8,1)
  33. cmp.ne p6,p7=r8,r0
  34. ;;
  35. (p6) cmp.ne.unc p8,p0=in1,r10
  36. (p8) br.cond.dpnt.few .Loop1
  37. ;;
  38. (p6) mov r8=in2 // buffer filled up---return buffer length
  39. (p7) sub r8=in1,r9,1 // return string length (excluding NUL character)
  40. [.Lexit:]
  41. br.ret.sptk.many rp
  42. END(__strncpy_from_user)
  43. EXPORT_SYMBOL(__strncpy_from_user)