void * __terminal_hook_memalign(size_t boundary, size_t size, const void *caller)
{
	static void *(*real_memalign)(size_t, size_t);
	if (!real_memalign) real_memalign = fake_dlsym(RTLD_DEFAULT, "__real_memalign");
	if (!real_memalign) real_memalign = fake_dlsym(RTLD_DEFAULT, "memalign"); // probably infinite regress...
	if (!real_memalign) abort();
	return real_memalign(boundary, size);
}
Beispiel #2
0
void* memalign(size_t blocksize, size_t bytes)
{
	void *ptr;
	START_CALL();
	ptr = real_memalign(blocksize, bytes);
	END_CALL(ptr, bytes);
	return ptr;
}
Beispiel #3
0
void *memalign(size_t boundary, size_t size)
{
	struct log_malloc_s *mem;
	sig_atomic_t memuse;
	sig_atomic_t memruse = 0;

	if(!DL_RESOLVE_CHECK(memalign))
		return NULL;

	if(boundary > MEM_OFF)
		return NULL;

	if((mem = real_memalign(boundary, size + MEM_OFF)) != NULL)
	{
		mem->size = size;
		mem->cb = ~mem->size;
		memuse = __sync_add_and_fetch(&g_ctx.mem_used, mem->size);
#ifdef HAVE_MALLOC_USABLE_SIZE
		mem->rsize = malloc_usable_size(mem);
		memruse = __sync_add_and_fetch(&g_ctx.mem_rused, mem->rsize);
#endif
	}
#ifndef DISABLE_CALL_COUNTS
	(void)__sync_fetch_and_add(&g_ctx.stat.memalign, 1);
	g_ctx.stat.unrel_sum++;
#endif

	if(!g_ctx.memlog_disabled)
	{
		int s;
		char buf[LOG_BUFSIZE];

		s = snprintf(buf, sizeof(buf), "+ memalign %zu %p (%zu) [%u:%u]\n",
			size, MEM_PTR(mem),
			boundary, 
			memuse, memruse);

		log_trace(buf, s, sizeof(buf), 1);
	}
	return MEM_PTR(mem);
}