StuffRsbNasm.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ;------------------------------------------------------------------------------
  2. ;
  3. ; Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
  4. ; SPDX-License-Identifier: BSD-2-Clause-Patent
  5. ;
  6. ; Abstract:
  7. ;
  8. ; This file provides macro definitions for stuffing the Return Stack Buffer (RSB)
  9. ; for NASM files.
  10. ;
  11. ;------------------------------------------------------------------------------
  12. %define RSB_STUFF_ENTRIES 0x20
  13. ;
  14. ; parameters:
  15. ; @param 1: register to use as counter (e.g. IA32:eax, X64:rax)
  16. ; @param 2: stack pointer to restore (IA32:esp, X64:rsp)
  17. ; @param 3: the size of a stack frame (IA32:4, X64:8)
  18. ;
  19. %macro StuffRsb 3
  20. mov %1, RSB_STUFF_ENTRIES / 2
  21. %%Unroll1:
  22. call %%Unroll2
  23. %%SpecTrap1:
  24. pause
  25. lfence
  26. jmp %%SpecTrap1
  27. %%Unroll2:
  28. call %%StuffLoop
  29. %%SpecTrap2:
  30. pause
  31. lfence
  32. jmp %%SpecTrap2
  33. %%StuffLoop:
  34. dec %1
  35. jnz %%Unroll1
  36. add %2, RSB_STUFF_ENTRIES * %3 ; Restore the stack pointer
  37. %endmacro
  38. ;
  39. ; RSB stuffing macros for IA32 and X64
  40. ;
  41. %macro StuffRsb32 0
  42. StuffRsb eax, esp, 4
  43. %endmacro
  44. %macro StuffRsb64 0
  45. StuffRsb rax, rsp, 8
  46. %endmacro