I'm trying to do some nasty hacking stuff with dynamically generated code, and I want the OS to send me SIGILL when it reaches an unknown opcode. This would allow me to add a layer of meta-information about my program and so on.
However, for my small test program, it seems that the OS does not send SIGILL, but sends either SIGBUS or SIGSEGV. I assume this means that the NX bit is set on the page where the memory is located.
Any tips on how to make an executable memory file?
For reference, here is my test program:
#include <stdio.h> #include <signal.h> #include <stdlib.h> #include <string.h> void SIGILL_handler(int sig) { printf("Handling SIGILL\n"); } typedef void(*FUNC)(void); int main() { signal(SIGILL, SIGILL_handler); int *bad = malloc(16); memset(bad, 255, 16); ((FUNC)bad)(); printf("Returning like it no big deal\n"); return 0; }
source share