Line data Source code
1 : /* Fetch live process registers from TID.
2 : Copyright (C) 2026 Matt Turner
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 :
30 : #ifdef HAVE_CONFIG_H
31 : # include <config.h>
32 : #endif
33 :
34 : #if defined __alpha__ && defined __linux__
35 : # include <errno.h>
36 : # include <stdint.h>
37 : # include <sys/ptrace.h>
38 : #endif
39 :
40 : #define BACKEND alpha_
41 : #include "libebl_CPU.h"
42 :
43 : bool
44 0 : alpha_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
45 : ebl_tid_registers_t *setfunc __attribute__ ((unused)),
46 : void *arg __attribute__ ((unused)))
47 : {
48 : #if !defined __alpha__ || !defined __linux__
49 0 : return false;
50 : #else /* __alpha__ */
51 : /* PTRACE_PEEKUSER takes a register number: 0-31 for the integer
52 : registers, 32-62 for $f0-$f30, 63 for the FPCR and 64 for the PC.
53 : The value is the return value, so check errno rather than for -1. */
54 : Dwarf_Word regs[65];
55 : for (int i = 0; i < 65; i++)
56 : {
57 : /* $31 and $f31 always read as zero. */
58 : if (i == 31 || i == 63)
59 : {
60 : regs[i] = 0;
61 : continue;
62 : }
63 : errno = 0;
64 : regs[i] = ptrace (PTRACE_PEEKUSER, tid, (void *) (uintptr_t) i, NULL);
65 : if (errno != 0)
66 : return false;
67 : }
68 :
69 : /* $0-$31 and $f0-$f31, then the PC. */
70 : return setfunc (0, 64, regs, arg) && setfunc (-1, 1, ®s[64], arg);
71 : #endif /* __alpha__ */
72 : }
|