20 # include <execinfo.h>
21 # include <sys/syscall.h>
22 # include <ucontext.h>
24 # define UNW_LOCAL_ONLY
25 # include <libunwind.h>
29 extern "C" void _sigtramp(
void );
34 #if !defined MAP_ANONYMOUS && defined MAP_ANON
35 # define MAP_ANONYMOUS MAP_ANON
45 #if 0 && __x86_64__ && __linux
74 struct IgHookTraceArgs
90 static _Unwind_Reason_Code
91 GCCBackTrace (_Unwind_Context *context,
void *arg)
93 IgHookTraceArgs *
args = (IgHookTraceArgs *) arg;
94 if (
args->stack.top < 0 ||
args->stack.top >=
args->stack.size)
95 return _URC_END_OF_STACK;
97 args->stack.addresses [
args->stack.top++] = (
void *) _Unwind_GetIP (context);
98 args->prevframe = (
void **) _Unwind_GetCFA (context);
99 return _URC_NO_REASON;
120 size_t psize = getpagesize();
121 size_t hunk = psize * 20;
122 if ( hunk < bytes ) hunk = ( hunk + psize - 1 ) & ~( psize - 1 );
123 void* addr = mmap( 0, hunk, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 );
124 if ( addr == MAP_FAILED )
return 0;
140 return alloc ? alloc->allocate(
n ) : ::operator
new(
n );
144 unsigned long long value )
145 : m_counter(
counter ), m_next( next ), m_value( value ), m_count( 0 ) {}
167 return m_value += value;
172 return m_value -= value;
177 if ( m_value < value ) m_value = value;
203 return alloc ? alloc->allocate(
n ) : ::operator
new(
n );
222 bool IgHookTrace::symbol(
void* address,
const char*& sym,
const char*& lib,
int& offset,
int& liboffset ) {
225 liboffset = (
unsigned long)
address;
228 if ( dladdr(
address, &info ) ) {
229 if ( info.dli_fname && info.dli_fname[0] ) lib = info.dli_fname;
231 if ( info.dli_fbase ) liboffset = (
unsigned long)
address - (
unsigned long)info.dli_fbase;
233 if ( info.dli_saddr ) offset = (
unsigned long)
address - (
unsigned long)info.dli_saddr;
235 if ( info.dli_sname && info.dli_sname[0] ) sym = info.dli_sname;
249 return ( dladdr(
address, &info ) && info.dli_fname && info.dli_fname[0] && info.dli_saddr ) ? info.dli_saddr