@@ -62,10 +62,15 @@ #ifndef CODE_EXECUTABLE /* configure guesses wrong?? */ #define CODE_EXECUTABLE #endif #endif #endif + +/* As of Windows XP SP 2, malloc'd memory is not executable */ +#ifdef _WIN32 +#undef CODE_EXECUTABLE +#endif #ifndef CODE_EXECUTABLE /* How do we make the trampoline's code executable? */ #if defined(HAVE_MACH_VM) || defined(__convex__) || defined(HAVE_WORKING_MPROTECT) || defined(HAVE_SYS_M88KBCS_H) /* mprotect() [or equivalent] the malloc'ed area. */ @@ -84,11 +89,15 @@ #else #ifdef HAVE_SHM /* Use an shmat'ed page. */ #define EXECUTABLE_VIA_SHM #else +#ifdef _WIN32 +/* Use VirtualAlloc */ +#else ?? +#endif #endif #endif #endif #endif @@ -387,10 +396,15 @@ if (shmid<0) { page = (char*)(-1); } else { page = shmat(shmid, 0, 0); shmctl(shmid, IPC_RMID, 0); } #endif +#ifdef _WIN32 + page = VirtualAlloc(NULL, pagesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if (page == 0) + { page = (char*)(-1); } +#endif if (page == (char*)(-1)) { fprintf(stderr,"trampoline: Out of virtual memory!\n"); abort(); } /* Fill it with free trampolines. */ { char** last = &freelist; char* page_end = page + pagesize;