-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab433a1
commit e2fbf90
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <signal.h> | ||
#include <signal.h> | ||
#define SIMPLE_WAY | ||
|
||
void sighandler(int signo) | ||
{ | ||
#ifdef SIMPLE_WAY | ||
exit(signo); | ||
#else | ||
extern void __gcov_flush(); | ||
__gcov_flush(); /* flush out gcov stats data */ | ||
raise(signo); /* raise the signal again to crash process */ | ||
#endif | ||
} | ||
|
||
/** | ||
* The code for cracking the preloaded dynamic library gcov_preload.so is as follows, where __attribute__((constructor)) is the symbol of gcc, | ||
* The modified function will be called before the main function is executed. We use it to intercept the exception signal to our own function, and then call __gcov_flush() to output the error message | ||
*/ | ||
|
||
__attribute__ ((constructor)) | ||
|
||
void ctor() | ||
{ | ||
int sigs[] = { | ||
SIGILL, SIGFPE, SIGABRT, SIGBUS, | ||
SIGSEGV, SIGHUP, SIGINT, SIGQUIT, | ||
SIGTERM | ||
}; | ||
int i; | ||
struct sigaction sa; | ||
sa.sa_handler = sighandler; | ||
sigemptyset(&sa.sa_mask); | ||
sa.sa_flags = SA_RESETHAND; | ||
|
||
for(i = 0; i < sizeof(sigs)/sizeof(sigs[0]); ++i) { | ||
if (sigaction(sigs[i], &sa, NULL) == -1) { | ||
perror("Could not set signal handler"); | ||
} | ||
} | ||
} |