RE: Segmentation fault


Subject: RE: Segmentation fault
From: Jan Zumwalt (jwzumwalt@neatinfo.com)
Date: Sat Jan 18 2003 - 19:55:13 AKST


What happens is the same for all CPU's, but how it is handled depends on the
Architecture that the CPU was designed under. The short answer is a program
is attempting to use unauthorized memory, the long answer follows :)

What Happens:
        Segmentation errors are when the program try's to access or use memory that
it has neither the right or permission to use. For example a C program may
request blocks of memory for its use, this is commonly called the heap. If
the C program asked for 1000 bytes (1k) to hold a address data base, but
attempted to use 2000 bytes (2k), a seg fault will occur. In most cases this
is considered a critical error and the program is killed by the OS -
sometimes the CPU will lock up.

How it's handled:
How the fault gets handled depends on the cooperation of the CPU designer
and OS programmer. In the case of Intel chips, there is hardware memory
police called the Segmentation Registers that always keeps track of what
memory a program is allowed. The seg register memory points to a small
internal table and/or large external table of memory blocks that the program
may use. A request for unauthorized memory even if OK'ed by the OS will
NEVER get past the seg registers. You can think of the seg registers as a
literal pass key to the memory bus. If the address is not one of the
authorized memory blocks the program has been given permission, the seg
registers will prevent (lock out physically) the address bus from working.
Pretty cool, and fool proof!
It would be nice if that was all there was to a seg faults, but it is not.
When a seg fault occurs on Intel CPU's the CPU goes into panic mode and
thinks a serious security violation is being attempted. The first seg fault
causes the CPU to warn the OS that a security violation has occurred and
gives the OS one chance to correct the problem - this usually means the OS
shuts the program down and sends the seg fault error to the screen. If the
seg fault happens again, the CPU interrupts this as an unstable Commander
(Communist?) in Chief at the Helm of the ship and promptly re-boots - no
third chance to correct things.
In the days of DOS, Windows 95, and NT, this unexpected reboot was what was
happening, this is called a "hard" violation (two strikes, your OUT!).
Microsoft and Unix now have proper error catching to never (we hope) allow a
program to seg fault twice. It is note worthy that for many years Intel did
not have a reboot opp code in the Pentuim repetuir. The way a program would
reboot dos or windows 3.1 was to deliberately cause a "double fault". The
two common ways of doing this was to send either two divide by zero commands
back to back, or send a double request for unauthorized memory and create
seg faults. Now Intel has a op code for re-booting - and you guessed it...
It creates a double fault for you!

Jan Zumwalt

-----Original Message-----
From: aklug-bounce@aklug.org [mailto:aklug-bounce@aklug.org]On Behalf Of
Adam Elkins
Sent: Saturday, January 18, 2003 3:57 PM
To: aklug@aklug.org
Subject: Segmentation fault

What causes segmentation faults?
with all the vmware talk, I thought I'd give it a try....
It installs fine (Slack 8.1), and I can run the vmware-wizzard to set up a
virtual disk, but when I run 'vmware' all I get is "Segmentation fault"
Since slack isn't a "supported" distro, I can't find anything on their site
about this, nor on google.

Adam Elkins.

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Sat Jan 18 2003 - 19:52:22 AKST