10b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* Fetch live process registers from TID. 20b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil Copyright (C) 2013 Red Hat, Inc. 30b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil This file is part of elfutils. 40b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 50b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil This file is free software; you can redistribute it and/or modify 60b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil it under the terms of either 70b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 80b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil * the GNU Lesser General Public License as published by the Free 90b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil Software Foundation; either version 3 of the License, or (at 100b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil your option) any later version 110b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 120b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil or 130b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 140b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil * the GNU General Public License as published by the Free 150b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil Software Foundation; either version 2 of the License, or (at 160b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil your option) any later version 170b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 180b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil or both in parallel, as here. 190b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 200b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil elfutils is distributed in the hope that it will be useful, but 210b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil WITHOUT ANY WARRANTY; without even the implied warranty of 220b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 230b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil General Public License for more details. 240b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 250b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil You should have received copies of the GNU General Public License and 260b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil the GNU Lesser General Public License along with this program. If 270b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil not, see <http://www.gnu.org/licenses/>. */ 280b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 290b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#ifdef HAVE_CONFIG_H 300b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# include <config.h> 310b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#endif 320b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 3365251494ae6eae66bfdf9134189fd11b1ee8e9b5Pino Toscano#if (defined __i386__ || defined __x86_64__) && defined(__linux__) 340b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# include <sys/types.h> 350b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# include <sys/user.h> 360b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# include <sys/ptrace.h> 370b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#endif 380b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 390b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#define BACKEND i386_ 400b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#include "libebl_CPU.h" 410b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil 420b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilbool 430b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvili386_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), 440b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil ebl_tid_registers_t *setfunc __attribute__ ((unused)), 450b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil void *arg __attribute__ ((unused))) 460b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil{ 4702cefdaa6429e620d6457fdb3ad9934f194c5a93Kurt Roeckx#if (!defined __i386__ && !defined __x86_64__) || !defined(__linux__) 480b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil return false; 490b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#else /* __i386__ || __x86_64__ */ 500b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil struct user_regs_struct user_regs; 510b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil if (ptrace (PTRACE_GETREGS, tid, NULL, &user_regs) != 0) 520b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil return false; 530b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil Dwarf_Word dwarf_regs[9]; 540b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# if defined __i386__ 550b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[0] = user_regs.eax; 560b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[1] = user_regs.ecx; 570b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[2] = user_regs.edx; 580b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[3] = user_regs.ebx; 590b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[4] = user_regs.esp; 600b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[5] = user_regs.ebp; 610b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[6] = user_regs.esi; 620b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[7] = user_regs.edi; 630b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[8] = user_regs.eip; 640b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# elif defined __x86_64__ 650b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[0] = user_regs.rax; 660b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[1] = user_regs.rcx; 670b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[2] = user_regs.rdx; 680b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[3] = user_regs.rbx; 690b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[4] = user_regs.rsp; 700b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[5] = user_regs.rbp; 710b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[6] = user_regs.rsi; 720b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[7] = user_regs.rdi; 730b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil dwarf_regs[8] = user_regs.rip; 740b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# else /* (__i386__ || __x86_64__) && (!__i386__ && !__x86_64__) */ 750b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# error "source file error, it cannot happen" 760b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil# endif /* (__i386__ || __x86_64__) && (!__i386__ && !__x86_64__) */ 770b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil return setfunc (0, 9, dwarf_regs, arg); 780b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil#endif /* __i386__ || __x86_64__ */ 790b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil} 80