Blame backends/i386_initreg.c

Packit Service 97d2fb
/* Fetch live process registers from TID.
Packit Service 97d2fb
   Copyright (C) 2013 Red Hat, Inc.
Packit Service 97d2fb
   This file is part of elfutils.
Packit Service 97d2fb
Packit Service 97d2fb
   This file is free software; you can redistribute it and/or modify
Packit Service 97d2fb
   it under the terms of either
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU Lesser General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 3 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 2 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or both in parallel, as here.
Packit Service 97d2fb
Packit Service 97d2fb
   elfutils is distributed in the hope that it will be useful, but
Packit Service 97d2fb
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 97d2fb
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 97d2fb
   General Public License for more details.
Packit Service 97d2fb
Packit Service 97d2fb
   You should have received copies of the GNU General Public License and
Packit Service 97d2fb
   the GNU Lesser General Public License along with this program.  If
Packit Service 97d2fb
   not, see <http://www.gnu.org/licenses/>.  */
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef HAVE_CONFIG_H
Packit Service 97d2fb
# include <config.h>
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#if (defined __i386__ || defined __x86_64__) && defined(__linux__)
Packit Service 97d2fb
# include <sys/types.h>
Packit Service 97d2fb
# include <sys/user.h>
Packit Service 97d2fb
# include <sys/ptrace.h>
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#define BACKEND i386_
Packit Service 97d2fb
#include "libebl_CPU.h"
Packit Service 97d2fb
Packit Service 97d2fb
bool
Packit Service 97d2fb
i386_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
Packit Service 97d2fb
			  ebl_tid_registers_t *setfunc __attribute__ ((unused)),
Packit Service 97d2fb
				void *arg __attribute__ ((unused)))
Packit Service 97d2fb
{
Packit Service 97d2fb
#if (!defined __i386__ && !defined __x86_64__) || !defined(__linux__)
Packit Service 97d2fb
  return false;
Packit Service 97d2fb
#else /* __i386__ || __x86_64__ */
Packit Service 97d2fb
  struct user_regs_struct user_regs;
Packit Service 97d2fb
  if (ptrace (PTRACE_GETREGS, tid, NULL, &user_regs) != 0)
Packit Service 97d2fb
    return false;
Packit Service 97d2fb
  Dwarf_Word dwarf_regs[9];
Packit Service 97d2fb
# if defined __i386__
Packit Service 97d2fb
  dwarf_regs[0] = user_regs.eax;
Packit Service 97d2fb
  dwarf_regs[1] = user_regs.ecx;
Packit Service 97d2fb
  dwarf_regs[2] = user_regs.edx;
Packit Service 97d2fb
  dwarf_regs[3] = user_regs.ebx;
Packit Service 97d2fb
  dwarf_regs[4] = user_regs.esp;
Packit Service 97d2fb
  dwarf_regs[5] = user_regs.ebp;
Packit Service 97d2fb
  dwarf_regs[6] = user_regs.esi;
Packit Service 97d2fb
  dwarf_regs[7] = user_regs.edi;
Packit Service 97d2fb
  dwarf_regs[8] = user_regs.eip;
Packit Service 97d2fb
# elif defined __x86_64__
Packit Service 97d2fb
  dwarf_regs[0] = user_regs.rax;
Packit Service 97d2fb
  dwarf_regs[1] = user_regs.rcx;
Packit Service 97d2fb
  dwarf_regs[2] = user_regs.rdx;
Packit Service 97d2fb
  dwarf_regs[3] = user_regs.rbx;
Packit Service 97d2fb
  dwarf_regs[4] = user_regs.rsp;
Packit Service 97d2fb
  dwarf_regs[5] = user_regs.rbp;
Packit Service 97d2fb
  dwarf_regs[6] = user_regs.rsi;
Packit Service 97d2fb
  dwarf_regs[7] = user_regs.rdi;
Packit Service 97d2fb
  dwarf_regs[8] = user_regs.rip;
Packit Service 97d2fb
# else /* (__i386__ || __x86_64__) && (!__i386__ && !__x86_64__) */
Packit Service 97d2fb
#  error "source file error, it cannot happen"
Packit Service 97d2fb
# endif /* (__i386__ || __x86_64__) && (!__i386__ && !__x86_64__) */
Packit Service 97d2fb
  return setfunc (0, 9, dwarf_regs, arg);
Packit Service 97d2fb
#endif /* __i386__ || __x86_64__ */
Packit Service 97d2fb
}