writing mudflap wrappers

Eyal Lebedinsky eyal@eyal.emu.id.au
Tue Apr 22 17:10:00 GMT 2003


I figured it is time to learn how to write these. I started with the
ones I actually need, and picked the io functions first.

I think I understand how it works, however I see that there are some
interactions that I did not forsee.

For example, validating the stream argument is non-trivial. I found
that some file handles are static (stdin etc.) and cannot be checked
without first being registered (somewhere in the init code?). Moreover,
registering fopen() results is wrong - it seems that libc allocates
it dynamically and the hooks pick it up. So now I need to find a way
to unregister this memory so that any use of the file handle will
trigger an error, and I want this even when libs did not actually
free the area.

BTW, when I tried to register on open() and unreg on close() I did
not get a violation in the open() but did get one at the close().
When I removed the reg/unreg code the handles validated just fine,
indicating the mf did track this memory. Does mf accept multiple
registration of memory?

A final question. I am developing on Linux/i386. The wrappers
I write are correct for this platform, but I do not know that all
will work on other platforms. How should I protect the wrappers?
I mean, if this stuff gets checked in, it may break the build
on untested platforms. I prefer to wrap new code with some #if
and then allow each port to enable it and test as they wish. Is
this how it should be done? What is the "correct" way here?

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>



More information about the Gcc mailing list