Could you post your results?
#include <stdio.h>
#include <stdlib.h>
_Bool xdb () {
unsigned int d;
__asm__("cpuid":"=d"(d):"a"(0x80000001):"%ebx","%ecx");
return ((d&0x100000)==0x100000);
}
char * code = "\xC3"; // ret
char buffer;
int main (int argc, char ** argv) {
void (*function)();
char opcode;
if (!xdb()) {printf ("This CPU does not have Execute Disable
Bit.\n"); return EXIT_SUCCESS;}
buffer=*code;
function = (void(*)())&buffer;
printf ("I\'ll try to call buffer located at %p.\n",function);
function();
printf ("Succeeded.\n");
if (NULL==(function=malloc(1))) {perror(NULL); return EXIT_FAILURE;}
*(char*)function = *code;
printf ("I\'ll try to call malloced mem located at %p.\n",function);
function();
printf ("Succeeded.\n");
opcode = *code;
function = (void(*)())&opcode;
printf ("I\'ll try to call stacked code located at %p.\n",function);
function();
printf ("Succeeded.\n");
printf ("Enter to exit.");
getchar();
return EXIT_SUCCESS;
}