setjmp.s (669B)
1 /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ 2 3 .section ".text.rt.setjmp","ax" 4 .global rt.setjmp 5 .type rt.setjmp,@function 6 rt.setjmp: 7 /* no endbr64 here to avoid exploitation - this function cannot be the 8 * result of an indirect branch. 9 */ 10 mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */ 11 mov %rbp,8(%rdi) 12 mov %r12,16(%rdi) 13 mov %r13,24(%rdi) 14 mov %r14,32(%rdi) 15 mov %r15,40(%rdi) 16 lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */ 17 mov %rdx,48(%rdi) 18 mov (%rsp),%rdx /* save return addr ptr for new rip */ 19 mov %rdx,56(%rdi) 20 xor %eax,%eax /* always return 0 */ 21 ret