putuser.S 1.8 KB

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