| 1 |
/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ |
| 2 |
|
| 3 |
.section ".text.rt.longjmp","ax" |
| 4 |
.global rt.longjmp |
| 5 |
.type rt.longjmp,@function |
| 6 |
rt.longjmp: |
| 7 |
/* no endbr64 here to avoid exploitation - this function cannot be the |
| 8 |
* result of an indirect branch. |
| 9 |
*/ |
| 10 |
xor %eax,%eax |
| 11 |
cmp $1,%esi /* CF = val ? 0 : 1 */ |
| 12 |
adc %esi,%eax /* eax = val + !val */ |
| 13 |
mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */ |
| 14 |
mov 8(%rdi),%rbp |
| 15 |
mov 16(%rdi),%r12 |
| 16 |
mov 24(%rdi),%r13 |
| 17 |
mov 32(%rdi),%r14 |
| 18 |
mov 40(%rdi),%r15 |
| 19 |
mov 48(%rdi),%rsp |
| 20 |
/* IBT: we cannot directly jump to the saved adress since this might be |
| 21 |
* in the middle of the function where we are not going to have an |
| 22 |
* endbr64. instead, we push the address to the stack and return to it |
| 23 |
* in order to avoid an indirect branch. |
| 24 |
*/ |
| 25 |
push 56(%rdi) /* goto saved address without altering rsp */ |
| 26 |
ret |