Subject: Re: NULL return value checking
To: Greywolf <>
From: Robert Elz <kre@munnari.OZ.AU>
List: tech-kern
Date: 04/25/2002 16:28:38
    Date:        Wed, 24 Apr 2002 09:02:26 -0700 (PDT)
    From:        Greywolf <>
    Message-ID:  <>

  | That's certainly convenient, to say the least.  Wonder what the linker's
  | doing in there on machines where 
  | 	(void *) 0 != (pointer_width_but_not_pointer) 0
  | ...or does the kernel exec code worry about that?

Where 0 is a valid address (as defined by the architecture and kernel
together) the linker needs to make sure that nothing that can ever be
validly referenced from a C program gets put there.   Typically, that's
done by sticking the beginning of crt0 at 0 - it has no name defined which
can be referenced from C code, so (aside from p = 0;) there's no way for
a C program to get a pointer that points there - and the memory is allocated,
so clearly malloc() and friends will never be fooled.   It doesn't matter
how it is done, it just has to be.  On split I/D systems (where crt0 could
take care of the instr zero address, but not the data) the linker would
typically simply create an unnamed dummy variable and stick that in the D
space address 0 (ie: waste 2 bytes - or sometimes just 1).   If it turns out
that 0 is left in the space that could be allocated by brk() (which is hard
to imagine the way that is defined) or by mmap() then those routines would
need to watch for that, and handle it (I've never seen a system like that,
I doubt one exists).