mostang.com!davidm | 653c900 | 2002-12-12 09:17:41 +0000 | [diff] [blame^] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2001-2002 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 internal_h |
| 27 | #define internal_h |
| 28 | |
| 29 | /* Platform-independent libunwind-internal declarations. */ |
| 30 | |
| 31 | #include <assert.h> |
| 32 | #include <pthread.h> |
| 33 | #include <libunwind.h> |
| 34 | #include <tdep.h> |
| 35 | |
| 36 | #ifdef __GNUC__ |
| 37 | # define HIDDEN __attribute__((visibility ("hidden"))) |
| 38 | #else |
| 39 | # define HIDDEN |
| 40 | #endif |
| 41 | |
| 42 | /* Make it easy to write thread-safe code which may or may not be |
| 43 | linked against libpthread. The macros below can be used |
| 44 | unconditionally and if -lpthread is around, they'll call the |
| 45 | corresponding routines otherwise, they do nothing. */ |
| 46 | |
| 47 | #pragma weak pthread_mutex_lock |
| 48 | #pragma weak pthread_mutex_unlock |
| 49 | |
| 50 | #define mutex_lock(l) (pthread_mutex_lock ? pthread_mutex_lock (l) : 0) |
| 51 | #define mutex_unlock(l) (pthread_mutex_unlock ? pthread_mutex_unlock (l) : 0) |
| 52 | |
| 53 | #define UNWI_OBJ(fn) UNW_PASTE(UNW_PREFIX,UNW_PASTE(I,fn)) |
| 54 | #define UNWI_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_UI,UNW_TARGET),_), fn) |
| 55 | |
| 56 | extern int UNWI_OBJ(find_dynamic_proc_info) (unw_addr_space_t as, |
| 57 | unw_word_t ip, |
| 58 | unw_proc_info_t *pi, |
| 59 | int need_unwind_info, void *arg); |
| 60 | extern int UNWI_ARCH_OBJ(extract_dynamic_proc_info) (unw_addr_space_t as, |
| 61 | unw_word_t ip, |
| 62 | unw_proc_info_t *pi, |
| 63 | unw_dyn_info_t *di, |
| 64 | int need_unwind_info, |
| 65 | void *arg); |
| 66 | extern void UNWI_OBJ(put_dynamic_unwind_info) (unw_addr_space_t as, |
| 67 | unw_proc_info_t *pi, void *arg); |
| 68 | extern int UNWI_ARCH_OBJ(dyn_remote_find_proc_info) (unw_addr_space_t as, |
| 69 | unw_word_t ip, |
| 70 | unw_proc_info_t *pi, |
| 71 | unw_word_t *generation, |
| 72 | int need_unwind_info, |
| 73 | void *arg); |
| 74 | extern void UNWI_ARCH_OBJ(dyn_remote_put_unwind_info) (unw_addr_space_t as, |
| 75 | unw_proc_info_t *pi, |
| 76 | void *arg); |
| 77 | extern int UNWI_ARCH_OBJ(get_proc_name) (unw_addr_space_t as, |
| 78 | unw_word_t ip, int is_local, |
| 79 | char *buf, size_t buf_len, void *arg); |
| 80 | |
| 81 | #define unwi_find_dynamic_proc_info(as,ip,pi,n,arg) \ |
| 82 | UNWI_OBJ(find_dynamic_proc_info)(as, ip, pi, n, arg) |
| 83 | |
| 84 | #define unwi_extract_dynamic_proc_info(as,ip,pi,di,n,arg) \ |
| 85 | UNWI_ARCH_OBJ(extract_dynamic_proc_info)(as, ip, pi, di, n, arg) |
| 86 | |
| 87 | #define unwi_put_dynamic_unwind_info(as,pi,arg) \ |
| 88 | UNWI_OBJ(put_dynamic_unwind_info)(as, pi, arg) |
| 89 | |
| 90 | /* These handle the remote (cross-address-space) case of accessing |
| 91 | dynamic unwind info. */ |
| 92 | |
| 93 | #define unwi_dyn_remote_find_proc_info(as,i,p,g,n,arg) \ |
| 94 | UNWI_ARCH_OBJ(dyn_remote_find_proc_info)(as, i, p, g, n, arg) |
| 95 | |
| 96 | #define unwi_dyn_remote_put_unwind_info(as,p,arg) \ |
| 97 | UNWI_ARCH_OBJ(dyn_remote_put_unwind_info)(as, p, arg) |
| 98 | |
| 99 | #define unwi_get_proc_name(as,ip,l,b,s,arg) \ |
| 100 | UNWI_ARCH_OBJ(get_proc_name)(as, ip, l, b, s, arg) |
| 101 | |
| 102 | extern unw_dyn_info_list_t _U_dyn_info_list; |
| 103 | extern pthread_mutex_t _U_dyn_info_list_lock; |
| 104 | |
| 105 | #define WSIZE (sizeof (unw_word_t)) |
| 106 | |
| 107 | static inline int |
| 108 | fetch8 (unw_addr_space_t as, unw_accessors_t *a, |
| 109 | unw_word_t *addr, int8_t *valp, void *arg) |
| 110 | { |
| 111 | unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr; |
| 112 | int ret; |
| 113 | |
| 114 | *addr += 1; |
| 115 | |
| 116 | ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg); |
| 117 | |
| 118 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 119 | val >>= 8*off; |
| 120 | #else |
| 121 | val >>= 8*(WSIZE - 1 - off); |
| 122 | #endif |
| 123 | *valp = val & 0xff; |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | static inline int |
| 128 | fetch16 (unw_addr_space_t as, unw_accessors_t *a, |
| 129 | unw_word_t *addr, int16_t *valp, void *arg) |
| 130 | { |
| 131 | unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr; |
| 132 | int ret; |
| 133 | |
| 134 | assert ((off & 0x1) == 0); |
| 135 | |
| 136 | *addr += 2; |
| 137 | |
| 138 | ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg); |
| 139 | |
| 140 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 141 | val >>= 8*off; |
| 142 | #else |
| 143 | val >>= 8*(WSIZE - 2 - off); |
| 144 | #endif |
| 145 | *valp = val & 0xffff; |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | static inline int |
| 150 | fetch32 (unw_addr_space_t as, unw_accessors_t *a, |
| 151 | unw_word_t *addr, int32_t *valp, void *arg) |
| 152 | { |
| 153 | unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr; |
| 154 | int ret; |
| 155 | |
| 156 | assert ((off & 0x3) == 0); |
| 157 | |
| 158 | *addr += 4; |
| 159 | |
| 160 | ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg); |
| 161 | |
| 162 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 163 | val >>= 8*off; |
| 164 | #else |
| 165 | val >>= 8*(WSIZE - 4 - off); |
| 166 | #endif |
| 167 | *valp = val & 0xffffffff; |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | static inline int |
| 172 | fetchw (unw_addr_space_t as, unw_accessors_t *a, |
| 173 | unw_word_t *addr, unw_word_t *valp, void *arg) |
| 174 | { |
| 175 | int ret; |
| 176 | |
| 177 | ret = (*a->access_mem) (as, *addr, valp, 0, arg); |
| 178 | *addr += WSIZE; |
| 179 | return ret; |
| 180 | } |
| 181 | |
| 182 | #endif /* internal_h */ |