putuser.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * __put_user functions.
  4. *
  5. * (C) Copyright 2005 Linus Torvalds
  6. * (C) Copyright 2005 Andi Kleen
  7. * (C) Copyright 2008 Glauber Costa
  8. *
  9. * These functions have a non-standard call interface
  10. * to make them more efficient, especially as they
  11. * return an error value in addition to the "real"
  12. * return value.
  13. */
  14. #include <linux/linkage.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/errno.h>
  17. #include <asm/asm.h>
  18. #include <asm/smap.h>
  19. #include <asm/export.h>
  20. /*
  21. * __put_user_X
  22. *
  23. * Inputs: %eax[:%edx] contains the data
  24. * %ecx contains the address
  25. *
  26. * Outputs: %eax is error code (0 or -EFAULT)
  27. *
  28. * These functions should not modify any other registers,
  29. * as they get called from within inline assembly.
  30. */
  31. #define ENTER mov PER_CPU_VAR(current_task), %_ASM_BX
  32. #define EXIT ASM_CLAC ; \
  33. ret
  34. .text
  35. ENTRY(__put_user_1)
  36. ENTER
  37. cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX
  38. jae bad_put_user
  39. ASM_STAC
  40. 1: movb %al,(%_ASM_CX)
  41. xor %eax,%eax
  42. EXIT
  43. ENDPROC(__put_user_1)
  44. EXPORT_SYMBOL(__put_user_1)
  45. ENTRY(__put_user_2)
  46. ENTER
  47. mov TASK_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. EXPORT_SYMBOL(__put_user_2)
  57. ENTRY(__put_user_4)
  58. ENTER
  59. mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
  60. sub $3,%_ASM_BX
  61. cmp %_ASM_BX,%_ASM_CX
  62. jae bad_put_user
  63. ASM_STAC
  64. 3: movl %eax,(%_ASM_CX)
  65. xor %eax,%eax
  66. EXIT
  67. ENDPROC(__put_user_4)
  68. EXPORT_SYMBOL(__put_user_4)
  69. ENTRY(__put_user_8)
  70. ENTER
  71. mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
  72. sub $7,%_ASM_BX
  73. cmp %_ASM_BX,%_ASM_CX
  74. jae bad_put_user
  75. ASM_STAC
  76. 4: mov %_ASM_AX,(%_ASM_CX)
  77. #ifdef CONFIG_X86_32
  78. 5: movl %edx,4(%_ASM_CX)
  79. #endif
  80. xor %eax,%eax
  81. EXIT
  82. ENDPROC(__put_user_8)
  83. EXPORT_SYMBOL(__put_user_8)
  84. bad_put_user:
  85. movl $-EFAULT,%eax
  86. EXIT
  87. END(bad_put_user)
  88. _ASM_EXTABLE(1b,bad_put_user)
  89. _ASM_EXTABLE(2b,bad_put_user)
  90. _ASM_EXTABLE(3b,bad_put_user)
  91. _ASM_EXTABLE(4b,bad_put_user)
  92. #ifdef CONFIG_X86_32
  93. _ASM_EXTABLE(5b,bad_put_user)
  94. #endif