Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.wizards Subject: Re: Referencing NULL pointers Message-ID: <12928@bloom-beacon.MIT.EDU> Date: 23 Jul 89 19:10:17 GMT References: <1989Jul14.092231.24845@inquiry.org> <19367@paris.ics.uci.edu> <10515@smoke.BRL.MIL> <168@jma.UUCP> <1501@ibmpa.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 36 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@Athena.MIT.EDU Akron, OH 44320 Office: 617-253-4261 Home: 216-869-6432