/[pcsx2_0.9.7]/trunk/common/src/Utilities/Linux/LnxHostSys.cpp
ViewVC logotype

Contents of /trunk/common/src/Utilities/Linux/LnxHostSys.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 5 months ago) by william
File size: 2038 byte(s)
exported r3113 from ./upstream/trunk
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16
17 #include "../PrecompiledHeader.h"
18
19 #include <sys/mman.h>
20 #include <signal.h>
21
22 namespace HostSys
23 {
24 static const uptr m_pagemask = getpagesize()-1;
25
26 void *Mmap(uptr base, u32 size)
27 {
28 u8 *Mem;
29 Mem = (u8*)mmap((uptr*)base, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
30 if (Mem == MAP_FAILED) Console.Warning("Mmap Failed!");
31
32 return Mem;
33 }
34
35 void Munmap(uptr base, u32 size)
36 {
37 munmap((uptr*)base, size);
38 }
39
40 void MemProtect( void* baseaddr, size_t size, PageProtectionMode mode, bool allowExecution )
41 {
42 pxAssertDev( (size & (__pagesize-1)) == 0, wxsFormat(
43 L"Memory block size must be a multiple of the target platform's page size.\n"
44 L"\tPage Size: 0x%04x (%d), Block Size: 0x%04x (%d)",
45 __pagesize, __pagesize, size, size )
46 );
47
48 int lnxmode = 0;
49
50 // make sure size is aligned to the system page size:
51 // Check is redundant against the assertion above, but might as well...
52 size = (size + m_pagemask) & ~m_pagemask;
53
54 switch( mode )
55 {
56 case Protect_NoAccess: break;
57 case Protect_ReadOnly: lnxmode = PROT_READ; break;
58 case Protect_ReadWrite: lnxmode = PROT_READ | PROT_WRITE; break;
59 }
60
61 if( allowExecution ) lnxmode |= PROT_EXEC;
62 mprotect( baseaddr, size, lnxmode );
63 }
64 }

  ViewVC Help
Powered by ViewVC 1.1.22