Discussion:
Reverse Zero address for null reference
(too old to reply)
c***@CSIC.UMD.EDU
2005-10-25 01:47:27 UTC
Permalink
If i reserve zero address for null reference

then i wont be able to use an entire page unless i can alter the
size of one page by 1 byte (and make an exception)

In other words, if the size of memory is 8KB then i should have
2048 pages however, the effective pages that i could use will be
2047 or i have to alter the page size( which i think is a bad
idea )

Please let me know if i am going in the right direction.
Iulian Neamtiu
2005-10-25 02:31:54 UTC
Permalink
I'm not sure I understand what your concern is, but leaving out
page 0 in order to catch NULL pointer dereferences is trivial:
You have to tell the paging unit that linear adresses in the first linear
page (0-4KB linear) are 'not present' in physical memory.
This means you just have to set
the associated page table entry to all 0's. No part of the kernel
tries to access that 0-4KB linear range, and if it does it's because of
some bug.
By setting the entry to all 0's you'll get a "page not present" when you
try to dereference a NULL pointer or when you do a structure
dereference (p->i, when p is NULL).

The first *physical* page, i.e. 0-4KB physical is unavailable anyway,
if you look at mem.c::Init_Mem() you see it's marked PAGE_UNUSED, (not
PAGE_AVAIL) hence it cannot be used to back virtual memory anyway.

Iulian
Post by c***@CSIC.UMD.EDU
If i reserve zero address for null reference
then i wont be able to use an entire page unless i can alter the
size of one page by 1 byte (and make an exception)
In other words, if the size of memory is 8KB then i should have
2048 pages however, the effective pages that i could use will be
2047 or i have to alter the page size( which i think is a bad
idea )
Please let me know if i am going in the right direction.
Iulian Neamtiu
2005-10-25 14:29:55 UTC
Permalink
... a corollary of this is to always wipe out (i.e. memset to 0)
a page before using it for page directories/page tables. This way, when
you do a wild read (or write) at some point in the future, you'll get a
'page not present' exception, rather than some weird error.

Iulian
Post by Iulian Neamtiu
I'm not sure I understand what your concern is, but leaving out
You have to tell the paging unit that linear adresses in the first linear
page (0-4KB linear) are 'not present' in physical memory.
This means you just have to set
the associated page table entry to all 0's. No part of the kernel
tries to access that 0-4KB linear range, and if it does it's because of
some bug.
By setting the entry to all 0's you'll get a "page not present" when you
try to dereference a NULL pointer or when you do a structure
dereference (p->i, when p is NULL).
The first *physical* page, i.e. 0-4KB physical is unavailable anyway,
if you look at mem.c::Init_Mem() you see it's marked PAGE_UNUSED, (not
PAGE_AVAIL) hence it cannot be used to back virtual memory anyway.
Iulian
Post by c***@CSIC.UMD.EDU
If i reserve zero address for null reference
then i wont be able to use an entire page unless i can alter the
size of one page by 1 byte (and make an exception)
In other words, if the size of memory is 8KB then i should have
2048 pages however, the effective pages that i could use will be
2047 or i have to alter the page size( which i think is a bad
idea )
Please let me know if i am going in the right direction.
Continue reading on narkive:
Loading...