You can sequentially read (inside your process) the file /proc/self/maps to get a memory map (including for shared objects) of the current process.
Then you can get your program counter (or callerβs number) and find in which segment it is. Perhaps relevant backtrace or GCC builtin_return_address .
You can also use the dladdr function.
See proc (5) , backtrace (3) , dladdr (3) man pages, as well as this answer .
additions
From the signal handler you can get the program counter when the signal was sent using sigaction (2) with SA_SIGINFO . The pointers to the sa_sigaction function get ucontext_t , from which you can get the program counter register (using C machine code). Then you can handle it.
I suggest exploring in detail what GCC does.
Basile starynkevitch
source share