Segmentation Fault

The Unix and CeePlusPlus way of spelling DoesNotUnderstand.

Most often seen as a result of attempting to dereference a broken or null pointer.

Also known as a SegFault.


SegmentationFault is the error which arises when a program tries to access a memory address to which it is not allowed access (if the hardware and OS provide MemoryProtection?, that is). SegFault is a UnixOperatingSystem term; in the Windows world, the terms GeneralProtectionFault and AccessViolation? are used.

http://www.catb.org/~esr/jargon/html/entry/segmentation-fault.html

The name derives from the fact that unix organises memory into virtual memory pages or segments, each potentially with its own read and write permissions; writing to a page marked read-only, or reading from a page that does not allow reading, will cause a hardware interrupt which is translated by the kernel into a software interrupt: a SegmentationViolation? signal.

The word "segment" dates to the 1970s, when Unix ran on systems (e.g. the pdp11, and later, the 80286 and 80386) that did not have virtual memory paging, but did have a small number of memory protected "segments"; the two terms are sometimes used synonymously, other times they are used in contrast. When contrasted, typically all "pages" on a system have the same size (e.g. 8192 bytes), while "segments" typically are variable length. [See Note 1]

Also the term "page" tends to imply hardware supported virtual memory, that allows pages to be loaded on demand, in response to a hardware interrupt on attempted access (in which case no signal is delivered to the user process), whereas the older "segment" implied hardware memory protection but no ability to demand-load pages; instead entire processes were swapped in and out of memory.

Compare with "bus error", the software signal (standard value 7) that means that, although the memory page was potentially accessible according to its read/write permissions, the attempted memory access caused the hardware to complain with an interrupt. This occurs most often on a RISC machine when word-oriented memory is accessed on a non-word-aligned boundary. It can also happen when non-existent or buggy memory is mapped into the address space.

C programmers can spend their whole careers in environments where Bus Error never happens, since it depends on the nature of the machine and details of the kernel implementation. Also some Unix kernels arbitrarily decide to deliver all such hardware complaints as Segmentation Violations, so it's not guaranteed that one can get a Bus Error on any architecture.

Related signals that are translations of hardware conditions:

SIGILL - illegal instruction (e.g. cpu doesn't recognize opcode)

SIGTRAP - trap ("interrupt") from user space to kernel space (some CPUs have special instructions to do this, typically used to implement system calls; this can indicate e.g. a trap instruction not used by convention for a system call)

SIGIOT - IO trap : error during execution of IO instruction (not all CPUs have such instructions) (Some CPUs only execute IO instructions in "supervisor mode". When a user-mode program tries to execute such instructions, the hardware traps it, switches to supervisor mode, and lets the OS handle it. Some paranoid OS assume the program is up to no good and/or has started executing random data -- so the OS kills that user-mode program. Other OS that need to run legacy applications emulate the instruction and return to the program -- this allows me to run ancient legacy applications that were designed to print by diddling with the parallel port hardware, but now I can tell the OS to print to a network printer or email a PostScript file. That's more than you needed to know -- sorry.)

SIGFPE - interrupt triggered by floating point unit; typically floating point divide by zero.

See /usr/include/*/signal.h for definitions (not descriptions), e.g. on Linux /usr/include/asm/signal.h

SegmentationFault is the way a static-typed system spells DoesNotUnderstand.


Whatever happened to the comic strip http://segfault.org/ ?


NOTES:

1. The term "segment" has a very specific use in the world of Intel X86 CPU architecture. X86 machines determine address access by applying two overlapping 16-bit (or larger) registers. The high order register determines the "segment" of memory that is being accessed, offset to the left by four (or more) bits. The low order register is then added to this offset to determine the final address.


See: DoesNotUnderstand, NullPointerException, GeneralProtectionFault, TechnicalFailure

CategoryHardware


EditText of this page (last edited April 6, 2012) or FindPage with title or text search