Posts for wisk

Joined: 12/25/2009
Posts: 1
Hi folks, I figure out why pcsx crashes when running a game under w7-rtm. It allocates memory in order to store recompiled instructions and then executes them. If I do remember, with vista and above, heap pages are not in EXECUTE anymore. You can either deactivate DEP(not recommended) or apply the following patch. In ./ix86/iR3000A.c
static int recInit() {
	int i;

#ifdef WIN32
  DWORD dwOldProtect;
  BOOL bRes;
#endif

	psxRecLUT = (u32*) malloc(0x010000 * 4);

	recMem = (char*) malloc(RECMEM_SIZE);
	recRAM = (char*) malloc(0x200000);
	recROM = (char*) malloc(0x080000);
	if (recRAM == NULL || recROM == NULL || recMem == NULL || psxRecLUT == NULL) {
		SysMessage("Error allocating memory"); return -1;
	}

#ifdef WIN32
  bRes = VirtualProtect(psxRecLUT, 0x010000 * 4, PAGE_EXECUTE_READWRITE, &dwOldProtect);
  bRes &= VirtualProtect(recMem, RECMEM_SIZE, PAGE_EXECUTE_READWRITE, &dwOldProtect);
  bRes &= VirtualProtect(recRAM, 0x200000, PAGE_EXECUTE_READWRITE, &dwOldProtect);
  bRes &= VirtualProtect(recROM, 0x080000, PAGE_EXECUTE_READWRITE, &dwOldProtect);
  if (bRes == FALSE)
  {
    SysMessage("Unable to change memory protection");
    return -1;
  }
#endif

	for (i=0; i<0x80; i++) psxRecLUT[i + 0x0000] = (u32)&recRAM[(i & 0x1f) << 16];
	memcpy(psxRecLUT + 0x8000, psxRecLUT, 0x80 * 4);
	memcpy(psxRecLUT + 0xa000, psxRecLUT, 0x80 * 4);

	for (i=0; i<0x08; i++) psxRecLUT[i + 0xbfc0] = (u32)&recROM[i << 16];

	return 0;
}
I have recompiled pcsx with VS2008 and it works like a charm, I can upload it if you wish. I hope it can help. :)