How does an operating system (preferably Linux) know that you've accessed a memory location that you're not allowed to?
This question was inspired by those damn pointers! The way I see it is: everything in computers is about a compromise between speed, security, integrity, and such things.
I'm well aware of memory maps in Linux, but it sounds a bit ridiculous to me that the kernel checks if the location you're trying to access resides in a valid range EVERY TIME you make an access. It sounds like it would waste so much time, which could be spent doing something more productive (but possibly less safe with no checking!). Or maybe it remembers all recent accesses and checks them on every hardware timer tick? (But that sounds unsafe, and yet again, slow.)
I was surprised that this question appears to be unanswered anywhere. It's something I've always wondered. It makes me think there is a section of hardware which will do this on behalf of the OS, in a nice, convenient level of abstraction. But still, it would possibly require loading the next processes memory maps on every context switch, which again sounds slow.
So yes, anyway, I'm going on a bit: how does an OS detect a memory violation?