Does Pike have any functionality to catch segfaults and similar errors that might be caused by a bad mmap?
Mirar @ Pike developers forum wrote:
Does Pike have any functionality to catch segfaults and similar errors that might be caused by a bad mmap?
I don't think I've ever encountered a C-program that did anything meaningful after catching a SIGSEGV. In most cases, trying to catch that and recovering is a bad idea. That signal usually belongs to debuggers and stacktraces.
Once a Pike program triggers a SIGSEGV due to a bad mmap, you need to fix your mmap usage. This inevitably needs to be done during the development stage. This usually is not something that can be handled satisfactory while in a production environment with mere users around.
SIGSEGV is just another signal, it's quite possible to use it to create an error and catch it.
That it's _normally_ used as a symptom of a badly written program doesn't make it less useful.
In the case of mmap it's quite possible to use it in Pike to catch unexpected file errors.
If the user have access to mmap I think the user can have access to telling what SIGSEGV should do, too. :)
In theory you could just catch the SIGSEGV signal in Pike, adjust your mmap() and retry, but in most cases, once you get a SIGSEGV you are already screwed beyond what you can repair inside your application in my experience.
Nothing gets screwed up by SIGSEGV, but you might get a SIGSEGV from screwing up.
Well, that is semantics. In practice there is no difference, if you get a SIGSEGV your are pretty much screwed.
In a specific case, you might be able to recover, but in the general case, you really have no clue what will still work and what won't, so terminating the application is really the only viable option.
My argument is _exactly_ that you're _not_ screwed if you accessed something in a mmaped area that didn't behave as you wanted.
And we're discussing mmap()ed areas.
Since Pike has very few ways of screwing up that you would get a SIGSEGV without using mmap I believe it would be a useful function to have.
The only other case for SIGSEGV would be to crash your program to restart it because _Pike itself_ had a bug. I haven't seen that case for many years. YMMV.
(I have gotten SIGILL because the CPU screwed up, but not SIGSEGV.)
pike-devel@lists.lysator.liu.se