Advertisement

05.12.2008 at 12:46AM PDT, ID: 23393869
[x]
Attachment Details

intercept library calls

Asked by pothios in C Programming Language

Tags: c

Hi, i have am trying to intercept calls to malloc and calloc and display but im having some problems. Things starts to go wrong when calloc is called..

calloc x x x
malloc x x

print reuslts:
m x x
c x x x
m x x

should be:
c x x x
m x x

i think this is caused by calloc calling melloc... the question is, how do i ignore the calls of melloc within calloc?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
void* malloc(size_t size)
{
    static void* (*func)(size_t);
	char str[200];
        void *r;
 
    if(!func) {
	func = (void * (*)(size_t))dlsym(RTLD_NEXT, "malloc");
    }
	r = func(size);
	if(firstRun) {
		start_print();
		firstRun = 0;
	}
	printf("m %p %i\n", r, size);
    return r;
}
 
void* calloc(size_t nelem, size_t elsize)
{
	static void* (*func)();
	char str[200];
	void *r;
	if(!func) {
		func = (void*(*)())dlsym(RTLD_NEXT, "calloc");
	}
	r = func(nelem, elsize);
	printf("c %p %d %d\n", r, nelem, elsize);
	return r;
}
[+][-]05.12.2008 at 12:52AM PDT, ID: 21545197

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: c
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.12.2008 at 12:56AM PDT, ID: 21545211

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628