29.01.2014 Views

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 6. OVERRIDING FUNCTIONS 50<br />

# include <br />

# include <br />

../test/tut6.c<br />

int counter = 0;<br />

pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;<br />

int main()<br />

{<br />

toggle_lock_tracking();<br />

pthread_mutex_lock(&mtx);<br />

counter++;<br />

pthread_mutex_unlock(&mtx);<br />

return 0;<br />

}<br />

Now, we can compile this test by doing:<br />

$ ciltutcc --enable-tut6 -lpthread -o tut6 test/tut6.c<br />

Then, when we run tut6, we should get something similar to the following output:<br />

$ ./tut6<br />

thread:<br />

thread:<br />

32646 - pthread mutex lock(0x602180)<br />

32646 - pthread mutex unlock(0x602180)<br />

6.5 Further Reading<br />

Many researchers have studied overriding memory allocation calls (along with the instrumentation<br />

<strong>of</strong> some memory accesses) with the goal <strong>of</strong> catching memory management errors. Examples are<br />

Libsafe [2], LibsafePlus [1], and HeapShield [3] (which is a part <strong>of</strong> DieHard [4]).<br />

The Trickle [5] userspace bandwidth shaper operates by using the dynamic linker to override IO<br />

calls with ones that track the number <strong>of</strong> bytes sent per unit time. Then, it puts the calling process<br />

to sleep when the sending or receiving rate exceeds a user given limit.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!