Referencing NULL pointers

Chris Lewis clewis at eci386.uucp
Tue Jul 25 05:30:48 AEST 1989


In article <12928 at bloom-beacon.MIT.EDU> jik at athena.mit.edu (Jonathan I. Kamens) writes:
>We're using something here at Project Athena which the compiler gurus
>call "Z0MAGIC" 
>
>What it does is, if the -Z flag is specified to the linker, cause any
>executing program to unmap page zero so that dereferencing null
>pointers will always cause a segfault.

Many moons ago, (Hi Dennis!), one of the development groups I worked
with wrote a sed script to parse assembler output from the C compiler, 
and when it detected indirections, inserted a sequence of instructions before
the reference to check the pointer for null and abort.  Then wrote
a shell script around it that would "cc -S", sed, and then assemble (analogous
to "cc -c" with an extra step).

This was on a VAX, running BSD4.1.  This was a pretty gruesome hack, so
gruesome that I never bothered to look at the fine details.  
They figured, so what if it ran slow - it was only used to run debug 
versions (the target trapped null dereferences by not mapping location 0).

This idea might be useful to those not having kernel source.
-- 
Chris Lewis, R.H. Lathwell & Associates: Elegant Communications Inc.
UUCP: {uunet!mnetor, utcsri!utzoo}!lsuc!eci386!clewis
Phone: (416)-595-5425



More information about the Comp.unix.wizards mailing list