/[pcsx2_0.9.7]/trunk/common/include/Utilities/General.h
ViewVC logotype

Diff of /trunk/common/include/Utilities/General.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/common/include/Utilities/General.h	2010/11/12 01:10:22	273
+++ trunk/common/include/Utilities/General.h	2010/12/23 12:02:12	280
@@ -133,14 +133,84 @@
 	virtual void DoDeletion();
 };
 
-
-enum PageProtectionMode
+// --------------------------------------------------------------------------------------
+//  PageProtectionMode
+// --------------------------------------------------------------------------------------
+class PageProtectionMode
 {
-	Protect_NoAccess = 0,
-	Protect_ReadOnly,
-	Protect_ReadWrite
+protected:
+	bool	m_read;
+	bool	m_write;
+	bool	m_exec;
+
+public:
+	PageProtectionMode()
+	{
+		All( false );
+	}
+
+	PageProtectionMode& Read( bool allow=true )
+	{
+		m_read = allow;
+		return *this;
+	}
+
+	PageProtectionMode& Write( bool allow=true )
+	{
+		m_write = allow;
+		return *this;
+	}
+
+	PageProtectionMode& Execute( bool allow=true )
+	{
+		m_exec = allow;
+		return *this;
+	}
+	
+	PageProtectionMode& All( bool allow=true )
+	{
+		m_read = m_write = m_exec = allow;
+		return *this;
+	}
+
+	bool CanRead() const	{ return m_read; }
+	bool CanWrite() const	{ return m_write; }
+	bool CanExecute() const	{ return m_exec && m_read; }
+	bool IsNone() const		{ return !m_read && !m_write; }
+	
+	wxString ToString() const;
 };
 
+static __fi PageProtectionMode PageAccess_None()
+{
+	return PageProtectionMode();
+}
+
+static __fi PageProtectionMode PageAccess_ReadOnly()
+{
+	return PageProtectionMode().Read();
+}
+
+static __fi PageProtectionMode PageAccess_WriteOnly()
+{
+	return PageProtectionMode().Write();
+}
+
+static __fi PageProtectionMode PageAccess_ReadWrite()
+{
+	return PageAccess_ReadOnly().Write();
+}
+
+static __fi PageProtectionMode PageAccess_ExecOnly()
+{
+	return PageAccess_ReadOnly().Execute();
+}
+
+static __fi PageProtectionMode PageAccess_Any()
+{
+	return PageProtectionMode().All();
+}
+
 // --------------------------------------------------------------------------------------
 //  HostSys
 // --------------------------------------------------------------------------------------
@@ -148,22 +218,29 @@
 // platform prior to wxWidgets .. it should prolly be removed -- air)
 namespace HostSys
 {
+	void* MmapReserve(uptr base, size_t size);
+	bool MmapCommit(uptr base, size_t size, const PageProtectionMode& mode);
+	void MmapReset(uptr base, size_t size);
+
+	void* MmapReservePtr(void* base, size_t size);
+	bool MmapCommitPtr(void* base, size_t size, const PageProtectionMode& mode);
+	void MmapResetPtr(void* base, size_t size);
+
 	// Maps a block of memory for use as a recompiled code buffer.
-	// The allocated block has code execution privileges.
 	// Returns NULL on allocation failure.
-	extern void *Mmap(uptr base, u32 size);
+	extern void* Mmap(uptr base, size_t size);
 
 	// Unmaps a block allocated by SysMmap
-	extern void Munmap(uptr base, u32 size);
+	extern void Munmap(uptr base, size_t size);
 
-	extern void MemProtect( void* baseaddr, size_t size, PageProtectionMode mode, bool allowExecution=false );
+	extern void MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode );
 
-	extern void Munmap( void* base, u32 size );
+	extern void Munmap( void* base, size_t size );
 
 	template< uint size >
-	void MemProtectStatic( u8 (&arr)[size], PageProtectionMode mode, bool allowExecution=false )
+	void MemProtectStatic( u8 (&arr)[size], const PageProtectionMode& mode )
 	{
-		MemProtect( arr, size, mode, allowExecution );
+		MemProtect( arr, size, mode );
 	}
 }
 
@@ -174,5 +251,6 @@
 extern void InitCPUTicks();
 extern u64  GetTickFrequency();
 extern u64  GetCPUTicks();
+extern u64 GetPhysicalMemory();
 
 extern wxString GetOSVersionString();

 

  ViewVC Help
Powered by ViewVC 1.1.22