putuser.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * __put_user functions.
  3. *
  4. * (C) Copyright 2005 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. #include <linux/linkage.h>
  14. #include <asm/dwarf2.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/errno.h>
  17. #include <asm/asm.h>
  18. #include <asm/smap.h>
  19. /*
  20. * __put_user_X
  21. *
  22. * Inputs: %eax[:%edx] contains the data
  23. * %ecx contains the address
  24. *
  25. * Outputs: %eax is error code (0 or -EFAULT)
  26. *
  27. * These functions should not modify any other registers,
  28. * as they get called from within inline assembly.
  29. */
  30. #define ENTER CFI_STARTPROC ; \
  31. GET_THREAD_INFO(%_ASM_BX)
  32. #define EXIT ASM_CLAC ; \
  33. ret ; \
  34. CFI_ENDPROC
  35. .text
  36. ENTRY(__put_user_1)
  37. ENTER
  38. cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
  39. jae bad_put_user
  40. ASM_STAC
  41. 1: movb %al,(%_ASM_CX)
  42. xor %eax,%eax
  43. EXIT
  44. ENDPROC(__put_user_1)
  45. ENTRY(__put_user_2)
  46. ENTER
  47. mov TI_addr_limit(%_ASM_BX),%_ASM_BX
  48. sub $1,%_ASM_BX
  49. cmp %_ASM_BX,%_ASM_CX
  50. jae bad_put_user
  51. ASM_STAC
  52. 2: movw %ax,(%_ASM_CX)
  53. xor %eax,%eax
  54. EXIT
  55. ENDPROC(__put_user_2)
  56. ENTRY(__put_user_4)
  57. ENTER
  58. mov TI_addr_limit(%_ASM_BX),%_ASM_BX
  59. sub $3,%_ASM_BX
  60. cmp %_ASM_BX,%_ASM_CX
  61. jae bad_put_user
  62. ASM_STAC
  63. 3: movl %eax,(%_ASM_CX)
  64. xor %eax,%eax
  65. EXIT
  66. ENDPROC(__put_user_4)
  67. ENTRY(__put_user_8)
  68. ENTER
  69. mov TI_addr_limit(%_ASM_BX),%_ASM_BX
  70. sub $7,%_ASM_BX
  71. cmp %_ASM_BX,%_ASM_CX
  72. jae bad_put_user
  73. ASM_STAC
  74. 4: mov %_ASM_AX,(%_ASM_CX)
  75. #ifdef CONFIG_X86_32
  76. 5: movl %edx,4(%_ASM_CX)
  77. #endif
  78. xor %eax,%eax
  79. EXIT
  80. ENDPROC(__put_user_8)
  81. bad_put_user:
  82. CFI_STARTPROC
  83. movl $-EFAULT,%eax
  84. EXIT
  85. END(bad_put_user)
  86. _ASM_EXTABLE(1b,bad_put_user)
  87. _ASM_EXTABLE(2b,bad_put_user)
  88. _ASM_EXTABLE(3b,bad_put_user)
  89. _ASM_EXTABLE(4b,bad_put_user)
  90. #ifdef CONFIG_X86_32
  91. _ASM_EXTABLE(5b,bad_put_user)
  92. #endif