Ticket #473 (closed bug: fixed)
Data Execution Prevention breaks "perl Configure.pl"; remove Parrot_memcpy_aligned
Description
I have Data Execution Prevention enabled on Windows XP. When I run perl Configure.pl, it fails in a couple places with DEP exceptions:
auto::jit - Determine JIT capability...
auto::cpu - Generate CPU specific stuff... (2 times)
Looking at one of the .c files that is compiled and run during the Configure.pl process, I can see the data execution.
static const char Parrot_memcpy_aligned_sse_code[] = { /* Parrot_memcpy_aligned_sse: */ 0x57, /* pushl %edi */ 0x56, /* pushl %esi */ 0x8B, 0x44, 0x24, 0x0C, /* movl 12(%esp), %eax */ 0x8B, 0x4C, 0x24, 0x14, /* mov 20(%esp), %ecx */ 0x8B, 0x74, 0x24, 0x10, /* mov 16(%esp), %esi */ 0x89, 0xC7, /* mov %eax, %edi */ 0xC1, 0xE9, 0x05, /* shr $5, %ecx */ /* 1: */ 0x0F, 0x10, 0x06, /* movups 0(%esi), %xmm0 */ 0x0F, 0x10, 0x4E, 0x10, /* movups 16(%esi), %xmm1 */ 0x83, 0xC6, 0x20, /* add $32, %esi */ 0x0F, 0x11, 0x07, /* movups %xmm0, 0(%edi) */ 0x0F, 0x11, 0x4F, 0x10, /* movups %xmm1, 16(%edi) */ 0x83, 0xC7, 0x20, /* add $32, %edi */ 0x49, /* dec %ecx */ 0x75, 0xE9, /* jnz 1b */ 0x5E, /* popl %esi */ 0x5F, /* popl %edi */ 0xC3, /* ret */ 0x00 }; typedef void* (*Parrot_memcpy_aligned_sse_t)(void *dest, const void *src, size_t); . . . Parrot_memcpy_aligned_sse_t Parrot_memcpy_aligned_sse = (Parrot_memcpy_aligned_sse_t) Parrot_memcpy_aligned_sse_code; . . . Parrot_memcpy_aligned_sse(d, s, n);
A data segment-based array is cast to a function pointer that is subsequently called, hence the DEP exception.
I recommend that on windoze platforms only, the data at Parrot_memcpy_aligned_sse_code be copied to a buffer allocated with VirtualAlloc(), then set execution privs on that buffer with VirtualProtect(PAGE_EXECUTE), and finally call the machine code at the VirtualAlloc address. It's a lot of rig-a-ma-roll, but it lets you execute arbitrary data without fear of DEP. Here is a link that discusses the issue:
http://msdn.microsoft.com/en-us/library/aa366553(VS.85).aspx
After disabling DEP and rebooting, I was able to successfully configure, compile, and run Parrot 1.0! The DEP errors are scary and vague looking enough that this bug might need to be addressed.
Cheers,
Dave Woldrich
dave@…