1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org>
5
6 This file is part of libunwind.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
26
27 #include "_UPT_internal.h"
28
29 #if HAVE_DECL_PTRACE_POKEUSER || HAVE_TTRACE
30 int
_UPT_access_fpreg(unw_addr_space_t as,unw_regnum_t reg,unw_fpreg_t * val,int write,void * arg)31 _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
32 int write, void *arg)
33 {
34 unw_word_t *wp = (unw_word_t *) val;
35 struct UPT_info *ui = arg;
36 pid_t pid = ui->pid;
37 int i;
38
39 if ((unsigned) reg >= ARRAY_SIZE (_UPT_reg_offset))
40 return -UNW_EBADREG;
41
42 errno = 0;
43 if (write)
44 for (i = 0; i < (int) (sizeof (*val) / sizeof (wp[i])); ++i)
45 {
46 #ifdef HAVE_TTRACE
47 # warning No support for ttrace() yet.
48 #else
49 /* ANDROID support update. */
50 ptrace (PTRACE_POKEUSER, pid, (void*) (_UPT_reg_offset[reg] + i * sizeof(wp[i])),
51 (void*) wp[i]);
52 /* End of ANDROID update. */
53 #endif
54 if (errno)
55 return -UNW_EBADREG;
56 }
57 else
58 for (i = 0; i < (int) (sizeof (*val) / sizeof (wp[i])); ++i)
59 {
60 #ifdef HAVE_TTRACE
61 # warning No support for ttrace() yet.
62 #else
63 /* ANDROID support update. */
64 wp[i] = ptrace (PTRACE_PEEKUSER, pid,
65 (void*) (_UPT_reg_offset[reg] + i * sizeof(wp[i])), 0);
66 /* End of ANDROID update. */
67 #endif
68 if (errno)
69 return -UNW_EBADREG;
70 }
71 return 0;
72 }
73 #elif HAVE_DECL_PT_GETFPREGS
74 int
_UPT_access_fpreg(unw_addr_space_t as,unw_regnum_t reg,unw_fpreg_t * val,int write,void * arg)75 _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
76 int write, void *arg)
77 {
78 struct UPT_info *ui = arg;
79 pid_t pid = ui->pid;
80 fpregset_t fpreg;
81
82 if ((unsigned) reg >= ARRAY_SIZE (_UPT_reg_offset))
83 return -UNW_EBADREG;
84
85 if (ptrace(PT_GETFPREGS, pid, (caddr_t)&fpreg, 0) == -1)
86 return -UNW_EBADREG;
87 if (write) {
88 #if defined(__amd64__)
89 memcpy(&fpreg.fpr_xacc[reg], val, sizeof(unw_fpreg_t));
90 #elif defined(__i386__)
91 memcpy(&fpreg.fpr_acc[reg], val, sizeof(unw_fpreg_t));
92 #else
93 #error Fix me
94 #endif
95 if (ptrace(PT_SETFPREGS, pid, (caddr_t)&fpreg, 0) == -1)
96 return -UNW_EBADREG;
97 } else
98 #if defined(__amd64__)
99 memcpy(val, &fpreg.fpr_xacc[reg], sizeof(unw_fpreg_t));
100 #elif defined(__i386__)
101 memcpy(val, &fpreg.fpr_acc[reg], sizeof(unw_fpreg_t));
102 #else
103 #error Fix me
104 #endif
105 return 0;
106 }
107 /* ANDROID support update. */
108 #elif defined(__mips__) || defined(__aarch64__)
109 int
_UPT_access_fpreg(unw_addr_space_t as,unw_regnum_t reg,unw_fpreg_t * val,int write,void * arg)110 _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
111 int write, void *arg)
112 {
113 # pragma message("_UPT_access_fpreg is not implemented and not currently used.")
114 return -UNW_EBADREG;
115 }
116 /* End of ANDROID update. */
117 #else
118 #error Fix me
119 #endif
120