From 47cde6a97e62362af7e259a2d16ecbde7d9d1c58 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Thu, 18 Aug 2005 10:51:57 +0000 Subject: [PATCH] Added patch 1154355 from Thomas Weidner. Marks memory executable in the dynamic core under 64 bits linux Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2277 --- configure.in | 7 +++++++ src/cpu/core_dyn_x86.cpp | 9 +++++++++ src/cpu/core_dyn_x86/cache.h | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/configure.in b/configure.in index fa36b356..7cc83ea8 100644 --- a/configure.in +++ b/configure.in @@ -244,6 +244,13 @@ else AC_MSG_WARN([Can't find libSDL_sound, libSDL_sound support disabled]) fi +dnl Check for mprotect. Needed for 64 bits linux +AH_TEMPLATE(C_HAVE_MPROTECT,[Define to 1 if you have the mprotect function]) +AC_CHECK_HEADER([sys/mman.h], [ +AC_CHECK_FUNC([mprotect],[AC_DEFINE(C_HAVE_MPROTECT,1)]) +]) + +dnl Setpriority AH_TEMPLATE(C_SET_PRIORITY,[Define to 1 if you have setpriority support]) AC_MSG_CHECKING(for setpriority support) AC_LINK_IFELSE([ diff --git a/src/cpu/core_dyn_x86.cpp b/src/cpu/core_dyn_x86.cpp index 71605085..e66df13f 100644 --- a/src/cpu/core_dyn_x86.cpp +++ b/src/cpu/core_dyn_x86.cpp @@ -26,6 +26,15 @@ #include #include +#if (C_HAVE_MPROTECT) +#include + +#include +#ifndef PAGESIZE +#define PAGESIZE 4096 +#endif +#endif /* C_HAVE_MPROTECT */ + #include "callback.h" #include "regs.h" #include "mem.h" diff --git a/src/cpu/core_dyn_x86/cache.h b/src/cpu/core_dyn_x86/cache.h index 9bdccb18..9bd30b5e 100644 --- a/src/cpu/core_dyn_x86/cache.h +++ b/src/cpu/core_dyn_x86/cache.h @@ -42,10 +42,17 @@ static struct { CodePageHandler * last_page; } cache; +#if (C_HAVE_MPROTECT) +static Bit8u cache_code_link_blocks[2][16] GCC_ATTRIBUTE(aligned(PAGESIZE)); +static Bit8u cache_code[CACHE_TOTAL+CACHE_MAXSIZE] GCC_ATTRIBUTE(aligned(PAGESIZE)); +#else static Bit8u cache_code_link_blocks[2][16]; static Bit8u cache_code[CACHE_TOTAL+CACHE_MAXSIZE]; +#endif + static CacheBlock cache_blocks[CACHE_BLOCKS]; static CacheBlock link_blocks[2]; + class CodePageHandler :public PageHandler { public: CodePageHandler() {} @@ -338,6 +345,10 @@ static void gen_return(BlockReturn retcode); static void cache_init(void) { Bits i; memset(&cache_blocks,0,sizeof(cache_blocks)); +#if (C_HAVE_MPROTECT) + mprotect(cache_code,sizeof(cache_code),PROT_WRITE|PROT_READ|PROT_EXEC); + mprotect(cache_code_link_blocks,sizeof(cache_code_link_blocks),PROT_WRITE|PROT_READ|PROT_EXEC); +#endif cache.block.free=&cache_blocks[0]; for (i=0;i