getuser.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * __get_user functions.
  3. *
  4. * (C) Copyright 1998 Linus Torvalds
  5. * (C) Copyright 2005 Andi Kleen
  6. *
  7. * These functions have a non-standard call interface
  8. * to make them more efficient, especially as they
  9. * return an error value in addition to the "real"
  10. * return value.
  11. */
  12. /*
  13. * __get_user_X
  14. *
  15. * Inputs: %rcx contains the address.
  16. * The register is modified, but all changes are undone
  17. * before returning because the C code doesn't know about it.
  18. *
  19. * Outputs: %rax is error code (0 or -EFAULT)
  20. * %rdx contains zero-extended value
  21. *
  22. * %r8 is destroyed.
  23. *
  24. * These functions should not modify any other registers,
  25. * as they get called from within inline assembly.
  26. */
  27. #include <linux/linkage.h>
  28. #include <asm/page.h>
  29. #include <asm/errno.h>
  30. #include <asm/asm-offsets.h>
  31. #include <asm/thread_info.h>
  32. .text
  33. .p2align 4
  34. .globl __get_user_1
  35. __get_user_1:
  36. GET_THREAD_INFO(%r8)
  37. cmpq threadinfo_addr_limit(%r8),%rcx
  38. jae bad_get_user
  39. 1: movzb (%rcx),%edx
  40. xorl %eax,%eax
  41. ret
  42. .p2align 4
  43. .globl __get_user_2
  44. __get_user_2:
  45. GET_THREAD_INFO(%r8)
  46. addq $1,%rcx
  47. jc 20f
  48. cmpq threadinfo_addr_limit(%r8),%rcx
  49. jae 20f
  50. decq %rcx
  51. 2: movzwl (%rcx),%edx
  52. xorl %eax,%eax
  53. ret
  54. 20: decq %rcx
  55. jmp bad_get_user
  56. .p2align 4
  57. .globl __get_user_4
  58. __get_user_4:
  59. GET_THREAD_INFO(%r8)
  60. addq $3,%rcx
  61. jc 30f
  62. cmpq threadinfo_addr_limit(%r8),%rcx
  63. jae 30f
  64. subq $3,%rcx
  65. 3: movl (%rcx),%edx
  66. xorl %eax,%eax
  67. ret
  68. 30: subq $3,%rcx
  69. jmp bad_get_user
  70. .p2align 4
  71. .globl __get_user_8
  72. __get_user_8:
  73. GET_THREAD_INFO(%r8)
  74. addq $7,%rcx
  75. jc 40f
  76. cmpq threadinfo_addr_limit(%r8),%rcx
  77. jae 40f
  78. subq $7,%rcx
  79. 4: movq (%rcx),%rdx
  80. xorl %eax,%eax
  81. ret
  82. 40: subq $7,%rcx
  83. jmp bad_get_user
  84. bad_get_user:
  85. xorl %edx,%edx
  86. movq $(-EFAULT),%rax
  87. ret
  88. .section __ex_table,"a"
  89. .quad 1b,bad_get_user
  90. .quad 2b,bad_get_user
  91. .quad 3b,bad_get_user
  92. .quad 4b,bad_get_user
  93. .previous