2018-01-30 03:41:02 +00:00
|
|
|
/*
|
2020-03-29 14:27:40 +00:00
|
|
|
* Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
|
2018-01-30 03:41:02 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
2020-03-29 14:27:40 +00:00
|
|
|
#include "defs.h"
|
|
|
|
|
2020-12-06 09:02:25 +00:00
|
|
|
ALIAS(getcontext, libucontext_getcontext)
|
2021-01-08 09:30:50 +00:00
|
|
|
ALIAS(__getcontext, libucontext_getcontext)
|
2020-03-29 14:27:40 +00:00
|
|
|
|
2020-12-06 09:02:25 +00:00
|
|
|
FUNC(libucontext_getcontext)
|
2018-01-30 03:41:02 +00:00
|
|
|
/* copy all of the current registers into the ucontext structure */
|
2020-03-29 14:27:40 +00:00
|
|
|
movq %r8, REG_OFFSET(REG_R8)(%rdi)
|
|
|
|
movq %r9, REG_OFFSET(REG_R9)(%rdi)
|
|
|
|
movq %r10, REG_OFFSET(REG_R10)(%rdi)
|
|
|
|
movq %r11, REG_OFFSET(REG_R11)(%rdi)
|
|
|
|
movq %r12, REG_OFFSET(REG_R12)(%rdi)
|
|
|
|
movq %r13, REG_OFFSET(REG_R13)(%rdi)
|
|
|
|
movq %r14, REG_OFFSET(REG_R14)(%rdi)
|
|
|
|
movq %r15, REG_OFFSET(REG_R15)(%rdi)
|
|
|
|
movq %rdi, REG_OFFSET(REG_RDI)(%rdi)
|
|
|
|
movq %rsi, REG_OFFSET(REG_RSI)(%rdi)
|
|
|
|
movq %rbp, REG_OFFSET(REG_RBP)(%rdi)
|
|
|
|
movq %rbx, REG_OFFSET(REG_RBX)(%rdi)
|
|
|
|
movq %rdx, REG_OFFSET(REG_RDX)(%rdi)
|
|
|
|
movq %rax, REG_OFFSET(REG_RAX)(%rdi)
|
|
|
|
movq %rcx, REG_OFFSET(REG_RCX)(%rdi)
|
2018-01-30 03:41:02 +00:00
|
|
|
|
|
|
|
/* the first argument on the stack is the jump target (%rip), so we store it in the RIP
|
|
|
|
register in the ucontext structure. */
|
|
|
|
movq (%rsp), %rcx
|
2020-03-29 14:27:40 +00:00
|
|
|
movq %rcx, REG_OFFSET(REG_RIP)(%rdi)
|
2018-01-29 21:50:49 +00:00
|
|
|
|
2018-01-30 03:41:02 +00:00
|
|
|
/* finally take the stack pointer address (%rsp) offsetting by 8 to skip over the jump
|
|
|
|
target. */
|
|
|
|
leaq 8(%rsp), %rcx
|
2020-03-29 14:27:40 +00:00
|
|
|
movq %rcx, REG_OFFSET(REG_RSP)(%rdi)
|
2018-01-30 03:41:02 +00:00
|
|
|
|
|
|
|
/* we're all done here, return 0 */
|
|
|
|
xorl %eax, %eax
|
2018-01-29 21:50:49 +00:00
|
|
|
ret
|
2020-12-06 09:02:25 +00:00
|
|
|
END(libucontext_getcontext)
|