putuser.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <asm/export.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 mov PER_CPU_VAR(current_task), %_ASM_BX
  31. #define EXIT ASM_CLAC ; \
  32. ret
  33. .text
  34. ENTRY(__put_user_1)
  35. ENTER
  36. cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX
  37. jae bad_put_user
  38. ASM_STAC
  39. 1: movb %al,(%_ASM_CX)
  40. xor %eax,%eax
  41. EXIT
  42. ENDPROC(__put_user_1)
  43. EXPORT_SYMBOL(__put_user_1)
  44. ENTRY(__put_user_2)
  45. ENTER
  46. mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
  47. sub $1,%_ASM_BX
  48. cmp %_ASM_BX,%_ASM_CX
  49. jae bad_put_user
  50. ASM_STAC
  51. 2: movw %ax,(%_ASM_CX)
  52. xor %eax,%eax
  53. EXIT
  54. ENDPROC(__put_user_2)
  55. EXPORT_SYMBOL(__put_user_2)
  56. ENTRY(__put_user_4)
  57. ENTER
  58. mov TASK_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. EXPORT_SYMBOL(__put_user_4)
  68. ENTRY(__put_user_8)
  69. ENTER
  70. mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
  71. sub $7,%_ASM_BX
  72. cmp %_ASM_BX,%_ASM_CX
  73. jae bad_put_user
  74. ASM_STAC
  75. 4: mov %_ASM_AX,(%_ASM_CX)
  76. #ifdef CONFIG_X86_32
  77. 5: movl %edx,4(%_ASM_CX)
  78. #endif
  79. xor %eax,%eax
  80. EXIT
  81. ENDPROC(__put_user_8)
  82. EXPORT_SYMBOL(__put_user_8)
  83. bad_put_user:
  84. movl $-EFAULT,%eax
  85. EXIT
  86. END(bad_put_user)
  87. _ASM_EXTABLE(1b,bad_put_user)
  88. _ASM_EXTABLE(2b,bad_put_user)
  89. _ASM_EXTABLE(3b,bad_put_user)
  90. _ASM_EXTABLE(4b,bad_put_user)
  91. #ifdef CONFIG_X86_32
  92. _ASM_EXTABLE(5b,bad_put_user)
  93. #endif