Slightly cleanup of mmap(2) flags:

Move MAP_32BIT to MemoryUtil.h.
MAP_VARIABLE is simply the absence of MAP_FIXED.
Replace MAP_ANONYMOUS with the more traditional MAP_ANON - Linux is compatible.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5899 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Soren Jorvang 2010-07-18 05:15:16 +00:00
parent 8208903fed
commit caeabf8bea
3 changed files with 11 additions and 17 deletions

View File

@ -114,10 +114,6 @@ extern const char *netplay_dolphin_ver;
#include "Config.h" // SCons autoconfiguration defines #include "Config.h" // SCons autoconfiguration defines
#endif #endif
#ifndef __linux__
#define MAP_32BIT 0 // MAP_32BIT is a Linux-specific mmap(2) flag
#endif
// Windows compatibility // Windows compatibility
#ifndef _WIN32 #ifndef _WIN32
#include <limits.h> #include <limits.h>

View File

@ -22,21 +22,11 @@
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <psapi.h> #include <psapi.h>
#elif __GNUC__ #else
#include <sys/mman.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#endif #endif
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON
#endif
// MacOSX does not support MAP_VARIABLE
#ifndef MAP_VARIABLE
#define MAP_VARIABLE 0
#endif
// This is purposely not a full wrapper for virtualalloc/mmap, but it // This is purposely not a full wrapper for virtualalloc/mmap, but it
// provides exactly the primitive operations that Dolphin needs. // provides exactly the primitive operations that Dolphin needs.
@ -55,7 +45,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
#else #else
void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_ANONYMOUS | MAP_PRIVATE MAP_ANON | MAP_PRIVATE
#ifdef __x86_64__ #ifdef __x86_64__
| (low ? MAP_32BIT : 0) | (low ? MAP_32BIT : 0)
#endif #endif
@ -86,7 +76,7 @@ void* AllocateMemoryPages(size_t size)
#else #else
void* retval = mmap(0, size, PROT_READ | PROT_WRITE, void* retval = mmap(0, size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // | MAP_FIXED MAP_ANON | MAP_PRIVATE, -1, 0); // | MAP_FIXED
// printf("Mapped memory at %p (size %i)\n", retval, size); // printf("Mapped memory at %p (size %i)\n", retval, size);
if (!retval) if (!retval)

View File

@ -18,8 +18,16 @@
#ifndef _MEMORYUTIL_H #ifndef _MEMORYUTIL_H
#define _MEMORYUTIL_H #define _MEMORYUTIL_H
#ifndef _WIN32
#include <sys/mman.h>
#endif
#include <string> #include <string>
// Linux-specific mmap(2) flag
#ifndef MAP_32BIT
#define MAP_32BIT 0
#endif
void* AllocateExecutableMemory(size_t size, bool low = true); void* AllocateExecutableMemory(size_t size, bool low = true);
void* AllocateMemoryPages(size_t size); void* AllocateMemoryPages(size_t size);
void FreeMemoryPages(void* ptr, size_t size); void FreeMemoryPages(void* ptr, size_t size);