2002-12-19 08:16:50 +01:00
|
|
|
/* libunwind - a platform-independent unwind library
|
2003-01-21 09:08:32 +01:00
|
|
|
Copyright (C) 2001-2003 Hewlett-Packard Co
|
2002-12-19 08:16:50 +01:00
|
|
|
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
|
|
|
|
|
|
|
This file is part of libunwind.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
|
|
|
|
#ifndef internal_h
|
|
|
|
#define internal_h
|
|
|
|
|
2003-03-19 20:25:18 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-12-04 08:30:39 +01:00
|
|
|
#ifdef HAVE___THREAD
|
|
|
|
/* For now, turn off per-thread caching. It uses up too much TLS
|
|
|
|
memory per thread even when the thread never uses libunwind at
|
|
|
|
all. */
|
|
|
|
# undef HAVE___THREAD
|
|
|
|
#endif
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
/* Platform-independent libunwind-internal declarations. */
|
|
|
|
|
2003-03-19 20:25:18 +01:00
|
|
|
#include <sys/types.h> /* HP-UX needs this before include of pthread.h */
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <libunwind.h>
|
2003-03-06 07:14:36 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
2004-01-03 11:50:24 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2002-12-19 08:16:50 +01:00
|
|
|
|
2003-04-03 09:59:15 +02:00
|
|
|
#ifdef HAVE_ENDIAN_H
|
|
|
|
# include <endian.h>
|
|
|
|
#else
|
|
|
|
# define __LITTLE_ENDIAN 1234
|
|
|
|
# define __BIG_ENDIAN 4321
|
|
|
|
# if defined(__hpux)
|
2003-10-11 03:05:18 +02:00
|
|
|
# define __BYTE_ORDER __BIG_ENDIAN
|
2003-04-03 09:59:15 +02:00
|
|
|
# else
|
|
|
|
# error Host has unknown byte-order.
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
#ifdef __GNUC__
|
2003-11-27 07:52:54 +01:00
|
|
|
# define UNUSED __attribute__((unused))
|
2004-01-03 11:50:24 +01:00
|
|
|
# define NORETURN __attribute__((noreturn))
|
2003-02-08 11:10:59 +01:00
|
|
|
# if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 2)
|
2003-12-04 08:30:39 +01:00
|
|
|
# define ALWAYS_INLINE __attribute__((always_inline))
|
2003-02-08 11:10:59 +01:00
|
|
|
# define HIDDEN __attribute__((visibility ("hidden")))
|
2004-01-03 11:50:24 +01:00
|
|
|
# define PROTECTED __attribute__((visibility ("protected")))
|
2003-02-08 11:10:59 +01:00
|
|
|
# else
|
2003-12-04 08:30:39 +01:00
|
|
|
# define ALWAYS_INLINE
|
2003-02-08 11:10:59 +01:00
|
|
|
# define HIDDEN
|
2004-01-03 11:50:24 +01:00
|
|
|
# define PROTECTED
|
2003-02-08 11:10:59 +01:00
|
|
|
# endif
|
2003-02-15 04:10:30 +01:00
|
|
|
# if (__GNUC__ >= 3)
|
|
|
|
# define likely(x) __builtin_expect ((x), 1)
|
|
|
|
# define unlikely(x) __builtin_expect ((x), 0)
|
|
|
|
# else
|
|
|
|
# define likely(x) (x)
|
|
|
|
# define unlikely(x) (x)
|
|
|
|
# endif
|
2002-12-19 08:16:50 +01:00
|
|
|
#else
|
2003-12-04 08:30:39 +01:00
|
|
|
# define ALWAYS_INLINE
|
2003-11-27 07:52:54 +01:00
|
|
|
# define UNUSED
|
2004-01-03 11:50:24 +01:00
|
|
|
# define NORETURN
|
2002-12-19 08:16:50 +01:00
|
|
|
# define HIDDEN
|
2004-01-03 11:50:24 +01:00
|
|
|
# define PROTECTED
|
2003-02-15 04:10:30 +01:00
|
|
|
# define likely(x) (x)
|
|
|
|
# define unlikely(x) (x)
|
2002-12-19 08:16:50 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
# define UNW_DEBUG 1
|
2003-11-27 07:52:54 +01:00
|
|
|
#else
|
|
|
|
# define UNW_DEBUG 0
|
2002-12-19 08:16:50 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UNW_DEBUG
|
|
|
|
# include <stdio.h>
|
2003-12-20 12:32:43 +01:00
|
|
|
# define debug(level,format...) \
|
|
|
|
do { \
|
|
|
|
if (tdep_debug_level > level) fprintf (stderr, format); \
|
|
|
|
} while (0)
|
|
|
|
# define Debug(level,format...) \
|
|
|
|
do { \
|
|
|
|
if (tdep_debug_level > level) \
|
|
|
|
{ \
|
|
|
|
int _n = level; \
|
|
|
|
if (_n > 16) \
|
|
|
|
_n = 16; \
|
|
|
|
fprintf (stderr, "%*c>%s: ", _n, ' ', __FUNCTION__); \
|
|
|
|
fprintf (stderr, format); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2002-12-19 08:16:50 +01:00
|
|
|
# define dprintf(format...) \
|
2003-02-15 04:10:30 +01:00
|
|
|
fprintf (stderr, format)
|
2002-12-19 08:16:50 +01:00
|
|
|
# ifdef __GNUC__
|
2003-11-24 22:37:22 +01:00
|
|
|
# undef inline
|
2003-11-27 07:52:54 +01:00
|
|
|
# define inline UNUSED
|
2002-12-19 08:16:50 +01:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define debug(level,format...)
|
|
|
|
# define dprintf(format...)
|
|
|
|
#endif
|
|
|
|
|
2003-01-21 09:08:32 +01:00
|
|
|
#define NELEMS(a) (sizeof (a) / sizeof ((a)[0]))
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
/* Make it easy to write thread-safe code which may or may not be
|
|
|
|
linked against libpthread. The macros below can be used
|
|
|
|
unconditionally and if -lpthread is around, they'll call the
|
|
|
|
corresponding routines otherwise, they do nothing. */
|
|
|
|
|
2003-03-29 08:32:50 +01:00
|
|
|
#pragma weak pthread_mutex_init
|
2002-12-19 08:16:50 +01:00
|
|
|
#pragma weak pthread_mutex_lock
|
|
|
|
#pragma weak pthread_mutex_unlock
|
|
|
|
|
2003-03-06 07:14:36 +01:00
|
|
|
#define mutex_init(l) (pthread_mutex_init ? pthread_mutex_init ((l), 0) : 0)
|
2002-12-19 08:16:50 +01:00
|
|
|
#define mutex_lock(l) (pthread_mutex_lock ? pthread_mutex_lock (l) : 0)
|
|
|
|
#define mutex_unlock(l) (pthread_mutex_unlock ? pthread_mutex_unlock (l) : 0)
|
|
|
|
|
2003-11-24 22:37:22 +01:00
|
|
|
#ifdef HAVE_ATOMIC_OPS_H
|
|
|
|
# include <atomic_ops.h>
|
|
|
|
# define cmpxchg_ptr(_ptr,_o,_n) AO_compare_and_swap((AO_T *)_ptr, \
|
|
|
|
(AO_T) (_o), \
|
|
|
|
(AO_T) (_n))
|
|
|
|
# define fetch_and_add1(_ptr) AO_fetch_and_add1(_ptr)
|
2003-11-27 07:52:54 +01:00
|
|
|
/* GCC 3.2.0 on HP-UX crashes on cmpxchg_ptr() */
|
|
|
|
# if !(defined(__hpux) && __GNUC__ == 3 && __GNUC_MINOR__ == 2)
|
|
|
|
# define HAVE_CMPXCHG
|
|
|
|
# endif
|
2003-11-24 22:37:22 +01:00
|
|
|
# define HAVE_FETCH_AND_ADD1
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_IA64INTRIN_H
|
|
|
|
# include <ia64intrin.h>
|
|
|
|
# define cmpxchg_ptr(_ptr,_o,_n) \
|
2003-12-05 07:42:28 +01:00
|
|
|
(__sync_bool_compare_and_swap((volatile long *) (_ptr), \
|
|
|
|
(long) (_o), (long) (_n)))
|
2003-11-24 22:37:22 +01:00
|
|
|
# define fetch_and_add1(_ptr) __sync_fetch_and_add(_ptr, 1)
|
|
|
|
# define HAVE_CMPXCHG
|
|
|
|
# define HAVE_FETCH_AND_ADD1
|
|
|
|
# endif
|
2003-03-06 07:14:36 +01:00
|
|
|
#endif
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
#define UNWI_OBJ(fn) UNW_PASTE(UNW_PREFIX,UNW_PASTE(I,fn))
|
|
|
|
#define UNWI_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_UI,UNW_TARGET),_), fn)
|
|
|
|
|
2003-03-06 07:14:36 +01:00
|
|
|
#define unwi_full_sigmask UNWI_ARCH_OBJ(full_sigmask)
|
|
|
|
|
|
|
|
extern sigset_t unwi_full_sigmask;
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
extern int UNWI_OBJ(find_dynamic_proc_info) (unw_addr_space_t as,
|
|
|
|
unw_word_t ip,
|
|
|
|
unw_proc_info_t *pi,
|
|
|
|
int need_unwind_info, void *arg);
|
2003-12-20 12:32:43 +01:00
|
|
|
extern int UNWI_OBJ(extract_dynamic_proc_info) (unw_addr_space_t as,
|
|
|
|
unw_word_t ip,
|
|
|
|
unw_proc_info_t *pi,
|
|
|
|
unw_dyn_info_t *di,
|
|
|
|
int need_unwind_info,
|
|
|
|
void *arg);
|
2002-12-19 08:16:50 +01:00
|
|
|
extern void UNWI_OBJ(put_dynamic_unwind_info) (unw_addr_space_t as,
|
|
|
|
unw_proc_info_t *pi, void *arg);
|
2003-12-20 12:32:43 +01:00
|
|
|
extern int UNWI_OBJ(dyn_remote_find_proc_info) (unw_addr_space_t as,
|
|
|
|
unw_word_t ip,
|
|
|
|
unw_proc_info_t *pi,
|
|
|
|
unw_word_t *generation,
|
|
|
|
int need_unwind_info,
|
|
|
|
void *arg);
|
|
|
|
extern void UNWI_OBJ(dyn_remote_put_unwind_info) (unw_addr_space_t as,
|
|
|
|
unw_proc_info_t *pi,
|
|
|
|
void *arg);
|
2003-02-22 09:19:43 +01:00
|
|
|
extern int UNWI_OBJ(get_proc_name) (unw_addr_space_t as, unw_word_t ip,
|
|
|
|
char *buf, size_t buf_len,
|
|
|
|
unw_word_t *offp, void *arg);
|
2002-12-19 08:16:50 +01:00
|
|
|
|
|
|
|
#define unwi_find_dynamic_proc_info(as,ip,pi,n,arg) \
|
|
|
|
UNWI_OBJ(find_dynamic_proc_info)(as, ip, pi, n, arg)
|
|
|
|
|
|
|
|
#define unwi_extract_dynamic_proc_info(as,ip,pi,di,n,arg) \
|
2003-12-20 12:32:43 +01:00
|
|
|
UNWI_OBJ(extract_dynamic_proc_info)(as, ip, pi, di, n, arg)
|
2002-12-19 08:16:50 +01:00
|
|
|
|
|
|
|
#define unwi_put_dynamic_unwind_info(as,pi,arg) \
|
|
|
|
UNWI_OBJ(put_dynamic_unwind_info)(as, pi, arg)
|
|
|
|
|
|
|
|
/* These handle the remote (cross-address-space) case of accessing
|
|
|
|
dynamic unwind info. */
|
|
|
|
|
|
|
|
#define unwi_dyn_remote_find_proc_info(as,i,p,g,n,arg) \
|
2003-12-20 12:32:43 +01:00
|
|
|
UNWI_OBJ(dyn_remote_find_proc_info)(as, i, p, g, n, arg)
|
2002-12-19 08:16:50 +01:00
|
|
|
|
|
|
|
#define unwi_dyn_remote_put_unwind_info(as,p,arg) \
|
2003-12-20 12:32:43 +01:00
|
|
|
UNWI_OBJ(dyn_remote_put_unwind_info)(as, p, arg)
|
2002-12-19 08:16:50 +01:00
|
|
|
|
2003-02-22 09:19:43 +01:00
|
|
|
#define unwi_get_proc_name(as,ip,b,s,o,arg) \
|
|
|
|
UNWI_OBJ(get_proc_name)(as, ip, b, s, o, arg)
|
2002-12-19 08:16:50 +01:00
|
|
|
|
|
|
|
extern unw_dyn_info_list_t _U_dyn_info_list;
|
|
|
|
extern pthread_mutex_t _U_dyn_info_list_lock;
|
|
|
|
|
|
|
|
#define WSIZE (sizeof (unw_word_t))
|
|
|
|
|
2004-01-03 11:50:24 +01:00
|
|
|
static inline ALWAYS_INLINE void
|
|
|
|
print_error (const char *string)
|
|
|
|
{
|
|
|
|
write (2, string, strlen (string));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UNW_LOCAL_ONLY
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetch8 (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, int8_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
*valp = *(int8_t *) *addr;
|
|
|
|
*addr += 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetch16 (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, int16_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
*valp = *(int16_t *) *addr;
|
|
|
|
*addr += 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetch32 (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, int32_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
*valp = *(int32_t *) *addr;
|
|
|
|
*addr += 4;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetchw (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, unw_word_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
*valp = *(unw_word_t *) *addr;
|
|
|
|
*addr += sizeof (unw_word_t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !UNW_LOCAL_ONLY */
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
static inline int
|
|
|
|
fetch8 (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, int8_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*addr += 1;
|
|
|
|
|
|
|
|
ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
|
|
|
|
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
val >>= 8*off;
|
|
|
|
#else
|
|
|
|
val >>= 8*(WSIZE - 1 - off);
|
|
|
|
#endif
|
|
|
|
*valp = val & 0xff;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetch16 (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, int16_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
assert ((off & 0x1) == 0);
|
|
|
|
|
|
|
|
*addr += 2;
|
|
|
|
|
|
|
|
ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
|
|
|
|
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
val >>= 8*off;
|
|
|
|
#else
|
|
|
|
val >>= 8*(WSIZE - 2 - off);
|
|
|
|
#endif
|
|
|
|
*valp = val & 0xffff;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetch32 (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, int32_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
assert ((off & 0x3) == 0);
|
|
|
|
|
|
|
|
*addr += 4;
|
|
|
|
|
|
|
|
ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
|
|
|
|
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
val >>= 8*off;
|
|
|
|
#else
|
|
|
|
val >>= 8*(WSIZE - 4 - off);
|
|
|
|
#endif
|
|
|
|
*valp = val & 0xffffffff;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fetchw (unw_addr_space_t as, unw_accessors_t *a,
|
|
|
|
unw_word_t *addr, unw_word_t *valp, void *arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = (*a->access_mem) (as, *addr, valp, 0, arg);
|
|
|
|
*addr += WSIZE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-01-03 11:50:24 +01:00
|
|
|
#endif /* !UNW_LOCAL_ONLY */
|
|
|
|
|
2003-01-23 11:04:09 +01:00
|
|
|
#define mi_init UNWI_ARCH_OBJ(mi_init)
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
extern void mi_init (void); /* machine-independent initializations */
|
2004-01-03 11:50:24 +01:00
|
|
|
extern unw_word_t _U_dyn_info_list_addr (void);
|
2002-12-19 08:16:50 +01:00
|
|
|
|
2003-02-08 11:10:59 +01:00
|
|
|
/* This is needed/used by ELF targets only. */
|
|
|
|
|
|
|
|
struct elf_image
|
|
|
|
{
|
|
|
|
void *image; /* pointer to mmap'd image */
|
|
|
|
size_t size; /* (file-) size of the image */
|
|
|
|
};
|
|
|
|
|
2002-12-19 08:16:50 +01:00
|
|
|
#endif /* internal_h */
|