getuser.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * __get_user functions.
  3. *
  4. * (C) Copyright 1998 Linus Torvalds
  5. * (C) Copyright 2005 Andi Kleen
  6. * (C) Copyright 2008 Glauber Costa
  7. *
  8. * These functions have a non-standard call interface
  9. * to make them more efficient, especially as they
  10. * return an error value in addition to the "real"
  11. * return value.
  12. */
  13. /*
  14. * __get_user_X
  15. *
  16. * Inputs: %[r|e]ax contains the address.
  17. * The register is modified, but all changes are undone
  18. * before returning because the C code doesn't know about it.
  19. *
  20. * Outputs: %[r|e]ax is error code (0 or -EFAULT)
  21. * %[r|e]dx contains zero-extended value
  22. *
  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/dwarf2.h>
  29. #include <asm/page_types.h>
  30. #include <asm/errno.h>
  31. #include <asm/asm-offsets.h>
  32. #include <asm/thread_info.h>
  33. #include <asm/asm.h>
  34. #include <asm/smap.h>
  35. .text
  36. ENTRY(__get_user_1)
  37. CFI_STARTPROC
  38. GET_THREAD_INFO(%_ASM_DX)
  39. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  40. jae bad_get_user
  41. ASM_STAC
  42. 1: movzb (%_ASM_AX),%edx
  43. xor %eax,%eax
  44. ASM_CLAC
  45. ret
  46. CFI_ENDPROC
  47. ENDPROC(__get_user_1)
  48. ENTRY(__get_user_2)
  49. CFI_STARTPROC
  50. add $1,%_ASM_AX
  51. jc bad_get_user
  52. GET_THREAD_INFO(%_ASM_DX)
  53. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  54. jae bad_get_user
  55. ASM_STAC
  56. 2: movzwl -1(%_ASM_AX),%edx
  57. xor %eax,%eax
  58. ASM_CLAC
  59. ret
  60. CFI_ENDPROC
  61. ENDPROC(__get_user_2)
  62. ENTRY(__get_user_4)
  63. CFI_STARTPROC
  64. add $3,%_ASM_AX
  65. jc bad_get_user
  66. GET_THREAD_INFO(%_ASM_DX)
  67. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  68. jae bad_get_user
  69. ASM_STAC
  70. 3: mov -3(%_ASM_AX),%edx
  71. xor %eax,%eax
  72. ASM_CLAC
  73. ret
  74. CFI_ENDPROC
  75. ENDPROC(__get_user_4)
  76. #ifdef CONFIG_X86_64
  77. ENTRY(__get_user_8)
  78. CFI_STARTPROC
  79. add $7,%_ASM_AX
  80. jc bad_get_user
  81. GET_THREAD_INFO(%_ASM_DX)
  82. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  83. jae bad_get_user
  84. ASM_STAC
  85. 4: movq -7(%_ASM_AX),%_ASM_DX
  86. xor %eax,%eax
  87. ASM_CLAC
  88. ret
  89. CFI_ENDPROC
  90. ENDPROC(__get_user_8)
  91. #endif
  92. bad_get_user:
  93. CFI_STARTPROC
  94. xor %edx,%edx
  95. mov $(-EFAULT),%_ASM_AX
  96. ASM_CLAC
  97. ret
  98. CFI_ENDPROC
  99. END(bad_get_user)
  100. _ASM_EXTABLE(1b,bad_get_user)
  101. _ASM_EXTABLE(2b,bad_get_user)
  102. _ASM_EXTABLE(3b,bad_get_user)
  103. #ifdef CONFIG_X86_64
  104. _ASM_EXTABLE(4b,bad_get_user)
  105. #endif