2 * $Id: noexecute.c 19171 2005-11-12 08:40:47Z sedwards $
10 #include <pseh/pseh.h>
17 void execute(char* message
, int(*func
)(int))
22 printf("%s ... ", message
);
30 status
= _SEH_GetExceptionCode();
39 printf("Error, status=%lx.\n", status
);
47 unsigned char stack
[100];
51 printf("NoExecute\n");
53 execute("Executing within the code segment", test
);
54 memcpy(data
, test
, 100);
55 execute("Executing within the data segment", (int(*)(int))data
);
56 memcpy(stack
, test
, 100);
57 execute("Executing on stack segment", (int(*)(int))stack
);
58 heap
= VirtualAlloc(NULL
, 100, MEM_COMMIT
, PAGE_READWRITE
);
59 memcpy(heap
, test
, 100);
60 execute("Executing on the heap with protection PAGE_READWRITE", (int(*)(int))heap
);
61 VirtualProtect(heap
, 100, PAGE_EXECUTE
, &protection
);
62 execute("Executing on the heap with protection PAGE_EXECUTE", (int(*)(int))heap
);