I am a C dummy and working on a C project which asked me to write a signal handler to catch SIGSEGV signal and perform some operations.
Basically, the main program will try to access a memory chunk that is neither readable or writable. When the main program access this chunk of memory it will raise a SIGSEGV signal, and in my signal handler function I will catch the signal and use mprotect() to convert that memory chunk into readable & writable.
But I don't know is there any way to get the address which caused SIGSEGV when signal is catched by my signal handler. I cannot do anything if I don't have the actual address which caused SIGSEGV. And I am not allowed to grab address from main into my signal handler.
can someone help me? Thanks!