Skip to content

Instantly share code, notes, and snippets.

@primiano
Last active October 17, 2016 09:56
Show Gist options
  • Save primiano/cbb772e2d07b8e00898084d0746b83e3 to your computer and use it in GitHub Desktop.
Save primiano/cbb772e2d07b8e00898084d0746b83e3 to your computer and use it in GitHub Desktop.
Ubuntu 14.04 on X86_64:
-----------------------
PID 34611 about to die jump 0x0
PID 34611 died with sig 11 Segmentation fault
PID 34612 about to die jump 0x12341230
PID 34612 died with sig 11 Segmentation fault
PID 34613 about to die with __builtin_trap
PID 34613 died with sig 4 Illegal instruction
Android 32 bit binary on armv7:
-------------------------------
PID 13646 about to die jump 0x0
PID 13646 died with sig 11 Segmentation fault
PID 13647 about to die jump 0x12341230
PID 13647 died with sig 11 Segmentation fault
PID 13648 about to die with __builtin_trap
PID 13648 died with sig 4 Illegal instruction
Android 32 bit binary on armv8:
-------------------------------
PID 15981 about to die jump 0x0
PID 15981 died with sig 11 Segmentation fault
PID 15982 about to die jump 0x12341230
PID 15982 died with sig 11 Segmentation fault
PID 15983 about to die with __builtin_trap
PID 15983 died with sig 4 Illegal instruction
Android 64 bit binary on armv8:
-------------------------------
PID 16243 about to die jump 0x0
PID 16243 died with sig 11 Segmentation fault
PID 16244 about to die jump 0x12341230
PID 16244 died with sig 11 Segmentation fault
PID 16245 about to die with __builtin_trap
PID 16245 died with sig 5 Trap
-------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>
static void sighandler (int signum) {
printf("PID %d died with sig %d %s\n", getpid(), signum, strsignal(signum));
_exit(0);
}
static void setupsighandler() {
signal(SIGILL, sighandler);
signal(SIGSEGV, sighandler);
signal(SIGABRT, sighandler);
signal(SIGFPE, sighandler);
signal(SIGTRAP, sighandler);
}
int main() {
int status = 0;
if (fork() == 0) {
setupsighandler();
printf("PID %d about to die jump 0x0\n", getpid());
((void(*)())0)();
return 0;
}
wait(&status);
if (fork() == 0) {
setupsighandler();
printf("PID %d about to die jump 0x12341230\n", getpid());
((void(*)())0x12341230)();
return 0;
}
wait(&status);
if (fork() == 0) {
setupsighandler();
printf("PID %d about to die with __builtin_trap\n", getpid());
__builtin_trap();
return 0;
}
wait(&status);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment