[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Somw questions [ MAYBE OFFTOPIC ]



Hi,

On Mon, 5 Apr 1999 05:12:50 -0400 (EDT), Amol Mohite
<amol@m-net.arbornet.org> said:

>> A NULL pointer is just yet another invalid address.  There is no
>> special test for a NULL pointer.  Most probably for example (char
>> *)0x12345678 will be invalid as a pointer as well and treated the
>> same.  The CPU detects this when the TLB doesn't have a translation
>> valid for the access being attempted.

> Yes but how does it know it is a null pointer ?

It doesn't.  It just looks up the current VM page tables and looks for
the mapping for that page.  If there isn't such a mapping, it just
invokes a page fault handler in the O/S.

It is then up to the kernel to decide whether the pointer was just a
page which is swapped out, or a real invalid pointer.  If the kernel has
a mapping installed for that address, then it can install a valid page
in the process's address space and, if necessary, read the appropriate
page of disk to initialise it (for mmap or swap).  Otherwise, it just
generates a SEGV signal.

> On that note, when c does not allow u to dereference a void pointer , is
> this compiler  doing the trick ?

It is undefined in C.  Dereferencing a null pointer might return zero,
might return garbage or might generate a SEGV; the language doesn't do
anything special about it.  It is all up to the operating system.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/