| 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 |
|
| 13 |
%define RSB_STUFF_ENTRIES 0x20 |
| 14 |
|
| 15 |
; |
| 16 |
; parameters: |
| 17 |
; @param 1: register to use as counter (e.g. IA32:eax, X64:rax) |
| 18 |
; @param 2: stack pointer to restore (IA32:esp, X64:rsp) |
| 19 |
; @param 3: the size of a stack frame (IA32:4, X64:8) |
| 20 |
; |
| 21 |
%macro StuffRsb 3 |
| 22 |
mov %1, RSB_STUFF_ENTRIES / 2 |
| 23 |
%%Unroll1: |
| 24 |
call %%Unroll2 |
| 25 |
%%SpecTrap1: |
| 26 |
pause |
| 27 |
lfence |
| 28 |
jmp %%SpecTrap1 |
| 29 |
%%Unroll2: |
| 30 |
call %%StuffLoop |
| 31 |
%%SpecTrap2: |
| 32 |
pause |
| 33 |
lfence |
| 34 |
jmp %%SpecTrap2 |
| 35 |
%%StuffLoop: |
| 36 |
dec %1 |
| 37 |
jnz %%Unroll1 |
| 38 |
add %2, RSB_STUFF_ENTRIES * %3 ; Restore the stack pointer |
| 39 |
%endmacro |
| 40 |
|
| 41 |
; |
| 42 |
; RSB stuffing macros for IA32 and X64 |
| 43 |
; |
| 44 |
%macro StuffRsb32 0 |
| 45 |
StuffRsb eax, esp, 4 |
| 46 |
%endmacro |
| 47 |
|
| 48 |
%macro StuffRsb64 0 |
| 49 |
StuffRsb rax, rsp, 8 |
| 50 |
%endmacro |