Referencing NULL pointers
Jonathan I. Kamens
jik at athena.mit.edu
Mon Jul 24 05:10:17 AEST 1989
We're using something here at Project Athena which the compiler gurus
call "Z0MAGIC" -- I don't know whether it's something they picked up
from somewhere or something they wrote themselves. I believe we have
it installed on both our VAX and RT compilers.
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. It's great for debugging,
because it won't let any null pointer references slip by. The blurb
about it from our ld(1) man page is as follows (the English seems to
be a bit scrod at the fourth line, but you get the idea):
-Z Similar to -z format except for two things: (1) the
magic number is 0420, (2) the first page of the text
segment is filled with zeros and the entry point is
immediately following instead of an offset of 0. (The
offset is 1024 on the VAX, 2048 on the RT). The kernel
doesn't map page 0, so a reference to NULL causes a bus
error on the VAX and segmentation violation on IBM RT
and SUN architectures.
I believe that the original code for this came from off of the net
somewhere, but we've done a lot of work with it to get it to work on
both the VAX and RT (it was originally only for the VAX), and to fix
some other problems.
No, I don't know where it originally came from. And no, I don't know
if we're allowed to redistribute it, although I just asked somebody
and I may get an answer back eventually.
(Now, I've never had to use it, of course, since I never dereference
null pointers. :-)
Jonathan Kamens USnail:
MIT Project Athena 432 S. Rose Blvd.
jik at Athena.MIT.EDU Akron, OH 44320
Office: 617-253-4261 Home: 216-869-6432
More information about the Comp.unix.wizards
mailing list