• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2001-2005 Hewlett-Packard Co
3         Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 
5 This file is part of libunwind.
6 
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25 
26 #ifndef IA64_LIBUNWIND_I_H
27 #define IA64_LIBUNWIND_I_H
28 
29 /* Target-dependent definitions that are internal to libunwind but need
30    to be shared with target-independent code.  */
31 
32 #include "elf64.h"
33 #include "mempool.h"
34 #include <stdatomic.h>
35 
36 typedef struct
37   {
38     /* no ia64-specific fast trace */
39   }
40 unw_tdep_frame_t;
41 
42 enum ia64_pregnum
43   {
44     /* primary unat: */
45     IA64_REG_PRI_UNAT_GR,
46     IA64_REG_PRI_UNAT_MEM,
47 
48     /* memory stack (order matters: see build_script() */
49     IA64_REG_PSP,                       /* previous memory stack pointer */
50     /* register stack */
51     IA64_REG_BSP,                       /* register stack pointer */
52     IA64_REG_BSPSTORE,
53     IA64_REG_PFS,                       /* previous function state */
54     IA64_REG_RNAT,
55     /* instruction pointer: */
56     IA64_REG_IP,
57 
58     /* preserved registers: */
59     IA64_REG_R4, IA64_REG_R5, IA64_REG_R6, IA64_REG_R7,
60     IA64_REG_NAT4, IA64_REG_NAT5, IA64_REG_NAT6, IA64_REG_NAT7,
61     IA64_REG_UNAT, IA64_REG_PR, IA64_REG_LC, IA64_REG_FPSR,
62     IA64_REG_B1, IA64_REG_B2, IA64_REG_B3, IA64_REG_B4, IA64_REG_B5,
63     IA64_REG_F2, IA64_REG_F3, IA64_REG_F4, IA64_REG_F5,
64     IA64_REG_F16, IA64_REG_F17, IA64_REG_F18, IA64_REG_F19,
65     IA64_REG_F20, IA64_REG_F21, IA64_REG_F22, IA64_REG_F23,
66     IA64_REG_F24, IA64_REG_F25, IA64_REG_F26, IA64_REG_F27,
67     IA64_REG_F28, IA64_REG_F29, IA64_REG_F30, IA64_REG_F31,
68     IA64_NUM_PREGS
69   };
70 
71 #ifdef UNW_LOCAL_ONLY
72 
73 typedef unw_word_t ia64_loc_t;
74 
75 #else /* !UNW_LOCAL_ONLY */
76 
77 typedef struct ia64_loc
78   {
79     unw_word_t w0, w1;
80   }
81 ia64_loc_t;
82 
83 #endif /* !UNW_LOCAL_ONLY */
84 
85 #include "script.h"
86 
87 #define ABI_UNKNOWN                     0
88 #define ABI_LINUX                       1
89 #define ABI_HPUX                        2
90 #define ABI_FREEBSD                     3
91 #define ABI_OPENVMS                     4
92 #define ABI_NSK                         5       /* Tandem/HP Non-Stop Kernel */
93 #define ABI_WINDOWS                     6
94 
95 struct unw_addr_space
96   {
97     struct unw_accessors acc;
98     int big_endian;
99     int abi;    /* abi < 0 => unknown, 0 => SysV, 1 => HP-UX, 2 => Windows */
100     unw_caching_policy_t caching_policy;
101     _Atomic uint32_t cache_generation;
102     unw_word_t dyn_generation;
103     unw_word_t dyn_info_list_addr;      /* (cached) dyn_info_list_addr */
104 #ifndef UNW_REMOTE_ONLY
105     unsigned long long shared_object_removals;
106 #endif
107 
108     struct ia64_script_cache global_cache;
109    };
110 
111 /* Note: The ABI numbers in the ABI-markers (.unwabi directive) are
112    not the same as the above ABI numbers.  */
113 #define ABI_MARKER_OLD_LINUX_SIGTRAMP   ((0 << 8) | 's')
114 #define ABI_MARKER_OLD_LINUX_INTERRUPT  ((0 << 8) | 'i')
115 #define ABI_MARKER_HP_UX_SIGTRAMP       ((1 << 8) | 1)
116 #define ABI_MARKER_LINUX_SIGTRAMP       ((3 << 8) | 's')
117 #define ABI_MARKER_LINUX_INTERRUPT      ((3 << 8) | 'i')
118 
119 struct cursor
120   {
121     void *as_arg;               /* argument to address-space callbacks */
122     unw_addr_space_t as;        /* reference to per-address-space info */
123 
124     /* IP, CFM, and predicate cache (these are always equal to the
125        values stored in ip_loc, cfm_loc, and pr_loc,
126        respectively).  */
127     unw_word_t ip;              /* instruction pointer value */
128     unw_word_t cfm;             /* current frame mask */
129     unw_word_t pr;              /* current predicate values */
130 
131     /* current frame info: */
132     unw_word_t bsp;             /* backing store pointer value */
133     unw_word_t sp;              /* stack pointer value */
134     unw_word_t psp;             /* previous sp value */
135     ia64_loc_t cfm_loc;         /* cfm save location (or NULL) */
136     ia64_loc_t ec_loc;          /* ar.ec save location (usually cfm_loc) */
137     ia64_loc_t loc[IA64_NUM_PREGS];
138 
139     unw_word_t eh_args[4];      /* exception handler arguments */
140     unw_word_t sigcontext_addr; /* address of sigcontext or 0 */
141     unw_word_t sigcontext_off;  /* sigcontext-offset relative to signal sp */
142 
143     short hint;
144     short prev_script;
145 
146     uint8_t nat_bitnr[4];       /* NaT bit numbers for r4-r7 */
147     uint16_t abi_marker;        /* abi_marker for current frame (if any) */
148     uint16_t last_abi_marker;   /* last abi_marker encountered so far */
149     uint8_t eh_valid_mask;
150 
151     unsigned int pi_valid :1;           /* is proc_info valid? */
152     unsigned int pi_is_dynamic :1; /* proc_info found via dynamic proc info? */
153     unw_proc_info_t pi;         /* info about current procedure */
154 
155     /* In case of stack-discontiguities, such as those introduced by
156        signal-delivery on an alternate signal-stack (see
157        sigaltstack(2)), we use the following data-structure to keep
158        track of the register-backing-store areas across on which the
159        current frame may be backed up.  Since there are at most 96
160        stacked registers and since we only have to track the current
161        frame and only areas that are not empty, this puts an upper
162        limit on the # of backing-store areas we have to track.
163 
164        Note that the rbs-area indexed by rbs_curr identifies the
165        rbs-area that was in effect at the time AR.BSP had the value
166        c->bsp.  However, this rbs area may not actually contain the
167        value in the register that c->bsp corresponds to because that
168        register may not have gotten spilled until much later, when a
169        possibly different rbs-area might have been in effect
170        already.  */
171     uint8_t rbs_curr;           /* index of curr. rbs-area (contains c->bsp) */
172     uint8_t rbs_left_edge;      /* index of inner-most valid rbs-area */
173     struct rbs_area
174       {
175         unw_word_t end;
176         unw_word_t size;
177         ia64_loc_t rnat_loc;
178       }
179     rbs_area[96 + 2];   /* 96 stacked regs + 1 extra stack on each side... */
180 };
181 
182 struct ia64_global_unwind_state
183   {
184     pthread_mutex_t lock;               /* global data lock */
185 
186     volatile char init_done;
187 
188     /* Table of registers that prologues can save (and order in which
189        they're saved).  */
190     const unsigned char save_order[8];
191 
192     /*
193      * uc_addr() may return pointers to these variables.  We need to
194      * make sure they don't get written via ia64_put() or
195      * ia64_putfp().  To make it possible to test for these variables
196      * quickly, we collect them in a single sub-structure.
197      */
198     struct
199       {
200         unw_word_t  r0;                 /* r0 is byte-order neutral */
201         unw_fpreg_t f0;                 /* f0 is byte-order neutral */
202         unw_fpreg_t f1_le, f1_be;       /* f1 is byte-order dependent */
203       }
204     read_only;
205     unw_fpreg_t nat_val_le, nat_val_be;
206     unw_fpreg_t int_val_le, int_val_be;
207 
208     struct mempool reg_state_pool;
209     struct mempool labeled_state_pool;
210 
211 # if UNW_DEBUG
212     const char *preg_name[IA64_NUM_PREGS];
213 # endif
214   };
215 
216 #define tdep_getcontext_trace           unw_getcontext
217 #define tdep_init_done                  unw.init_done
218 #define tdep_init                       UNW_OBJ(init)
219 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
220    tdep_search_unwind_table.  */
221 #define tdep_search_unwind_table        unw_search_ia64_unwind_table
222 #define tdep_find_unwind_table  ia64_find_unwind_table
223 #define tdep_find_proc_info             UNW_OBJ(find_proc_info)
224 #define tdep_uc_addr                    UNW_OBJ(uc_addr)
225 #define tdep_get_elf_image              UNW_ARCH_OBJ(get_elf_image)
226 #define tdep_get_exe_image_path         UNW_ARCH_OBJ(get_exe_image_path)
227 #define tdep_access_reg                 UNW_OBJ(access_reg)
228 #define tdep_access_fpreg               UNW_OBJ(access_fpreg)
229 #define tdep_fetch_frame(c,ip,n)        do {} while(0)
230 #define tdep_cache_frame(c)             0
231 #define tdep_reuse_frame(c,frame)       do {} while(0)
232 #define tdep_stash_frame(c,rs)          do {} while(0)
233 #define tdep_trace(cur,addr,n)          (-UNW_ENOINFO)
234 #define tdep_get_as(c)                  ((c)->as)
235 #define tdep_get_as_arg(c)              ((c)->as_arg)
236 #define tdep_get_ip(c)                  ((c)->ip)
237 #define tdep_big_endian(as)             ((c)->as->big_endian != 0)
238 
239 #ifndef UNW_LOCAL_ONLY
240 # define tdep_put_unwind_info           UNW_OBJ(put_unwind_info)
241 #endif
242 
243 /* This can't be an UNW_ARCH_OBJ() because we need separate
244    unw.initialized flags for the local-only and generic versions of
245    the library.  Also, if we wanted to have a single, shared global
246    data structure, we couldn't declare "unw" as HIDDEN.  */
247 #define unw                             UNW_OBJ(data)
248 
249 extern void tdep_init (void);
250 extern int tdep_find_unwind_table (struct elf_dyn_info *edi,
251                                    unw_addr_space_t as, char *path,
252                                    unw_word_t segbase, unw_word_t mapoff,
253                                    unw_word_t ip);
254 extern int tdep_find_proc_info (unw_addr_space_t as, unw_word_t ip,
255                                 unw_proc_info_t *pi, int need_unwind_info,
256                                 void *arg);
257 extern void tdep_put_unwind_info (unw_addr_space_t as,
258                                   unw_proc_info_t *pi, void *arg);
259 extern void *tdep_uc_addr (ucontext_t *uc, unw_regnum_t regnum,
260                            uint8_t *nat_bitnr);
261 extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
262                                unsigned long *segbase, unsigned long *mapoff,
263                                char *path, size_t pathlen);
264 extern void tdep_get_exe_image_path (char *path);
265 extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
266                             unw_word_t *valp, int write);
267 extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
268                               unw_fpreg_t *valp, int write);
269 
270 extern struct ia64_global_unwind_state unw;
271 
272 /* In user-level, we have no reasonable way of determining the base of
273    an arbitrary backing-store.  We default to half the
274    address-space.  */
275 #define rbs_get_base(c,bspstore,rbs_basep)                              \
276         (*(rbs_basep) = (bspstore) - (((unw_word_t) 1) << 63), 0)
277 
278 #endif /* IA64_LIBUNWIND_I_H */
279