[RFC PATCH v3 2/5] x86: Support for Static Trampolines
Madhavan T. Venkataraman
madvenka@linux.microsoft.com
Fri Jan 29 03:24:16 GMT 2021
On 1/28/21 8:48 PM, DJ Delorie wrote:
>
> Sure, you still need to use the __CET_ENDBR macro in your trampoline.
> And it might be tricky to compute the number of iterations per page (I
> understand about the packing ;)
>
> I'm just saying you don't need both CET and non-CET trampolines.
>
> A CET-enabled trampoline should work in a CET-disabled system.
>
You are right. I only needed two versions because of the nops for aligment.
However, I think I can address your concern. Now that we are able to
define ENDBR_PRESENT, we can define the trampoline size in the header like
this
#ifdef ENDBR_PRESENT
#define UNIX64_TRAMP_SIZE 40
#else
#define UNIX64_TRAMP_SIZE 32
#endif
Then, in the trampoline code table:
C(trampoline_code_table):
.rept UNIX64_TRAMP_MAP_SIZE / UNIX64_TRAMP_SIZE
_CET_ENDBR
subq $16, %rsp /* Make space on the stack */
movq %r10, (%rsp) /* Save %r10 on stack */
movq 4077(%rip), %r10 /* Copy data into %r10 */
movq %r10, 8(%rsp) /* Save data on stack */
movq 4073(%rip), %r10 /* Copy code into %r10 */
jmp *%r10 /* Jump to code */
nop
nop
#ifdef ENDBR_PRESENT
nop
nop
nop
nop
#endif
.endr
ENDF(C(trampoline_code_table))
This is cool. We only need one table.
Thanks.
Madhavan
More information about the Libffi-discuss
mailing list