clear_user.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/alternative.h>
  20. #include <asm/assembler.h>
  21. #include <asm/cpufeature.h>
  22. #include <asm/sysreg.h>
  23. .text
  24. /* Prototype: int __arch_clear_user(void *addr, size_t sz)
  25. * Purpose : clear some user memory
  26. * Params : addr - user memory address to clear
  27. * : sz - number of bytes to clear
  28. * Returns : number of bytes NOT cleared
  29. *
  30. * Alignment fixed up by hardware.
  31. */
  32. ENTRY(__arch_clear_user)
  33. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_ALT_PAN_NOT_UAO, \
  34. CONFIG_ARM64_PAN)
  35. mov x2, x1 // save the size for fixup return
  36. subs x1, x1, #8
  37. b.mi 2f
  38. 1:
  39. uao_user_alternative 9f, str, sttr, xzr, x0, 8
  40. subs x1, x1, #8
  41. b.pl 1b
  42. 2: adds x1, x1, #4
  43. b.mi 3f
  44. uao_user_alternative 9f, str, sttr, wzr, x0, 4
  45. sub x1, x1, #4
  46. 3: adds x1, x1, #2
  47. b.mi 4f
  48. uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
  49. sub x1, x1, #2
  50. 4: adds x1, x1, #1
  51. b.mi 5f
  52. uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
  53. 5: mov x0, #0
  54. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_ALT_PAN_NOT_UAO, \
  55. CONFIG_ARM64_PAN)
  56. ret
  57. ENDPROC(__arch_clear_user)
  58. .section .fixup,"ax"
  59. .align 2
  60. 9: mov x0, x2 // return the original size
  61. ret
  62. .previous