
How does a segmentation fault work under the hood? - gedrap
http://unix.stackexchange.com/questions/257598/how-does-a-segmentation-fault-work-under-the-hood
======
mattiemass
Good explanation, but a little too light no the details of the signal
mechanism itself.

~~~
asveikau
Not to mention how and why the kernel receives the trap.

There is no mention of the words "page table", and it's very light on use of
the word "interrupt".

~~~
pjc50
Page faults are a "trap" rather than an "interrupt", aren't they? In that
they're internal to the CPU-MMU system and delivered synchronously.

The answer is a good stackexchange answer in that it's about a page long and
covers all the key points. It gives a link to "page" for those who want to
understand that subsystem. It's not necessary to include a whole computer
architecture course.

~~~
steveklabnik
My understanding is that "interrupt" is the most general term, and "fault,"
"trap," and "exception" are all various kinds of interrupts with a very
unclear set of rules distinguishing them.

And of course this is all architecture dependent.

~~~
hacknat
Fault simply means that the TLB has a cache miss and then traps to the OS to
handle the miss. "Fault" is a concept of what is happening a "trap" is what
happens.

Edit:

x86 does have a register for defining the location of page tables that it will
walk, the it would trap on a miss if the PTE is missing. Idk, if Linux uses
this register or not or uses a software defined TLB, or some kind of hybrid
approach.

~~~
moyix
> x86 does have a register for defining the location of page tables that it
> will walk, the it would trap on a miss if the PTE is missing. Idk, if Linux
> uses this register or not or uses a software defined TLB, or some kind of
> hybrid approach.

TLB management is done in hardware on x86. TLB misses don't generate
exceptions, they just trigger page table walks in hardware, and then if the
page table walk fails (e.g. because of a non-present page table entry) it
triggers a CPU exception (page fault) that the OS can then handle.

Things like MIPS use a software-managed TLB that works roughly as you
describe, though.

~~~
hacknat
If you read what I wrote you'll see that I said this.

------
js2
[https://en.m.wikipedia.org/wiki/Segmentation_fault](https://en.m.wikipedia.org/wiki/Segmentation_fault)
seems like a much better explanation to me.

~~~
noxToken
Non-mobile:
[https://en.wikipedia.org/wiki/Segmentation_fault](https://en.wikipedia.org/wiki/Segmentation_fault)

------
AnimalMuppet
Obligatory XKCD: [https://xkcd.com/371/](https://xkcd.com/371/)

