On Saturday 21 July 2001 04:02, Abraham Mandac wrote:
> I don't know if this is a stupid question:
> What exactly is a segmentation fault?


The 8086 when first introduced had 16-bit registers and a whopping 1-Megabyte 
Address space.  Since the registers contained only 16 bits, their maximum 
addressable range was from 0 to 2 to the power 16 minus one, or 65535, a 
total of 65536 or 64x1024 (64K).  Four special registers were created, also 
16 bits long, called segment registers, Code Segment, Data Segment, Stack 
Segment, and Extra Segment.  They added with other registers and immediate 
data to form 20-bit addresses because they were used offset four bits to the 
left in addressing mode though their data loading and saving was done along 
the 16-bit bus.  Thus 2 to the power 20 bytes could be addressed, but only by 
changing data in segment registers.  Memory was four not always discrete 
chunks of 64k each addressable without changing the value of segment registers

Anyway, when an address would calculate with an offset from the segment 
pointer that could not be achieved with a 16-bit register, basically an 
impossible to get to address, then a segment violation or segment fault had 
occurred and the processor (mostly 4.77 MHz 8088s in those days) would 
continue on its merry way, blissfully unaware that it had committed a faux 
pas, (but of course program results would become unpredictable).

And yes, running in real mode, we are still stuck with this clumsiness.  
Running in protected mode, it is a little different, but memory addressing is 
still a rough spot in the scheme of things.  So the segfault is still with 
us, but now it is noticeable by the processor, because pograms have segments 
of memory allocated to them, and when an address calculates outside those 
segments...



segmentation fault n. 

[Unix] 1. [techspeak] An error in which a running program attempts to access 
memory not allocated to it and core dumps with a segmentation violation 
error. This is often caused by improper usage of pointers in the source code, 
dereferencing a null pointer, or (in C) inadvertently using a non-pointer 
variable as a pointer. The classic example is:   

int i;
   scanf ("%d", i);  /* should have used &i */

2. To lose a train of thought or a line of reasoning. Also uttered as an 
exclamation at the point of befuddlement. 


segv /seg'vee/ n.,vi. 

 Yet another synonym for segmentation fault (actually, in this case, 
`segmentation violation'). 

Civileme

Reply via email to