Re: Kernel loaded at top of memory

From: Floyd Davidson (floyd_at_barrow.com)
Date: 02/04/04


Date: Wed, 04 Feb 2004 07:26:01 -0900

John Reiser <jreiser@BitWagon.com> wrote:
>
>> The NULL pointer is also interesting.
>> Considering that the NULL pointer points to the
>> virtual address 0, ...

Not necessarily.

NULL is a macro (a source code device), which when used in a
pointer context will result in the compiled program producing a
/null/ /pointer/ (a implementation defined device). A /null/
/pointer/ is *guaranteed* not to point at a valid object. It is
*not* guaranteed to be a pointer to address 0, and in fact may
or may not actually point at that, or any, address.

>The UNIX SystemVr4 ABI requires that it be _possible_ for a read/write/
>execute page to exist at address 0; mmap(0,,,MAP_FIXED,,) must succeed
>if otherwise OK. Some software depends on (0==*(char *)0), and other code
>can take advantage of (0==*(int *)0).

Software which depends on either of the above expressions is
seriously *broken*.

Conversion of a "null pointer constant", such as the integer 0,
to a pointer results in the /null/ /pointer/ described above.
Both of the two above expressions involve doing exactly that,
and the pointer which results is *guaranteed* not to point at
any valid object. Dereferencing that pointer to an invalid
object is undefined behavior.

--
Floyd L. Davidson           <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@barrow.com


Relevant Pages

  • Re: The difference between 0 and NULL?
    ... >> pointer value is all zeros. ... If the OS thinks memory at address 0 is okay, ... >> I copy my valid object to the pointer with the zero address. ...
    (comp.unix.programmer)
  • Re: about NULL as a parameter to a libc function
    ... pointer to a valid object will ever return a null pointer. ... Note, too, that it's perfectly acceptable to have NULL point to a "valid" address, as long as no valid object can be at that address. ... memory). ... You can read/write it correctly. ...
    (comp.lang.c)
  • Re: struct and pointer question
    ... unless the pointer is actually pointing to a valid object of ... the correct type, the result is undefined. ... There is one exception to ... char pointer. ...
    (comp.lang.c)
  • Re: The difference between 0 and NULL?
    ... > I copy my valid object to the pointer with the zero address. ... > I suspect that the result will be true on many systems. ...
    (comp.unix.programmer)
  • Re: C Standard Regarding Null Pointer Dereferencing
    ... to a valid object and so does incrementing that pointer by '20'. ... Type is not all there is to a pointer. ... Also, if only "an array object" is specified, it ... If an implementation attempts to keep track of the 'int *'-typed ...
    (comp.lang.c)