segmented memory models
ethan.dicks at usap.gov
Mon Aug 4 19:14:08 CDT 2008
On Mon, Aug 04, 2008 at 05:06:17PM -0400, Sean Conner wrote:
> > I wasn't aware that this was a requirement of C, or any other language.
> The C Standard say the token "0" (in a pointer context) is to be
> translated to a null address in the target architecture, and in most
> implementations, that address is indeed 0, but it doesn't have to be.
> Also, dereferencing such a pointer causes undefined behavior, which means
> what happens really depends upon the C compiler and underlying hardware.
I ran into this when someone at Lucent ported a simple utility from an
NCR Unix box to a Sun box - somewhere, someone was dereferencing a null
pointer (getting strlen() perhaps?)... on the NCR box, the implementation
treated the length of a null pointer as the same as a pointer to a null
(character). On the Solaris machine, it threw a segfault.
It took me a bit of time to convince the guys that both implementations
were valid and that it wasn't a "Solaris bug".
This particular implementation issue is, IIRC, one reason the Amiga
puts a $00000000 at $0000000 (and uses $00000004 as its "ExecBase"
pointer location)... the two ways to catch these sorts of user code
issues are to either stuff something like $DEADBEEF at $00000000
or to use Enforcer to trip up your program if you try to dereference
a null pointer (presuming your development platform has an MMU, of
course). Either way, you'll quickly find null-pointer derefs and
be able to take them out to avoid "undefined behavior".
Ethan Dicks, A-333-S Current South Pole Weather at 5-Aug-2008 at 00:00 Z
South Pole Station
PSC 468 Box 400 Temp -75.8 F (-59.9 C) Windchill -112.0 F (-80.0 C)
APO AP 96598 Wind 9.9 kts Grid 28 Barometer 672.2 mb (10924 ft)
Ethan.Dicks at usap.gov http://penguincentral.com/penguincentral.html
More information about the cctalk