|
|
|
|
|
|
| Author |
Message |
vishal_study@yahoo.com *nix forums beginner
Joined: 10 Nov 2005
Posts: 1
|
Posted: Thu Nov 10, 2005 8:46 pm Post subject:
mechanism behind segmentation violation
|
|
|
Hi:
When someone tries to dereference a NULL pointer, we get segmentation
violation.
Can someone please let me know the mechanism behind it? I mean how is
this mechanism implemented in kernel.
I have seen a private kernel/OS in which dereferencing a null pointer
doesn't lead to exception. Hence the developers have to be more
careful...
Question (again):
How is this mechanism to generate SEGV on dereferncing a null pointer
implemented? Any pointers would be greatly appreciated.
Thanks,
Vishal. |
|
| Back to top |
|
 |
Barry Margolin *nix forums Guru
Joined: 24 Feb 2005
Posts: 323
|
Posted: Fri Nov 11, 2005 1:30 am Post subject:
Re: mechanism behind segmentation violation
|
|
|
In article <1131655600.104821.192150@f14g2000cwb.googlegroups.com>,
"vishal_study@yahoo.com" <vishal_study@yahoo.com> wrote:
| Quote: | Hi:
When someone tries to dereference a NULL pointer, we get segmentation
violation.
Can someone please let me know the mechanism behind it? I mean how is
this mechanism implemented in kernel.
|
It's done by not mapping the zero page into the process's memory, or
turning off both its read and write permissions in the page table entry.
When a user-mode process tries to read anything on this page, it traps
into the kernel in the same way that it would if you used some other
invalid pointer. The kernel processes this trap by setting the
segmentation violation bit in the process's signals.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me *** |
|
| Back to top |
|
 |
junky_fellow@yahoo.co.in *nix forums addict
Joined: 19 Jul 2005
Posts: 78
|
Posted: Thu Dec 08, 2005 3:09 pm Post subject:
Re: mechanism behind segmentation violation
|
|
|
vishal_study@yahoo.com wrote:
| Quote: | Hi:
When someone tries to dereference a NULL pointer, we get segmentation
violation.
Can someone please let me know the mechanism behind it? I mean how is
this mechanism implemented in kernel.
I have seen a private kernel/OS in which dereferencing a null pointer
doesn't lead to exception. Hence the developers have to be more
careful...
Question (again):
How is this mechanism to generate SEGV on dereferncing a null pointer
implemented? Any pointers would be greatly appreciated.
|
Any attempt to dereference a null pointer invokes undefined behavior.
However, it's entirely possible (for a given implementation) that
there is an
addressible memory location at address all-bits-zero, and that a C
program is able to
access it by dereferencing a null pointer.
SIGSEGV may be generated on dereferencing the Null pointer, by not
mapping
the NULL pointer address to user address space. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Tue Dec 02, 2008 3:53 pm | All times are GMT
|
|
Home Loan | Bleach 149 . Bleach 150 | Personal Loans | Problem Mortgage | Adverse Credit Remortgage
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|