clear_user.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Based on arch/arm/lib/clear_user.S
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  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. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/linkage.h>
  19. #include <asm/asm-uaccess.h>
  20. .text
  21. /* Prototype: int __arch_clear_user(void *addr, size_t sz)
  22. * Purpose : clear some user memory
  23. * Params : addr - user memory address to clear
  24. * : sz - number of bytes to clear
  25. * Returns : number of bytes NOT cleared
  26. *
  27. * Alignment fixed up by hardware.
  28. */
  29. ENTRY(__arch_clear_user)
  30. uaccess_enable_not_uao x2, x3, x4
  31. mov x2, x1 // save the size for fixup return
  32. subs x1, x1, #8
  33. b.mi 2f
  34. 1:
  35. uao_user_alternative 9f, str, sttr, xzr, x0, 8
  36. subs x1, x1, #8
  37. b.pl 1b
  38. 2: adds x1, x1, #4
  39. b.mi 3f
  40. uao_user_alternative 9f, str, sttr, wzr, x0, 4
  41. sub x1, x1, #4
  42. 3: adds x1, x1, #2
  43. b.mi 4f
  44. uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
  45. sub x1, x1, #2
  46. 4: adds x1, x1, #1
  47. b.mi 5f
  48. uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
  49. 5: mov x0, #0
  50. uaccess_disable_not_uao x2, x3
  51. ret
  52. ENDPROC(__arch_clear_user)
  53. .section .fixup,"ax"
  54. .align 2
  55. 9: mov x0, x2 // return the original size
  56. uaccess_disable_not_uao x2, x3
  57. ret
  58. .previous