Segmentation Faults
On the first set of notes for this week, we had a process running that motivated this week’s notes. We left it in the following state:
RAM:
| [0] | programCode (1/5) |
| [1] | (heap memory data) |
| [2] | programCode (2/5) |
| [3] | (heap memory data) |
P1 Page Table:
| [0] | (empty) |
| [1] | ==> ram[0], disk[42] |
| [2] | ==> ram[2], disk[43] |
| [3] | ==> disk[44] |
| [4] | ==> disk[45] |
| [5] | ==> disk[46] |
| [6] | (empty) |
| [7] | (empty) |
| [8] | (heap memory) ==> ram[1] |
| [9] | (heap memory) ==> ram[3] |
| [10] | (heap memory) |
| [11] | (heap memory) |
| [12] | (empty) |
| [13] | (empty) |
| [14] | (empty) |
| [15] | (empty) |
Hard Drive:
| ... | (empty) |
| [41] | (empty) |
| [42] | programCode (1/5) |
| [43] | programCode (2/5) |
| [44] | programCode (3/5) |
| [45] | programCode (4/5) |
| [46] | programCode (5/5) |
| [47] | (empty) |
| ... | (empty) |
| [81] | (empty) |
| [82] | hiddenImage.png |
| [83] | hiddenImage.png |
| [84] | hiddenImage.png |
| [85] | (empty) |
| ... | (empty) |
Operations:
...
...
Memory Accesses
Q: What happens if our program accesses the memory address 0xC123?
- In our system, our pages are 4 KiB. Therefore, page offset is
0x123(12 bits) and the page number is the remaining bits (0xC). - We know
0xC==12. - The contents of index 12, [12], in our page table is empty!
RAM:
| [0] | programCode (1/5) |
| [1] | (heap memory data) |
| [2] | programCode (2/5) |
| [3] | (heap memory data) |
P1 Page Table:
| [0] | (empty) |
| [1] | ==> ram[0], disk[42] |
| [2] | ==> ram[2], disk[43] |
| [3] | ==> disk[44] |
| [4] | ==> disk[45] |
| [5] | ==> disk[46] |
| [6] | (empty) |
| [7] | (empty) |
| [8] | (heap memory) ==> ram[1] |
| [9] | (heap memory) ==> ram[3] |
| [10] | (heap memory) |
| [11] | (heap memory) |
| [12] | (empty) |
| [13] | (empty) |
| [14] | (empty) |
| [15] | (empty) |
Hard Drive:
| ... | (empty) |
| [41] | (empty) |
| [42] | programCode (1/5) |
| [43] | programCode (2/5) |
| [44] | programCode (3/5) |
| [45] | programCode (4/5) |
| [46] | programCode (5/5) |
| [47] | (empty) |
| ... | (empty) |
| [81] | (empty) |
| [82] | hiddenImage.png |
| [83] | hiddenImage.png |
| [84] | hiddenImage.png |
| [85] | (empty) |
| ... | (empty) |
Operations:
...
...
Segmentation Fault
A segmentation fault occurs when you access memory that has not been mapped in your virtual memory!
- The example above results in a segmentation fault because [12] is an unused page table entry.
- Additionally, the operating system will ALWAYS leave the memory address
0x0(and the whole page associated with0000 ... 0000) empty. Due to this, access aNULLpointer (asNULLis simply0) will also always result in a segmentation fault.