Пример #1
0
static void *
do_malloc (size_t size, int to_skip)
{
	void *result;
	MIInfo info;

	/* It's possible to get recursion here, since dlsym() can trigger
	 * memory allocation. To deal with this, we flag the initialization
	 * condition specially, then use the special knowledge that it's
	 * OK for malloc to fail during initialization (libc degrades
	 * gracefully), so we just return NULL from malloc(), realloc().
	 *
	 * This trick is borrowed from from libc's memusage.
	 */
	if (!mi_check_init ())
		return NULL;

	result = (*old_malloc) (size);

	if (mi_tracing ()) {
		info.alloc.operation = MI_MALLOC;
		info.alloc.old_ptr = NULL;
		info.alloc.new_ptr = result;
		info.alloc.size = size;

		mi_call_with_backtrace (to_skip + 1, mi_write_stack, &info);
	}
		
	return result;
}
Пример #2
0
static void
do_free (void  *ptr)
{
	MIInfo info;

	if (!mi_check_init ())
		return;

	(*old_free) (ptr);

	if (mi_tracing ()) {
		info.alloc.operation = MI_FREE;
		info.alloc.old_ptr = ptr;
		info.alloc.new_ptr = NULL;
		info.alloc.size = 0;

		mi_call_with_backtrace (2, mi_write_stack, &info);
	}
}
Пример #3
0
static void *
do_memalign (size_t boundary, size_t size)
{
	void *result;
	MIInfo info;

	if (!mi_check_init ())
		abort_unitialized ("memalign");

	result = (*old_memalign) (boundary, size);

	if (mi_tracing ()) {
		info.alloc.operation = MI_MALLOC;
		info.alloc.old_ptr = NULL;
		info.alloc.new_ptr = result;
		info.alloc.size = size;
	
		mi_call_with_backtrace (2, mi_write_stack, &info);
	}

	return result;
}
Пример #4
0
static void *
do_realloc (void *ptr, size_t size)
{
	void *result;
	MIInfo info;

	if (!mi_check_init ())
		return NULL;/* See comment in initialize() */

	result = (*old_realloc) (ptr, size);

	if (mi_tracing ()) {
		info.alloc.operation = MI_REALLOC;
		info.alloc.old_ptr = ptr;
		info.alloc.new_ptr = result;
		info.alloc.size = size;
	
		mi_call_with_backtrace (2, mi_write_stack, &info);
	}

	return result;
}
Пример #5
0
sigprof_handler (int unused)
#endif
{
	int saved_errno = errno;
	MIInfo info;

	info.alloc.operation = MI_TIME;
	info.alloc.old_ptr = NULL;
	info.alloc.new_ptr = NULL;
	info.alloc.size = 1;
    
#if defined (__linux__)
	mi_call_with_signal_backtrace ((void *)ctx.EIPRIP, (void *)ctx.EBPRBP,
					(void *)ctx.ESPRSP, mi_write_stack, &info);
#else
	mi_call_with_backtrace (SIGHANDLER_FRAMES, saved_pc, mi_write_stack, &info);
#endif

	if (profile_type == SPEED_PROF_ITIMER)
		reset_itimer_timer ();
	errno = saved_errno;
}