Thunks.asm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ;-------------------------------------------------------------------------------------------------------
  2. ; Copyright (C) Microsoft. All rights reserved.
  3. ; Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. ;-------------------------------------------------------------------------------------------------------
  5. include ksamd64.inc
  6. _TEXT SEGMENT
  7. ifdef _CONTROL_FLOW_GUARD
  8. extrn __guard_check_icall_fptr:QWORD
  9. endif
  10. ;;============================================================================================================
  11. ;; NativeCodeGenerator::CheckCodeGenThunk
  12. ;;============================================================================================================
  13. extrn ?CheckCodeGen@NativeCodeGenerator@@SAP6APEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZPEAVScriptFunction@3@@Z : PROC
  14. align 16
  15. ?CheckCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ PROC FRAME
  16. ;; save volatile registers
  17. mov qword ptr [rsp + 8h], rcx
  18. mov qword ptr [rsp + 10h], rdx
  19. mov qword ptr [rsp + 18h], r8
  20. mov qword ptr [rsp + 20h], r9
  21. push rbp
  22. .pushreg rbp
  23. lea rbp, [rsp]
  24. .setframe rbp, 0
  25. .endprolog
  26. ifdef _CONTROL_FLOW_GUARD
  27. sub rsp, 30h ;allocate stack space for the callee params(min 4 slots is mandate + 1 for saving call target + 1 for alignment)
  28. call ?CheckCodeGen@NativeCodeGenerator@@SAP6APEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZPEAVScriptFunction@3@@Z
  29. mov [rsp + 28h], rax ;save rax (call target) [6th slot will have call target and 5th slot is left untouched]
  30. mov rcx, rax ; __guard_check_icall_fptr requires the call target in rcx.
  31. call [__guard_check_icall_fptr] ; verify that the call target is valid
  32. add rsp, 28h ;de-allocate stack space for the callee params(min 4 slots is mandate + 1 for alignment )
  33. pop rax ;restore call target
  34. else
  35. sub rsp, 20h ;allocate stack space for the callee params(min 4 slots is mandate)
  36. call ?CheckCodeGen@NativeCodeGenerator@@SAP6APEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZPEAVScriptFunction@3@@Z
  37. add rsp, 20h ;de-allocate stack space for the callee params(min 4 slots is mandate)
  38. endif
  39. ;EPILOGUE starts here
  40. lea rsp, [rbp]
  41. pop rbp
  42. ;; restore volatile registers
  43. mov rcx, qword ptr [rsp + 8h]
  44. mov rdx, qword ptr [rsp + 10h]
  45. mov r8, qword ptr [rsp + 18h]
  46. mov r9, qword ptr [rsp + 20h]
  47. rex_jmp_reg rax
  48. ?CheckCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ ENDP
  49. ;;============================================================================================================
  50. ;; NativeCodeGenerator::CheckAsmJsCodeGenThunk
  51. ;;============================================================================================================
  52. extrn ?CheckAsmJsCodeGen@NativeCodeGenerator@@SAPEAXPEAVScriptFunction@Js@@@Z : PROC
  53. align 16
  54. ?CheckAsmJsCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ PROC FRAME
  55. ;; save volatile registers
  56. mov qword ptr [rsp + 8h], rcx
  57. mov qword ptr [rsp + 10h], rdx
  58. mov qword ptr [rsp + 18h], r8
  59. mov qword ptr [rsp + 20h], r9
  60. push rbp
  61. .pushreg rbp
  62. lea rbp, [rsp]
  63. .setframe rbp, 0
  64. .endprolog
  65. sub rsp, 60h
  66. ; spill potential floating point arguments to stack
  67. movups xmmword ptr [rsp + 30h], xmm1
  68. movups xmmword ptr [rsp + 40h], xmm2
  69. movups xmmword ptr [rsp + 50h], xmm3
  70. ifdef _CONTROL_FLOW_GUARD
  71. call ?CheckAsmJsCodeGen@NativeCodeGenerator@@SAPEAXPEAVScriptFunction@Js@@@Z
  72. mov rcx, rax ; __guard_check_icall_fptr requires the call target in rcx.
  73. call [__guard_check_icall_fptr] ; verify that the call target is valid
  74. mov rax, rcx ; CFG is guaranteed not to mess up rcx
  75. else
  76. call ?CheckAsmJsCodeGen@NativeCodeGenerator@@SAPEAXPEAVScriptFunction@Js@@@Z
  77. endif
  78. ;EPILOGUE starts here
  79. movups xmm1, xmmword ptr [rsp + 30h]
  80. movups xmm2, xmmword ptr [rsp + 40h]
  81. movups xmm3, xmmword ptr [rsp + 50h]
  82. lea rsp, [rbp]
  83. pop rbp
  84. ;; restore volatile registers
  85. mov rcx, qword ptr [rsp + 8h]
  86. mov rdx, qword ptr [rsp + 10h]
  87. mov r8, qword ptr [rsp + 18h]
  88. mov r9, qword ptr [rsp + 20h]
  89. rex_jmp_reg rax
  90. ?CheckAsmJsCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ ENDP
  91. ;;============================================================================================================
  92. _TEXT ENDS
  93. end