I plan to create a logging/tracing mechanism, which writes the address (const char*) of string literals to a ring-buffer. These strings are in the read-only data-segment and are created by the preprocessor with __function__ or __file__.
The Question: Is it possible, to analyze this ring-buffer content after a Segfault, if all pointers are valid? With “valid” I mean that they point to a mapped memory area and dereferencing won’t cause a segmentation fault.
I’m working with Linux 2.6.3x and GCC 4.4.x.
Best regards,
Charly
Of course if the stack or other memory that you rely upon has been corrupted then there could be problems, but that is true for any code.
Assuming that that there is no problem with the stack or other memory that you rely upon, and assuming that you do not call any functions like
malloc()that are not async-signal safe, and assuming that you do not attempt to return from your signal handler, then there should be no problem reading or writing your buffer from within your signal handler.If you are trying to test whether a particular address is valid, you could use a system call such as
mincore()and check for an error result.