niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Unix internals
mechanism behind segmentation violation
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
vishal_study@yahoo.com
*nix forums beginner


Joined: 10 Nov 2005
Posts: 1

PostPosted: Thu Nov 10, 2005 8:46 pm    Post subject: mechanism behind segmentation violation Reply with 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.

Thanks,
Vishal.
Back to top
Barry Margolin
*nix forums Guru


Joined: 24 Feb 2005
Posts: 323

PostPosted: Fri Nov 11, 2005 1:30 am    Post subject: Re: mechanism behind segmentation violation Reply with quote

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

PostPosted: Thu Dec 08, 2005 3:09 pm    Post subject: Re: mechanism behind segmentation violation Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Tue Dec 02, 2008 3:53 pm | All times are GMT
navigation Forum index » Programming » Unix internals
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Access violation in QueryBrowser Vittorio Zuccalà MySQL 0 Thu Jul 20, 2006 2:49 pm
No new posts vary caching issue (segment violation 2.6/STABLE1, Solari... Bertold Kolics Squid 1 Tue Jul 18, 2006 3:44 pm
No new posts Segmentation fault with perl 5.8.8 JyGius modules 0 Tue Jul 11, 2006 10:03 am
No new posts Segmentation faulty Tree - aptitude jb701@uku.co.uk Debian 2 Sat Jul 08, 2006 8:10 pm
No new posts segmentation fault with SSLCertificateChainFile Matteo Corti Apache 2 Tue Jul 04, 2006 2:59 pm

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
[ Time: 0.1509s ][ Queries: 16 (0.0745s) ][ GZIP on - Debug on ]