Wednesday, August 5, 2009

what does segmentation fault mean?

Probably the best explanation of program memory I have seen is this article:
Anatomy of a Program Memory

Once you understand the program memory, you get a better idea what causes a "segmentation fault:

In summary, the major reasons for a segmentation fault are:

a) Trying to read from or write to addresses in kernel space of your program memory.
b) Trying to feed to push to the stack more data that it can fit.
c) Trying to write to the text segment of the process memory (text segment is where the binary image of the process is stored).
d) Trying to access unallocated memory.
When you ask for memory from the OS, the kernel creates an entry for you in the VMA - Virtual Memory Area. If you try to access a address in the memory and not suitable VMA exists for it, your program is going to have the segmentation fault.

No comments: