2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-04-27 02:04:31 +00:00
|
|
|
*/
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
#include "PrecompiledHeader.h"
|
2009-07-03 00:49:40 +00:00
|
|
|
#include "Utilities/RedtapeWindows.h"
|
2009-04-27 02:04:31 +00:00
|
|
|
#include <winnt.h>
|
|
|
|
|
2010-10-22 16:23:52 +00:00
|
|
|
void* HostSys::MmapReserve(uptr base, size_t size)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-10-22 16:23:52 +00:00
|
|
|
return VirtualAlloc((void*)base, size, MEM_RESERVE, PAGE_NOACCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostSys::MmapCommit(void* base, size_t size)
|
|
|
|
{
|
|
|
|
// Execution flag for this and the Reserve should match... ?
|
|
|
|
void* result = VirtualAlloc(base, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
pxAssumeDev(result, L"VirtualAlloc COMMIT failed: " + Exception::WinApiError().GetMsgFromWindows());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostSys::MmapReset(void* base, size_t size)
|
|
|
|
{
|
|
|
|
// Execution flag is actually irrelevant for this operation, but whatever.
|
|
|
|
//void* result = VirtualAlloc((void*)base, size, MEM_RESET, PAGE_EXECUTE_READWRITE);
|
|
|
|
//pxAssumeDev(result, L"VirtualAlloc RESET failed: " + Exception::WinApiError().GetMsgFromWindows());
|
|
|
|
|
|
|
|
VirtualFree(base, size, MEM_DECOMMIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* HostSys::Mmap(uptr base, size_t size)
|
|
|
|
{
|
|
|
|
return VirtualAlloc((void*)base, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostSys::Munmap(uptr base, size_t size)
|
|
|
|
{
|
|
|
|
if (!base) return;
|
|
|
|
VirtualFree((void*)base, size, MEM_DECOMMIT);
|
|
|
|
VirtualFree((void*)base, 0, MEM_RELEASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostSys::MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode )
|
|
|
|
{
|
|
|
|
pxAssertDev( ((size & (__pagesize-1)) == 0), wxsFormat(
|
|
|
|
L"Memory block size must be a multiple of the target platform's page size.\n"
|
|
|
|
L"\tPage Size: 0x%04x (%d), Block Size: 0x%04x (%d)",
|
|
|
|
__pagesize, __pagesize, size, size )
|
|
|
|
);
|
|
|
|
|
|
|
|
DWORD winmode = PAGE_NOACCESS;
|
|
|
|
|
|
|
|
// Windows has some really bizarre memory protection enumeration that uses bitwise
|
|
|
|
// numbering (like flags) but is in fact not a flag value. *Someone* from the early
|
|
|
|
// microsoft days wasn't a very good coder, me thinks. --air
|
|
|
|
|
|
|
|
if (mode.CanExecute())
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-10-22 16:23:52 +00:00
|
|
|
winmode = mode.CanWrite() ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
2010-10-22 16:23:52 +00:00
|
|
|
else if (mode.CanRead())
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-10-22 16:23:52 +00:00
|
|
|
winmode = mode.CanWrite() ? PAGE_READWRITE : PAGE_READONLY;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
2010-10-22 16:23:52 +00:00
|
|
|
|
|
|
|
DWORD OldProtect; // enjoy my uselessness, yo!
|
|
|
|
if (!VirtualProtect( baseaddr, size, winmode, &OldProtect ))
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-10-22 16:23:52 +00:00
|
|
|
throw Exception::WinApiError().SetDiagMsg(
|
|
|
|
pxsFmt(L"VirtualProtect failed @ 0x%08X -> 0x%08X (mode=%s)",
|
|
|
|
baseaddr, (uptr)baseaddr + size, mode.ToString().c_str()
|
|
|
|
));
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
}
|