putuser.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * __put_user functions.
  3. *
  4. * (C) Copyright 1998 Linus Torvalds
  5. * (C) Copyright 2005 Andi Kleen
  6. *
  7. * These functions have a non-standard call interface
  8. * to make them more efficient, especially as they
  9. * return an error value in addition to the "real"
  10. * return value.
  11. */
  12. /*
  13. * __put_user_X
  14. *
  15. * Inputs: %rcx contains the address
  16. * %rdx contains new value
  17. *
  18. * Outputs: %rax is error code (0 or -EFAULT)
  19. *
  20. * %r8 is destroyed.
  21. *
  22. * These functions should not modify any other registers,
  23. * as they get called from within inline assembly.
  24. */
  25. #include <linux/linkage.h>
  26. #include <asm/page.h>
  27. #include <asm/errno.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/thread_info.h>
  30. .text
  31. .p2align 4
  32. .globl __put_user_1
  33. __put_user_1:
  34. GET_THREAD_INFO(%r8)
  35. cmpq threadinfo_addr_limit(%r8),%rcx
  36. jae bad_put_user
  37. 1: movb %dl,(%rcx)
  38. xorl %eax,%eax
  39. ret
  40. .p2align 4
  41. .globl __put_user_2
  42. __put_user_2:
  43. GET_THREAD_INFO(%r8)
  44. addq $1,%rcx
  45. jc 20f
  46. cmpq threadinfo_addr_limit(%r8),%rcx
  47. jae 20f
  48. decq %rcx
  49. 2: movw %dx,(%rcx)
  50. xorl %eax,%eax
  51. ret
  52. 20: decq %rcx
  53. jmp bad_put_user
  54. .p2align 4
  55. .globl __put_user_4
  56. __put_user_4:
  57. GET_THREAD_INFO(%r8)
  58. addq $3,%rcx
  59. jc 30f
  60. cmpq threadinfo_addr_limit(%r8),%rcx
  61. jae 30f
  62. subq $3,%rcx
  63. 3: movl %edx,(%rcx)
  64. xorl %eax,%eax
  65. ret
  66. 30: subq $3,%rcx
  67. jmp bad_put_user
  68. .p2align 4
  69. .globl __put_user_8
  70. __put_user_8:
  71. GET_THREAD_INFO(%r8)
  72. addq $7,%rcx
  73. jc 40f
  74. cmpq threadinfo_addr_limit(%r8),%rcx
  75. jae 40f
  76. subq $7,%rcx
  77. 4: movq %rdx,(%rcx)
  78. xorl %eax,%eax
  79. ret
  80. 40: subq $7,%rcx
  81. jmp bad_put_user
  82. bad_put_user:
  83. movq $(-EFAULT),%rax
  84. ret
  85. .section __ex_table,"a"
  86. .quad 1b,bad_put_user
  87. .quad 2b,bad_put_user
  88. .quad 3b,bad_put_user
  89. .quad 4b,bad_put_user
  90. .previous