blob: c4a90a6c99e93a3223dbd4ec07d731cafc360af7 [file] [log] [blame]
mostang.com!davidmbf070a92002-12-19 07:16:50 +00001/* libunwind - a platform-independent unwind library
mostang.com!davidm313653f2003-01-21 08:08:32 +00002 Copyright (C) 2001-2003 Hewlett-Packard Co
mostang.com!davidmbf070a92002-12-19 07:16:50 +00003 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
26#ifndef internal_h
27#define internal_h
28
mostang.com!davidm15693e22003-03-19 19:25:18 +000029#ifdef HAVE_CONFIG_H
30# include "config.h"
31#endif
32
mostang.com!davidmbf070a92002-12-19 07:16:50 +000033/* Platform-independent libunwind-internal declarations. */
34
mostang.com!davidm15693e22003-03-19 19:25:18 +000035#include <sys/types.h> /* HP-UX needs this before include of pthread.h */
36
mostang.com!davidmbf070a92002-12-19 07:16:50 +000037#include <assert.h>
mostang.com!davidmbf070a92002-12-19 07:16:50 +000038#include <libunwind.h>
mostang.com!davidm9003fd22003-03-06 06:14:36 +000039#include <pthread.h>
40#include <signal.h>
mostang.com!davidmbf070a92002-12-19 07:16:50 +000041
42#ifdef __GNUC__
mostang.com!davidmf5265f52003-02-08 10:10:59 +000043# if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 2)
44# define HIDDEN __attribute__((visibility ("hidden")))
45# else
46# define HIDDEN
47# endif
hp.com!davidma45c8882003-02-15 03:10:30 +000048# if (__GNUC__ >= 3)
49# define likely(x) __builtin_expect ((x), 1)
50# define unlikely(x) __builtin_expect ((x), 0)
51# else
52# define likely(x) (x)
53# define unlikely(x) (x)
54# endif
mostang.com!davidmbf070a92002-12-19 07:16:50 +000055#else
56# define HIDDEN
hp.com!davidma45c8882003-02-15 03:10:30 +000057# define likely(x) (x)
58# define unlikely(x) (x)
mostang.com!davidmbf070a92002-12-19 07:16:50 +000059#endif
60
61#ifdef DEBUG
62# define UNW_DEBUG 1
63#endif
64
65#if UNW_DEBUG
66# include <stdio.h>
67# define debug(level,format...) \
hp.com!davidma45c8882003-02-15 03:10:30 +000068 do { if (tdep_debug_level > level) fprintf (stderr, format); } while (0)
mostang.com!davidmbf070a92002-12-19 07:16:50 +000069# define dprintf(format...) \
hp.com!davidma45c8882003-02-15 03:10:30 +000070 fprintf (stderr, format)
mostang.com!davidmbf070a92002-12-19 07:16:50 +000071# ifdef __GNUC__
72# define inline __attribute__ ((unused))
73# endif
74#else
75# define debug(level,format...)
76# define dprintf(format...)
mostang.com!davidmbf070a92002-12-19 07:16:50 +000077#endif
78
mostang.com!davidm313653f2003-01-21 08:08:32 +000079#define NELEMS(a) (sizeof (a) / sizeof ((a)[0]))
80
mostang.com!davidmbf070a92002-12-19 07:16:50 +000081/* Make it easy to write thread-safe code which may or may not be
82 linked against libpthread. The macros below can be used
83 unconditionally and if -lpthread is around, they'll call the
84 corresponding routines otherwise, they do nothing. */
85
86#pragma weak pthread_mutex_lock
87#pragma weak pthread_mutex_unlock
88
mostang.com!davidm9003fd22003-03-06 06:14:36 +000089#define mutex_init(l) (pthread_mutex_init ? pthread_mutex_init ((l), 0) : 0)
mostang.com!davidmbf070a92002-12-19 07:16:50 +000090#define mutex_lock(l) (pthread_mutex_lock ? pthread_mutex_lock (l) : 0)
91#define mutex_unlock(l) (pthread_mutex_unlock ? pthread_mutex_unlock (l) : 0)
92
mostang.com!davidm15693e22003-03-19 19:25:18 +000093#ifdef HAVE_IA64INTRIN_H
mostang.com!davidm9003fd22003-03-06 06:14:36 +000094# define HAVE_CMPXCHG
95# include <ia64intrin.h>
96# define cmpxchg_ptr(_ptr,_o,_n) \
97 ((void *) __sync_val_compare_and_swap((long *) (_ptr), \
98 (long) (_o), (long) (_n)))
99#endif
100
mostang.com!davidmbf070a92002-12-19 07:16:50 +0000101#define UNWI_OBJ(fn) UNW_PASTE(UNW_PREFIX,UNW_PASTE(I,fn))
102#define UNWI_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_UI,UNW_TARGET),_), fn)
103
mostang.com!davidm9003fd22003-03-06 06:14:36 +0000104#define unwi_full_sigmask UNWI_ARCH_OBJ(full_sigmask)
105
106extern sigset_t unwi_full_sigmask;
107
mostang.com!davidmbf070a92002-12-19 07:16:50 +0000108extern int UNWI_OBJ(find_dynamic_proc_info) (unw_addr_space_t as,
109 unw_word_t ip,
110 unw_proc_info_t *pi,
111 int need_unwind_info, void *arg);
112extern int UNWI_ARCH_OBJ(extract_dynamic_proc_info) (unw_addr_space_t as,
113 unw_word_t ip,
114 unw_proc_info_t *pi,
115 unw_dyn_info_t *di,
116 int need_unwind_info,
117 void *arg);
118extern void UNWI_OBJ(put_dynamic_unwind_info) (unw_addr_space_t as,
119 unw_proc_info_t *pi, void *arg);
120extern int UNWI_ARCH_OBJ(dyn_remote_find_proc_info) (unw_addr_space_t as,
121 unw_word_t ip,
122 unw_proc_info_t *pi,
123 unw_word_t *generation,
124 int need_unwind_info,
125 void *arg);
126extern void UNWI_ARCH_OBJ(dyn_remote_put_unwind_info) (unw_addr_space_t as,
127 unw_proc_info_t *pi,
128 void *arg);
mostang.com!davidme20ecc62003-02-22 08:19:43 +0000129extern int UNWI_OBJ(get_proc_name) (unw_addr_space_t as, unw_word_t ip,
130 char *buf, size_t buf_len,
131 unw_word_t *offp, void *arg);
mostang.com!davidmbf070a92002-12-19 07:16:50 +0000132
133#define unwi_find_dynamic_proc_info(as,ip,pi,n,arg) \
134 UNWI_OBJ(find_dynamic_proc_info)(as, ip, pi, n, arg)
135
136#define unwi_extract_dynamic_proc_info(as,ip,pi,di,n,arg) \
137 UNWI_ARCH_OBJ(extract_dynamic_proc_info)(as, ip, pi, di, n, arg)
138
139#define unwi_put_dynamic_unwind_info(as,pi,arg) \
140 UNWI_OBJ(put_dynamic_unwind_info)(as, pi, arg)
141
142/* These handle the remote (cross-address-space) case of accessing
143 dynamic unwind info. */
144
145#define unwi_dyn_remote_find_proc_info(as,i,p,g,n,arg) \
146 UNWI_ARCH_OBJ(dyn_remote_find_proc_info)(as, i, p, g, n, arg)
147
148#define unwi_dyn_remote_put_unwind_info(as,p,arg) \
149 UNWI_ARCH_OBJ(dyn_remote_put_unwind_info)(as, p, arg)
150
mostang.com!davidme20ecc62003-02-22 08:19:43 +0000151#define unwi_get_proc_name(as,ip,b,s,o,arg) \
152 UNWI_OBJ(get_proc_name)(as, ip, b, s, o, arg)
mostang.com!davidmbf070a92002-12-19 07:16:50 +0000153
154extern unw_dyn_info_list_t _U_dyn_info_list;
155extern pthread_mutex_t _U_dyn_info_list_lock;
156
157#define WSIZE (sizeof (unw_word_t))
158
159static inline int
160fetch8 (unw_addr_space_t as, unw_accessors_t *a,
161 unw_word_t *addr, int8_t *valp, void *arg)
162{
163 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
164 int ret;
165
166 *addr += 1;
167
168 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
169
170#if __BYTE_ORDER == __LITTLE_ENDIAN
171 val >>= 8*off;
172#else
173 val >>= 8*(WSIZE - 1 - off);
174#endif
175 *valp = val & 0xff;
176 return ret;
177}
178
179static inline int
180fetch16 (unw_addr_space_t as, unw_accessors_t *a,
181 unw_word_t *addr, int16_t *valp, void *arg)
182{
183 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
184 int ret;
185
186 assert ((off & 0x1) == 0);
187
188 *addr += 2;
189
190 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
191
192#if __BYTE_ORDER == __LITTLE_ENDIAN
193 val >>= 8*off;
194#else
195 val >>= 8*(WSIZE - 2 - off);
196#endif
197 *valp = val & 0xffff;
198 return ret;
199}
200
201static inline int
202fetch32 (unw_addr_space_t as, unw_accessors_t *a,
203 unw_word_t *addr, int32_t *valp, void *arg)
204{
205 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
206 int ret;
207
208 assert ((off & 0x3) == 0);
209
210 *addr += 4;
211
212 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
213
214#if __BYTE_ORDER == __LITTLE_ENDIAN
215 val >>= 8*off;
216#else
217 val >>= 8*(WSIZE - 4 - off);
218#endif
219 *valp = val & 0xffffffff;
220 return ret;
221}
222
223static inline int
224fetchw (unw_addr_space_t as, unw_accessors_t *a,
225 unw_word_t *addr, unw_word_t *valp, void *arg)
226{
227 int ret;
228
229 ret = (*a->access_mem) (as, *addr, valp, 0, arg);
230 *addr += WSIZE;
231 return ret;
232}
233
mostang.com!davidm7e268d22003-01-23 10:04:09 +0000234#define mi_init UNWI_ARCH_OBJ(mi_init)
235
mostang.com!davidmbf070a92002-12-19 07:16:50 +0000236extern void mi_init (void); /* machine-independent initializations */
237
mostang.com!davidmf5265f52003-02-08 10:10:59 +0000238/* This is needed/used by ELF targets only. */
239
240struct elf_image
241 {
242 void *image; /* pointer to mmap'd image */
243 size_t size; /* (file-) size of the image */
244 };
245
mostang.com!davidmbf070a92002-12-19 07:16:50 +0000246#endif /* internal_h */