Line data Source code
1 : /* Fetch live process registers from TID.
2 : Copyright (C) 2014 Red Hat, Inc.
3 : This file is part of elfutils.
4 :
5 : This file is free software; you can redistribute it and/or modify
6 : it under the terms of either
7 :
8 : * the GNU Lesser General Public License as published by the Free
9 : Software Foundation; either version 3 of the License, or (at
10 : your option) any later version
11 :
12 : or
13 :
14 : * the GNU General Public License as published by the Free
15 : Software Foundation; either version 2 of the License, or (at
16 : your option) any later version
17 :
18 : or both in parallel, as here.
19 :
20 : elfutils is distributed in the hope that it will be useful, but
21 : WITHOUT ANY WARRANTY; without even the implied warranty of
22 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 : General Public License for more details.
24 :
25 : You should have received copies of the GNU General Public License and
26 : the GNU Lesser General Public License along with this program. If
27 : not, see <http://www.gnu.org/licenses/>. */
28 :
29 : #ifdef HAVE_CONFIG_H
30 : # include <config.h>
31 : #endif
32 :
33 : #ifdef __linux__
34 : #if defined __arm__
35 : # include <sys/types.h>
36 : # include <sys/user.h>
37 : # include <sys/ptrace.h>
38 : #endif
39 :
40 : #ifdef __aarch64__
41 : # include <linux/uio.h>
42 : # include <sys/user.h>
43 : # include <sys/ptrace.h>
44 : /* Deal with old glibc defining user_pt_regs instead of user_regs_struct. */
45 : # ifndef HAVE_SYS_USER_REGS
46 : # define user_regs_struct user_pt_regs
47 : # endif
48 : #endif
49 : #endif
50 :
51 : #define BACKEND arm_
52 : #include "libebl_CPU.h"
53 :
54 : bool
55 0 : arm_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
56 : ebl_tid_registers_t *setfunc __attribute__ ((unused)),
57 : void *arg __attribute__ ((unused)))
58 : {
59 : #if !defined(__linux__) || (!defined __arm__ && !defined __aarch64__)
60 0 : return false;
61 : #else /* __arm__ || __aarch64__ */
62 : #if defined __arm__
63 : struct user_regs user_regs;
64 : if (ptrace (PTRACE_GETREGS, tid, NULL, &user_regs) != 0)
65 : return false;
66 :
67 : Dwarf_Word dwarf_regs[16];
68 : /* R0..R12 SP LR PC */
69 : for (int i = 0; i < 16; i++)
70 : dwarf_regs[i] = user_regs.uregs[i];
71 :
72 : return setfunc (0, 16, dwarf_regs, arg);
73 : #elif defined __aarch64__
74 : /* Compat mode: arm compatible code running on aarch64 */
75 : int i;
76 : struct user_regs_struct gregs;
77 : struct iovec iovec;
78 : iovec.iov_base = &gregs;
79 : iovec.iov_len = sizeof (gregs);
80 : if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec) != 0)
81 : return false;
82 :
83 : Dwarf_Word dwarf_regs[16];
84 : /* R0..R12 SP LR PC, encoded as 32 bit quantities */
85 : uint32_t *u32_ptr = (uint32_t *) &gregs.regs[0];
86 : for (i = 0; i < 16; i++)
87 : dwarf_regs[i] = u32_ptr[i];
88 :
89 : return setfunc (0, 16, dwarf_regs, arg);
90 : #else
91 : # error "source file error, it cannot happen"
92 : #endif
93 : #endif
94 : }
|